Hows this for hipster: these are all basic programming techniques that have existed for decades and barely need to be pointed out. Or have I missed the joke?<p>EDIT: this is "fake surprise" isn't it. I'm sorry HN. Everyone has to learn this stuff somewhere. But the title was kindof asking for it.<p>To any newly minted developers out there, the best way to learn this stuff is just to read other peoples code. Pick the library you enjoy using the most and read every file until you understand what all the constructions and bits of syntax are for. Then compare it to another library, etc etc. Develop a taste for some and a distaste for others. There's no excuse not to learn experimentally in js as it has a repl. Use the source luke!
Many of these are:<p>1) Much less legible, and in some cases outright lazy
2) Extremely vulnerable to Javascript's fast-and-loose type checking.<p>However it's good to be AWARE of them, since you tend to see them a lot in team projects.
While introducing new developers to work on the JS part of our codebase (node & client side) - I noticed some puzzled looks here and there.<p>Not everyone understands why && and || are used outside of if statements. Not everyone knows about joining strings using an array.<p>This summarises the things you'll have to know to read code in our codebase.
Non-slideshow link: <a href="http://berzniz.com/post/68001735765/javascript-hacks-for-hipsters" rel="nofollow">http://berzniz.com/post/68001735765/javascript-hacks-for-hip...</a><p>This may impugn my credibility as a professional developer, but I genuinely can't tell if this article is sarcastic or sincere.
For some reason the entire thing reads to me as a guide to writing Javascript like an experienced Perl developer. Either way, it's really cool to see people advocating an idiomatic style for JS. :)
One I've never thought of using before is the:
isAwesome && alert("yay");<p>I have used the name || "no name" operator a lot and thought to myself that it looked cool on first impression. But having something like:
isAwesome() && alert("yay");
Already makes it harder to read I think. I'm curious to what others think of this one? Maybe its just because it is new to me..
IMHO, hipster JavaScript is called CoffeeScript.<p><pre><code> 1) do obj[if success then 'start' else 'stop']
2) ['milk', 'coffee', 'sugar'].join ', '
3) doStuff = (options = {}) ->
4) isThisAwesome?()
5) ### ... ###
6-8) ...
9) template = "Hi, my name is #{firstName} and my twitter screen name is @#{screenName}"
</code></pre>
[1] <a href="http://coffeescript.org/#try:do%20obj%5Bif%20success%20then%20'start'%20else%20'stop'%5D%0A%0A%5B'milk'%2C%20'coffee'%2C%20'sugar'%5D.join%20'%2C%20'%0A%0AdoStuff%20%3D%20(options%20%3D%20%7B%7D)%20-%3E%0A%0AisThisAwesome%3F()%0A%0Atemplate%20%3D%20%22Hi%2C%20my%20name%20is%20%23%7BfirstName%7D%20and%20my%20twitter%20screen%20name%20is%20%40%23%7BscreenName%7D%22" rel="nofollow">http://coffeescript.org/#try:do%20obj%5Bif%20success%20then%...</a>
This was originally published a year ago in this blog post:<p><a href="http://berzniz.com/post/68001735765/javascript-hacks-for-hipsters" rel="nofollow">http://berzniz.com/post/68001735765/javascript-hacks-for-hip...</a><p>Makes for a nicer read than slideshare imo.
I have read a few places recently about techniques and strategies to get rid of ifs and else's in code. It was all in the spirit of writing more concise and compact code, not about the actual speed when executing the code. So often, I see "concise" at odds with "readability." The '&&' slide is a good example of this. For me, multi-line if/else statements are pretty easy to read. I hate running into complicated, one line, if else statements, it feels to me that it takes twice as long to parse and understand.
Someone needs to clarify to me why people are excited about this. Isn't this just horrible for readability?<p>I've just started reading Clean Code, and there is a lot of emphasis on writhing readable code, because the philosophy is that code is only written once but read many times.
I have witnessed many of these on some JS projects I've been working on!
While I took time to think on it and figure out what the "author" was aiming at, my colleagues were more like "What does this mean? No way I'm touching that. Let's rewrite that crap!"
I'm actually not sure whether this is a joke or not, some of these practices like #1, #4 and even #5 reek of amateurish programming practices - maybe this is fine for your own pet projects, but if you're working with teams or on open source then have fun!
Hey, I love neat Javascript tricks... but things like the "TODO" operator are really bad style and will hurt larger teams.<p>Stick to standards, so ease-of-communication is simpler! The reality is that collaboration is harder than programming!
Some of these are mildly useful, but not sure it deserves front page.<p>I like using .filter, .forEach and .map native methods on arrays. Also making use of Underscore.js where possible.