6 ms·
Primarily a Python and Go programmer. OO: Only rarely, and only where it really makes sense. Most programs I work on are not complex enough to justify the over
by falcolas 9y ago
Primarily a Python and Go programmer.
OO: Only rarely, and only where it really makes sense. Most programs I work on are not complex enough to justify the overhead (boilerplate, cognitive).
FP: I use this more, but again, only when I can really justify the added cognitive overhead.
You'll notice the two references to cognitive overhead: I have adapted the "write for a 6th grade level" idiom into programming. I want as many people to be able to pick up the code and modify it as possibly can. I work with everything from interns to decades plus veterans, and my code must be grok-able by both. Pure FP tends to confuse interns, and veterans have a tendency to hate the layers and layers of indirection and abstraction OO brings into a program.
Normal and boring old "an imperative main method with functions" tends to be the least offensive and most understandable to all parties. Compromise r fun.
- solipsism 9y agoHow do you test your code? When a module of code, C, depends on abstraction X, how do you test C in isolation from X? The common way to do this in OO (and yes this very much includes Go, whose standard library is incredibly OO) is to have C depend on an interface instead of a concrete X. Then you have full freedom to test C very robustly and at different abstraction levels. So how do you cope with this in your code? "Imperative main method with functions" doesn't sound like it leaves room for proper testing, unless the code doesn't do much.
- rpedela 9y agoThe functions are the interface. Just because the interface isn't formalized by a class or "interface" definition doesn't mean there isn't an interface.
- solipsism 9y agoIf you have an implicit interface then you are implicitly doing OOP. You may be intelligently eschewing the worst parts of so-called OO languages (too much statefulness, and inheritance), but by using the best concepts of OOP you're demonstrating how great OOP can be when really done right. I will point you to this interview where Joe Armstrong describes Erlang as perhaps the only Object Oriented language (countering his earlier, less considered view that OO sucks): https://www.infoq.com/interviews/johnson-armstrong-oop https://www.infoq.com/interviews/johnson-armstrong-oop
- joshribakoff 9y agoI disagree. Just because your code has an interface doesn't make it OOP. If your functions are stateless yes they have an interface but that's not really OOP which is usually defined as scoped data bound with behavior. A bunch of static classes aren't OOP either, they may be using classes, but the state is global so it's not OOP. Interfaces are just one aspect of OOP and the concept of interfaces existed long before OOP and is used in other programming paradigms. An imperative program can have an interface too.
- rpedela 9y ago> If you have an implicit interface then you are implicitly doing OOP. Are you saying that having a set of functions is an implicit interface and therefore every program ever written that contains a set of functions is implicitly doing OOP?
- solipsism 9y agoWe are talking explicitly about an interface allowing an implementation that can be swapped out for testing. Not every program ever written is organized like this, but those that are are making use of polymorphism and therefore a bit of OOP.
- rpedela 9y agoThank you for adding some nuance. So then would OpenGL be an OOP API?
- KirinDave 9y agoPolymorphism is not OOP, although OOP designs may be polymorphic. Many FP approaches leverage polymorphic functions heavily (and in fact in most they use a parametric style of polymorphism which provides a lot more structure than the OO-family ad-hoc polymorphism).
- joshribakoff 9y agoWhat is proper testing? 100% code coverage doesn't mean you covered 100% of the paths in your code. Maybe you hit a line, but didn't hit that line with particular inputs that expose a bug. I'd argue that unit testing is a design tool, not necessarily a tenant of "proper testing". It will be impossible to test every unit of code super thoroughly. Even 1 line of code that accepts 1 input has an infinite number of states it can be in. Proper testing is exercising all the functionality via the UI and understanding your program and it's use cases. If you're doing end to end testing, the codes architecture does not matter because your program is basically a black box.
- qorrect 9y agoProgramming for the lowest common denominator? Something about that sounds wrong. I generally agree with "use only as much cognitive overhead as needed to get the job done" ( I'm enjoying that term ) - but it seems like a slippery slope that could slowly bring everyones abilities down to the least capable developer.
- stouset 9y agoIt's also an excuse to avoid any sort of abstraction whatsoever, which makes solutions to genuinely difficult problems impossible to read, since one has to wade through the low-level details at every step. To me, it's a bit like telling a person how to get from point A to point B by telling them when, how hard, and for how long to step on the gas and what angles to put the steering wheel at. Sure, that might work to get someone out the driveway, but good luck getting to the grocery store that way. I will genuinely never understand the go philosophy that "excessive" abstraction is bad, with no attempt to justify why current levels of abstraction — which are charitably hundreds of times more complicated than the difference between, say, go and ruby — are good, right, and just. Everything we do on a computer from processing to memory access to networked communications to rendering to handling input to relational data modeling to… anything is dozens of layers away from what's actually happening. But somehow right now we're at the optimal level of abstraction and any more would just be too much. Okay.
- teej 9y agoHere's the thing though - most programmers are not working on "genuinely difficult problems". Yes, abstraction is a useful tool but like many tools it's harmful if used improperly. Code has a tendency to live way longer than a programmer expects. Writing code that is simple, quickly grokable, and low risk to change is really important. Especially when 3 generations of software developers have come and gone between the original author and the current maintainer. I think falcolas's philosophy is spot on - treat most problems plainly and simply. In the rare event a genuinely difficult problem arises, use your tools to get it done right.
- 9y ago