Live data from Hacker News

No ifs...alternatives to statement branching in JavaScript

javascriptweblog.wordpress.com

41–45 of 45 posts

Re: No ifs...alternatives to statement branching in JavaScript

#41
post #40
post #39

Earlier quoted context omitted.

// I don't like the keyword "if" so I'm hiding it with && and || because I haven't thought deep enough about a better way of structuring my code // TODO think harder

I'm guessing you must be joking?

I'm trying to elicit a wry smile from those who understand but those comments describe the OP.

It's a cute trick, useful in shell scripts but not serious code where readability should trump cute & terse. When I clicked the title I too was expecting some kind of method dispatch. Lets get some ternaries in there too

    a && b || c ? (d || e) && f : f && d || h;

Re: No ifs...alternatives to statement branching in JavaScript

#42
post #41
post #40

Earlier quoted context omitted.

I'm guessing you must be joking?

I'm trying to elicit a wry smile from those who understand but those comments describe the OP. It's a cute trick, useful in shell scripts but not serious code where readability should trump cute & terse. When I clicked the title I too was expecting some kind of method dispatch. Lets get some ternaries in there too a && b || c ? (d || e) && f : f && d || h;

Did you read the entire article?

Re: No ifs...alternatives to statement branching in JavaScript

#43
post #42
post #41

Earlier quoted context omitted.

I'm trying to elicit a wry smile from those who understand but those comments describe the OP. It's a cute trick, useful in shell scripts but not serious code where readability should trump cute & terse. When I clicked the title I too was expecting some kind of method dispatch. Lets get some ternaries in there too a && b || c ? (d || e) && f : f && d || h;

Did you read the entire article?

Yes, it's the sort of thing every programmer goes through on the road to enlightenment

Re: No ifs...alternatives to statement branching in JavaScript

#44
post #43
post #42

Earlier quoted context omitted.

Did you read the entire article?

Yes, it's the sort of thing every programmer goes through on the road to enlightenment

You said "I don't like the keyword "if" so I'm hiding it with && and || because I haven't thought deep enough about a better way of structuring my code"

In addition to talking about ternaries, guards and defaults, the article discusses myriad techniques aimed at replacing conditional logic with entirely non-conditional approaches (both functional and oop).These include function dispatching, function delegation, use of high order functions, functions as data and polymorphism.

These techniques aren't going to work for everyone and it would be very cool if you chimed in with your own experiences. What's not cool is misrepresenting the article.

Re: No ifs...alternatives to statement branching in JavaScript

#45
post #44
post #43

Earlier quoted context omitted.

Yes, it's the sort of thing every programmer goes through on the road to enlightenment

You said "I don't like the keyword "if" so I'm hiding it with && and || because I haven't thought deep enough about a better way of structuring my code" In addition to talking about ternaries, guards and defaults, the article discusses myriad techniques aimed at replacing conditional logic with entirely non-conditional approaches (both functional and oop).These include function dispatching, function delegation, use o…

Also not cool is to be a patronizing prick. If I may sprinkle a bit of anti-troll powder: I liked your article and admire anyone who approaches his craft with that degree of thoughtfulness. There's relatively little flamewarism in this community overall, and you'd make a pretty good participant, so please feel welcome.
Post reply on HN