3 ms·
I would respect the JavaScript so much more if there wasn't so much faddishness - somehow JS devs have decided switch statements are bad, indenting with 2 space
by labrador 10y ago
I would respect the JavaScript so much more if there wasn't so much faddishness - somehow JS devs have decided switch statements are bad, indenting with 2 spaces is the only way to go, semi-colons should be banished and "boilerplate" code should be hidden in libraries the magically wipe it away so your code looks "clean," if barely understandable without reading through a bunch of libs.
Edit: forgot to add that these are my initial impressions after diving into front end development with node and browserify. I ended up avoiding a lot of pain by just using TypeScript and a make file. Who has time to wade through umpteen million build systems?
- BinaryIdiot 10y ago> somehow JS devs have decided switch statements are bad Nonsense. Though sometimes using an object can look cleaner depending on your use case. > indenting with 2 spaces is the only way to go I love 4 spaces and I use 4 in my JavaScript projects. Just because you've seen some subset of people use 2 doesn't mean it's the majority, what you have to use, etc. > semi-colons should be banished Absolutely, positively NO. Semi-colons are a requirement of the language. Some people elide them, incorrectly, because the JavaScript engines are good enough to still handle it. In my experience being playing a limited part in open source JavaScript eliding the semi colon seems to be a rarely done practice. Regardless it's incorrect no matter how you slice it. > "boilerplate" code should be hidden in libraries the magically wipe it away so your code looks "clean," This sounds more like a rails-ism than a JavaScript-ism. Though you'd be hard pressed to find libraries without implicit behaviors in every language. Some people take DRY way too far. This point just seems more anecdotal than anything else. > a make file. Who has time to wade through umpteen million build systems? A lot of JavaScript devs use make. Nothing wrong with that.
- labrador 10y agoI'm heartened by your comment. I'm glad to be wrong on this.
- Roboprog 10y agoI think the semicolon requirement is more for broken minifiers than actually making the unpacked code clear/correct. But that's just me, I guess, as I have worked with many line oriented languages, and have no reverence for C syntax.
- Illniyar 10y ago> somehow JS devs have decided switch statements are bad huh. You obviously haven't played with Redux yet, it's basically switch statements all they way. The JS community is the biggest programming community in the world, there is no way you can lump anything on the community as a whole.
- timbuckley 10y agoIndeed, I've never seen anyone use anything but switch statements in Redux reducer functions.
- labrador 10y agoRedux is a wonderful piece of software and of course I use switch statements. I was referring to this question on reddit/r/javascript which kind of boggled my mind. I didn't know there were people advocating against switch statements. https://www.reddit.com/r/javascript/comments/2582qv/is_switch_ever_a_good_idea_in_javascript/ https://www.reddit.com/r/javascript/comments/2582qv/is_switc...
- Forlien 10y agoDid you link the wrong page? It looks like they are advocating switch statements.
- labrador 10y agoIf you read down, there are people against them. I didn't know this was a thing. The top comment is saying of course, switch statements are fine. There are other posts if you search for switch in r/JavaScript. This one is probably more indicative: https://www.reddit.com/r/javascript/comments/3a4ras/how_often_do_you_use_the_javascript_switch/ https://www.reddit.com/r/javascript/comments/3a4ras/how_ofte...
- Roboprog 10y agoC and its descendants does have a somewhat "broken" case statement. Pascal's was much less error prone. Putting in semicolons won't make the language NOT terminate a statement if you split a line in the wrong spot. (I suppose one solution would be just to put everything on one giant line, and separate the statements with semis, but, YUCK) Repetitive boilerplate should indeed be pushed down a level or two in any language, so the top of your program reads in terms of the business logic / problem space, not a bunch of code management noise. This is less traumatic if your functions have actual documentation for an IDE to display when a symbol is clicked on, rather than buying into the "self documenting" fairy tale. However, 2 spaces per level isn't visually very much. I don't need to nest things so deeply that I begrudge a few spaces per level. - - - - Static OOP was the shizzle back in the 80s (when we were learning about clones, often bad clones, of Simula 67). The last 10 years or so, though, I have really started to appreciate much (if not all) of what Lisp offered back in the day. Javascript is an acceptable Lisp.