5 ms·
I honestly never thought that much about the use of semicolons vs not. I'm not a hardcore JS programmer, I know enough to get paid for it, and I'm the best JS
by trickjarrett 16y ago
I honestly never thought that much about the use of semicolons vs not.
I'm not a hardcore JS programmer, I know enough to get paid for it, and I'm the best JS programmer of my current employer. But I'm far from a jedi master.
Isn't this just a matter of personal preference? A semi-colon is interchangable with \n as long as you use it following the same rules. Which I do because I treat it as a visual marker for the end of a statement.
The counter argument is why use it if the system already recognizes the \n in place there, for which I say to make it easier for other JS programmers to recognize and parse since the \n is used in other places where it isn't the end of a line.
I guess I don't really see this as a compelling argument being made here, or I've misunderstood what is being argued.
- JonnieCache 16y agoMost of the controversy stems from the fact that Doug Crockford, widely regarded as the javascript expert, has been aggressively saying "Use semicolons at the end of every statement or you will be miserable" for years, particularly in his influential book "Javascript - the Good Parts." You can see a presentation where he reiterates this point, among others, here: http://www.youtube.com/watch?v=hQVTIJBZook http://www.youtube.com/watch?v=hQVTIJBZook This blogger has a pretty compelling argument against this view.
- selectnull 16y agoActually, that's not what Crockford is saying. From the same link: "Figure out where the semicolons go. Put 'em in the right place. You'll be very much better off." That is a quote from 13:02 into the video. There is a trancript on the video, so you can read it too. I won't claim Doug has never said something like that, but I doubt it. I watched many of his videos that can be found and he is always evangelizing learning the language, instead of blindly cargo culting.
- JonnieCache 16y agoYou are totally right, I was paraphrasing somewhat flippantly, and I should have been more clear about this. Doug is definitely high up on the list of my most respected programmers, everyone should definitely take notice of what he says. Any person who is putting out that much good information will eventually lay themselves open to some criticism, its the inevitable consequence of doing so much work.
- jsight 16y agoYes, I agree... what Crockford says makes sense to me. Know where they go, and use them consistently. This blog post doesn't make so much sense. It seems to say that you should be aware of the rules at all times and strive to use as few semicolons as possible (even going so far as to put them in front of statements). Yes, it would work, but I don't really see this as more readable.
- IsaacSchlueter 16y agoMy recommendation to use minimal semicolons is a very weak suggestion. I took great care to make that clear, and to point out a few cases where it makes perfect sense to use more semicolons than strictly necessary. My recommendation against lying is much more forceful.