4 ms·
This one is interesting: "Take pleasure in writing more code". I agree with the author's reasoning that the number of lines of code you write is meaningless an
by OskarS 5y ago
This one is interesting: "Take pleasure in writing more code".
I agree with the author's reasoning that the number of lines of code you write is meaningless and not something you should hold up with pride, but there is a flipside to that: when you get to a certain amount of experience, code verbosity is usually a good thing.
At some point when learning, many programmers become good enough at thinking in code that they become able to express everything in incredibly terse one-liners. This is when they start using ternary operators everywhere instead of if statements, or very obscure functional map/reduces instead of simple for loops.
Being able to write like this is obviously good, but that doesn't mean you should do it: just because you can cram everything into one line/statement, doesn't mean you should. This gig is not just about writing clever code, it's about writing code that others can read (as well as yourself, six months later) and reason about and debug easily.
Writing understandable code is not always the same as writing more verbose code, but the two are certainly correlated.
- UglyToad 5y agoThis is my take from writing object oriented code (I don't know how broadly applicable to functional languages it is). I started off writing code in a procedural style with no organisation. I was told that was bad so I created fragmented abstracted code where everything did very little across 10s of classes and methods. Now I write procedural style code again, I don't worry about long methods as long as the flow is obvious and the abstractions, used sparingly, feel right.
- samsquire 5y agoI'm the same. I'd rather inherit large methods that do a thing than an over abstracted mess of classes and methods that don't give you anything but noise.
- Swizec 5y ago> or very obscure functional map/reduces instead of simple for loops The functional programmer in me just died a little. Map and reduce are not obscure. They’re the basic building blocks! For loops, now that’s obscure. There’s like 5 different incantantions for a for loop in JavaScript alone. Each with its own subtle behavior differences.
- deleted 5y ago[deleted]
- OskarS 5y agoYou’re right, there’s nothing inherently wrong with map, reduce and the rest of the high-order functional suite. What I’m talking about more is when people make very complicated aggregation functions in order to keep state around. In these cases, simple for loops are usually much easier to read and as a bonus they’re almost always significantly faster. Not every problem benefits from a functional solution.
- ratww 5y agoI mean, sure, but the opposite is also true: Sometimes people make complicated incantations inside for loops (or worse, while loops) that could be replaced by simpler functional constructs. In these cases, map and friends are easier to read. The problem here is not one construct or the other, but the fact some people are making code that is hard to understand. There's no one size fit all solution.
- jhgb 5y ago> What I’m talking about more is when people make very complicated aggregation functions in order to keep state around Are we talking about languages without handy combinators? I can imagine that in these, turning stateless functions into stateful aggregators is going to be more obscure rather than easy. As for speed, that seems like an implementation issue. In principle a functional solution could still preserve more information for efficient code generation than a loop for which such information needs to be extracted from by complicated auto-vectorizers. In practice the environments aren't "quite there" (lack of such features as Common Lisp's compiler macros), and any potential or even realized benefits may be cancelled out by other performance issues of such environments.
- overgard 5y ago> As for speed, that seems like an implementation issue. At the end of the day though, it's still your issue, even if you can point at a 3rd party. Personally I'd rather have my fate in my own hands rather than wait on a "sufficiently smart optimizer"
- deleted 5y ago[deleted]