|
|
|
|
|
by TheOtherHobbes
4128 days ago
|
|
As someone pointed out, the implied semicolon isn't the problem. The problem is that the code is written in a way that makes it vulnerable to an implied semicolon. The core syntax of JavaScript won't be changing any time soon, so it's important to teach beginners how to write code that minimises mistakes like these. I haven't seen many books and tutorials attempt this. So it's unfair to blame beginners when there's so little encouragement to learn a strong defensive coding style. jshint is nice for basic sanity checks, but it can't deal with bigger structural or stylistic mistakes. You can only fix those by learning from strong examples of good, clean code. I think this applies to all languages. Being able to solve a problem and write a solution in code symbols isn't enough. I wonder if it would help everyone if there was a store of established best practices with examples for every language. |
|
Javascript's automagic semicolon is that, and you're the kind of person who condones it.
Yes, at the end of the day one has to learn how to deal with the automagic semicolon, if one doesn't just give up on Javascript wholesale and finds a way to write better languages. However the very presence and behavior of that code in every javascript interpreter is still a cruel misbehavior whose implementation was a mistake. It is just as cruel and as much of a mistake to imply even in the slightest way that it isn't.
The correct response is to not blame the coder who stumbles over that, but to gently let them know that yes, Javascript is a bad language, and to gracefully show them how to not fall into that trap.