Can You Find the Bug in This Code?
41–50 of 64 posts
Re: Can You Find the Bug in This Code?
#42Earlier quoted context omitted.
>Just end lines with `;`. But that's not always the solution, you still need to know when ASI kicks in and when it doesn't. "just end lines with ;" isn't true in multi-line arrays, in multi-line objects, and a ton of other situations where a semi at the end of the line is a syntax error. And while i'm sure you know that and didn't actually mean "every" line, it just goes to show that you already have the knowledge of…
You're absolutely correct. Jey provided the better phrasing of my comment: Use `;` to end a statement. The point I'm making is more bias toward using `;`, even when not strictly "necessary". This brings JS's statement parsing in line with most other languages. And yes, absolutely use a linter.
He only ever worked with his favorite layout, and we worked with ours!
I'm not a big fan of holy wars in programming, i'm fine with either even if I do prefer one style over the other, but at the end of the day I just hope that everyone involved understands that it's just a preference thing for the most part. Linters will catch the edge cases for both styles, and if you really can't adapt to using or not using semicolons in javascript, there are probably other issues at play.
Re: Can You Find the Bug in This Code?
#43Re: Can You Find the Bug in This Code?
#44Re: Can You Find the Bug in This Code?
#45Earlier quoted context omitted.
Close to 100% of semi-colons are noise in any given project. That's why.
Samewithwhitespace.
Re: Can You Find the Bug in This Code?
#46Semicolons are usually optional in JS. The 'usually' part if why it's a good idea to enforce usage of them to avoid situations like this. You don't even need to do IEEs for this - running a function on an inline-declared array has a high probability of creeping the array up as an index on the previous expression.
No. It either does or it doesn't. The spec is not ambigous.
Learn how ASI works, or you will run into trouble no matter if you prefer semis or not.
Re: Can You Find the Bug in This Code?
#47The real bug is the failure to use semi-colons. I literally cannot comprehend the non-use of semi-colons in JS.
If so, the failure lies with the spec. (personally, I like ASI)
The explanations that have been given to me typically fall in line with, "well, to new comers, it won't make sense why you don't add a semicolon after a function declaration or if statement. I consider that a teaching moment.
But, I'll admit, this debate has little merit. Folks whom are dead set against using them are rarely convinced until they get bitten hard by a 2 hour hunt for an obscure bug. And folks that use them will probably end up with RSI or Emacs Pinky™
Re: Can You Find the Bug in This Code?
#48An even more common use-case that fails without semicolons by T.J. Crowder (2015): http://blog.niftysnippets.org/2015/09/automatic-semicolon-in... There are a number of cases where not having semicolons has its downsides, I'm yet to see a single case of an upside.
> I'm yet to see a single case of an upside. It's a signal of coolness from inexperienced programmers. That's the value proposition offered by semicolon-free JS.
Re: Can You Find the Bug in This Code?
#49Python and Ruby support semicolons for occasional statement termination; why is JavaScript any different? I can't help but think "semicolons by default" would be regarded as ritualistic if the practice was never popularized in the first place.
Re: Can You Find the Bug in This Code?
#50An even more common use-case that fails without semicolons by T.J. Crowder (2015): http://blog.niftysnippets.org/2015/09/automatic-semicolon-in... There are a number of cases where not having semicolons has its downsides, I'm yet to see a single case of an upside.
> I'm yet to see a single case of an upside. It's a signal of coolness from inexperienced programmers. That's the value proposition offered by semicolon-free JS.
No warning, no error and completely valid code. It really triggered my proverbial OCD. That one function out of ten where I made that typo.
So I stopped, and it was a major relief. Note that I didn't use a linter at that time.
I don't really mind semicolons in languages where they are enforced, but I also don't end statements in Python with semicolons.