3 ms·
I'm a very young coder and loved the article, especially how it brings functional features to imperative languages. But what if I write the entire company fram
by BoppreH 16y ago
I'm a very young coder and loved the article, especially how it brings functional features to imperative languages.
But what if I write the entire company framework without a single conditional (including loops)? Are this alternatives to be used sparingly or as much as possible? Would you frown upon when you see it?
On a side note, I would love to never see a conditional again Even before learning functional programming I felt bad at every "if" and especially every "for" loop, but now I know why.
- mrj 16y agoWhat if you did? Would it be a better framework? Would anybody care at all? I doubt it. This a code style and if you like it, then maybe you use the parts you want. But "micro branching" is still branching and it makes little difference how you do it (except the nod to performance concerns towards the end). Thinking about code style and readability is useful and good, but this is by no means a common way to code. Beware of excess cleverness. It would be far better to worry about the correctness of the code rather than optimizing for a meaningless benchmark (no ifs).
- BoppreH 16y agoIt would not be for cleverness, much less for optimization (is it even faster?) For some reason every time I see a condition I cringe mentally. There's something in a "for" loop that makes me uncomfortable and god, using "map", "filter" and micro branching would help a lot. I'm just thinking of what I would like to see and checking it against the opinion of others.
- mrj 16y agoMaybe it's a coding style that suits you then. That's cool. I just caution against putting it in such simple terms. I hate it when I read code by somebody who latched on to the latest trend and then ruthlessly bent their style to match the new way, whether it made sense or not. As for performance, it would have to be tested. In some languages with first-class closures, a lot of code like the examples might seriously strain the garbage collector (if present). There might be a ton of young objects to clean up, all the time. That was my only thought on it.
- ori_b 16y agoThis isn't a functional technique! Functional languages remove assignments and mutable variables. Not branches.
- BoppreH 16y agoBranches too. The only conditionals I've seen in functional programming are equivalent to the ternary operator. Unless I'm absurdly wrong, which can happen.
- davidw 16y agoThe program still branches (decides which code path to follow) - it just does it with a different mechanism, for instance pattern matching.
- BoppreH 16y agoYes, pattern matching fits the bill, thanks.
- ori_b 16y agoI think codesearch can answer you: http://www.google.com/codesearch?q=if+lang%3Ahaskell http://www.google.com/codesearch?q=if+lang%3Ahaskell
- BoppreH 16y ago"if"s in Haskell work exactly like the ternary operators, just as I said. I was using the article's differentiation of "branching" and "microbranching" and stating that I haven't seen the former in functional languages. The link provided doesn't contradict any of this, actually it does quite the opposite.