News for hackers. Stuff that matters.
Re:Write code. Not too much. Mostly functions. by plasticchris on Monday December 21, 2020 @10:17PM (#25502477)
Abstraction here likely means more than a function - maybe something like an interface base class?
Re:Write code. Not too much. Mostly functions. by bcrosby95 on Tuesday December 22, 2020 @02:05AM (#25503750)
Probably. When talking about object oriented programs, "abstraction" is oftentimes used as a placeholder for "abstract class" as opposed to a "concrete class". You can see this at play when talking about the SOLID principles and when you get to the "D" part people want to turn every class into an interface because it says you must "depend upon abstractions, not concretions".
Re:Write code. Not too much. Mostly functions. by eyelidlessness on Tuesday December 22, 2020 @01:59PM (#25509801)
I think this is where I’ve been most at odds with common OOP approaches (apart from the common practice of widespread mutability). An interface should be an abstraction defining what a given operation (function, module) needs from input to operate on it and produce output, and nothing more. Mirroring concrete types with an interface isn’t abstraction, it’s just putting an IPrefix on concrete types to check a design pattern box.
Re:Write code. Not too much. Mostly functions. by m_mueller on Tuesday December 22, 2020 @05:02AM (#25504675)
A function is an abstraction as well. In case of a function, a 'client' of the function is the call.
Re:Write code. Not too much. Mostly functions. by eyelidlessness on Monday December 21, 2020 @10:27PM (#25502523)
That’s not what I took from it, but even if that’s what was meant, I think I’d have the same reaction. In terms of abstraction implementations, a class is just a different expression of the same idea of encapsulation.
Re:Write code. Not too much. Mostly functions. by harpiaharpyja on Monday December 21, 2020 @10:49PM (#25502646)
Given the context of the posts that it was replying to, my impression was that they meant the "rule of three" applied to an entire abstraction layer.
Re:Write code. Not too much. Mostly functions. by eyelidlessness on Monday December 21, 2020 @11:08PM (#25502741)
I still don’t think I’d react differently. A function is an abstraction layer. Maybe this is just me being unintentionally obtuse because I’ve worked so long in environments where functions or collections/modules of functions are the primary organizing principle, but when I encounter “premature abstraction” arguments I don’t generally understand them to mean “sure take those three repetitions of the same logic and write a function, but think really hard about writing a module/namespace/package/class/etc”. Am I misunderstanding this?
Re:Write code. Not too much. Mostly functions. by slaymaker1907 on Monday December 21, 2020 @11:34PM (#25502882)
I agree with the sentiment. A pure function with one or two parameters is going to attract a lot less scrutiny than a whole module with multiple classes.