News for hackers. Stuff that matters.
Re:No ifs...alternatives to statement branching in JavaScript by BoppreH on Friday August 06, 2010 @07:02PM (#1582586)
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.

Re:No ifs...alternatives to statement branching in JavaScript by mrj on Friday August 06, 2010 @07:58PM (#1582692)
What 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).

Re:No ifs...alternatives to statement branching in JavaScript by BoppreH on Friday August 06, 2010 @11:27PM (#1583002)
It 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.

Re:No ifs...alternatives to statement branching in JavaScript by mrj on Saturday August 07, 2010 @01:29PM (#1583892)
Maybe 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.

Re:No ifs...alternatives to statement branching in JavaScript by ori_b on Friday August 06, 2010 @11:37PM (#1583013)
This isn't a functional technique! Functional languages remove assignments and mutable variables. Not branches.
Re:No ifs...alternatives to statement branching in JavaScript by BoppreH on Friday August 06, 2010 @11:47PM (#1583022)
Branches too. The only conditionals I've seen in functional programming are equivalent to the ternary operator.

Unless I'm absurdly wrong, which can happen.

Re:No ifs...alternatives to statement branching in JavaScript by davidw on Saturday August 07, 2010 @02:24AM (#1583168)
The program still branches (decides which code path to follow) - it just does it with a different mechanism, for instance pattern matching.
Re:No ifs...alternatives to statement branching in JavaScript by BoppreH on Saturday August 07, 2010 @03:05PM (#1584081)
Yes, pattern matching fits the bill, thanks.
Re:No ifs...alternatives to statement branching in JavaScript by ori_b on Saturday August 07, 2010 @10:52AM (#1583633)
I think codesearch can answer you: http://www.google.com/codesearch?q=if+lang%3Ahaskell
Re:No ifs...alternatives to statement branching in JavaScript by BoppreH on Saturday August 07, 2010 @03:02PM (#1584076)
"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.