New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap-dropdown.js clearMenus() needs ; at the end #3057

Closed
englishextra opened this Issue Apr 13, 2012 · 289 comments

Comments

Projects
None yet
@englishextra

englishextra commented Apr 13, 2012

bootstrap-dropdown.js when minified with JSMin::minify produces error in Firefox error console saying clearMenus()needs ;

on line:

  clearMenus()
  !isActive && $parent.toggleClass('open')

if in source code this is corrected -- no error in minified version

@fat

This comment has been minimized.

Show comment
Hide comment
@fat

fat Apr 14, 2012

Member

nope - that's a bug in jsmin. Probably should let @douglascrockford know about it though. thanks!

edit: The code had already been changed to an if when i suggested the jsmin issue be filed as a bug. Bootstrap and jsmin play very well together.

Member

fat commented Apr 14, 2012

nope - that's a bug in jsmin. Probably should let @douglascrockford know about it though. thanks!

edit: The code had already been changed to an if when i suggested the jsmin issue be filed as a bug. Bootstrap and jsmin play very well together.

@fat fat closed this Apr 14, 2012

@douglascrockford

This comment has been minimized.

Show comment
Hide comment
@douglascrockford

douglascrockford Apr 14, 2012

That is insanely stupid code. I am not going to dumb down JSMin for this case.

douglascrockford commented Apr 14, 2012

That is insanely stupid code. I am not going to dumb down JSMin for this case.

@douglascrockford

This comment has been minimized.

Show comment
Hide comment
@douglascrockford

douglascrockford Apr 14, 2012

TC39 is considering the use of ! as an infix operator. This code will break in the future. Fix it now. Learn to use semicolons properly. ! is not intended to be a statement separator. ; is.

douglascrockford commented Apr 14, 2012

TC39 is considering the use of ! as an infix operator. This code will break in the future. Fix it now. Learn to use semicolons properly. ! is not intended to be a statement separator. ; is.

@fat

This comment has been minimized.

Show comment
Hide comment
@fat

fat Apr 15, 2012

Member

i have learned to use them, that's why there isn't one present.

Member

fat commented Apr 15, 2012

i have learned to use them, that's why there isn't one present.

@kitcambridge

This comment has been minimized.

Show comment
Hide comment
@kitcambridge

kitcambridge Apr 15, 2012

i have learned to use them, that's why there isn't one present.

Zzzzing!

kitcambridge commented Apr 15, 2012

i have learned to use them, that's why there isn't one present.

Zzzzing!

@sferik sferik referenced this issue Apr 15, 2012

Closed

Add semicolon #3069

@backspaces

This comment has been minimized.

Show comment
Hide comment
@backspaces

backspaces Apr 15, 2012

Any language with syntax arguments is clearly broken, compilers deal with this. Dart, I guess.

backspaces commented Apr 15, 2012

Any language with syntax arguments is clearly broken, compilers deal with this. Dart, I guess.

@stephenhandley

This comment has been minimized.

Show comment
Hide comment
@adrusi

This comment has been minimized.

Show comment
Hide comment
@adrusi

adrusi Apr 15, 2012

if you really wanted to get rid of the semicolons (though I really don't see the point of that, is it really that bad that it's worth worrying about it?), ! ... && in this context an be replaced with ... ||.

adrusi commented Apr 15, 2012

if you really wanted to get rid of the semicolons (though I really don't see the point of that, is it really that bad that it's worth worrying about it?), ! ... && in this context an be replaced with ... ||.

@coolaj86

This comment has been minimized.

Show comment
Hide comment
@coolaj86

coolaj86 Apr 15, 2012

coffeescript ftw?

otherwise, if you're doing real javascript, do it right?

p.s. (I'm not a coffeescripter yet, but it looks more and more like the right tool every day)

coolaj86 commented Apr 15, 2012

coffeescript ftw?

otherwise, if you're doing real javascript, do it right?

p.s. (I'm not a coffeescripter yet, but it looks more and more like the right tool every day)

@zacstewart

This comment has been minimized.

Show comment
Hide comment
@zacstewart

zacstewart Apr 15, 2012

i have learned to use them, that's why there isn't one present.

Wow. I've read @fat's reasoning for not using semis, but when it comes to actual problems cropping up in the real world, why does "aesthetic" preference take precedence? Why write something like

!function( $ ){
...
}( jQuery )

just to avoid placing a semi a the end?

! is clearly not meant to do this job. It's a bool operator. Does the fact that the symbol looks prettier really matter?

I am well aware that you can hack your way around this and keep saying "nuh uh!" instead of admitting that it's ill conceived and improving, but seriously: making a snippy response like that just makes you look like an immature hipster smarting off to a battle worn professional. @douglascrockford is on the technical committee for fuck's sake.

zacstewart commented Apr 15, 2012

i have learned to use them, that's why there isn't one present.

Wow. I've read @fat's reasoning for not using semis, but when it comes to actual problems cropping up in the real world, why does "aesthetic" preference take precedence? Why write something like

!function( $ ){
...
}( jQuery )

just to avoid placing a semi a the end?

! is clearly not meant to do this job. It's a bool operator. Does the fact that the symbol looks prettier really matter?

I am well aware that you can hack your way around this and keep saying "nuh uh!" instead of admitting that it's ill conceived and improving, but seriously: making a snippy response like that just makes you look like an immature hipster smarting off to a battle worn professional. @douglascrockford is on the technical committee for fuck's sake.

@dubcanada

This comment has been minimized.

Show comment
Hide comment
@dubcanada

dubcanada Apr 15, 2012

This has nothing to do with being a hipster, and I have no idea why anyone seems to think it does. The simple fact is this code runs on ALL browsers without issue. Regardless if the fact that X version of javascript somewhere in the Y future will stop supporting it (maybe) does NOT give a reason for a javascript minifier to NOT correctly minify it.

Also if Crockford thinks this is insanely stupid code and he is on the technical committee then why is this insanely stupid code even possible?

dubcanada commented Apr 15, 2012

This has nothing to do with being a hipster, and I have no idea why anyone seems to think it does. The simple fact is this code runs on ALL browsers without issue. Regardless if the fact that X version of javascript somewhere in the Y future will stop supporting it (maybe) does NOT give a reason for a javascript minifier to NOT correctly minify it.

Also if Crockford thinks this is insanely stupid code and he is on the technical committee then why is this insanely stupid code even possible?

@davidk01

This comment has been minimized.

Show comment
Hide comment
@davidk01

davidk01 Apr 15, 2012

I know who @douglascrockford is but who is this @fat fellow?

davidk01 commented Apr 15, 2012

I know who @douglascrockford is but who is this @fat fellow?

@zacstewart

This comment has been minimized.

Show comment
Hide comment
@zacstewart

zacstewart Apr 15, 2012

Also if Crockford thinks this is insanely stupid code and he is on the technical committee then why is this insanely stupid code even possible?

Being on the technical committee in 2012 for a language initially created 16 years ago probably doesn't grant him authority to radically change things like that.

zacstewart commented Apr 15, 2012

Also if Crockford thinks this is insanely stupid code and he is on the technical committee then why is this insanely stupid code even possible?

Being on the technical committee in 2012 for a language initially created 16 years ago probably doesn't grant him authority to radically change things like that.

@mdo

This comment has been minimized.

Show comment
Hide comment
@mdo

mdo Apr 15, 2012

Member

@zacstewart Jacob wasn't trying to snippy, he was responding directly to one person's aggressive remarks. Taken out of context I can understand how it might look that way, but side-by-side, there's no issue there.

All Jacob pointed out was that this is a bug in someone else's code and that guy comes in guns blazing instead of speaking calmly and objectively? I call bullshit on the whole situation. If semicolons aren't required, then we don't need to include them. It's as simple as that.

Member

mdo commented Apr 15, 2012

@zacstewart Jacob wasn't trying to snippy, he was responding directly to one person's aggressive remarks. Taken out of context I can understand how it might look that way, but side-by-side, there's no issue there.

All Jacob pointed out was that this is a bug in someone else's code and that guy comes in guns blazing instead of speaking calmly and objectively? I call bullshit on the whole situation. If semicolons aren't required, then we don't need to include them. It's as simple as that.

@jack9

This comment has been minimized.

Show comment
Hide comment
@jack9

jack9 Apr 15, 2012

The simple fact is this code runs on ALL browsers without issue. Regardless if the fact that X version of javascript somewhere in the Y future will stop supporting it (maybe) does NOT give a reason for a javascript minifier to NOT correctly minify it.

Forcing unwanted paradigms has no business in code reviews.

Tools that reformat code can break code if the code is dependent on whitespace. Javascript is dependent on whitespace due to semicolon insertion. Javascript minification is not part of the language. So the code is correct for the author and they should not use a tool that breaks it.

I agree that the code runs and my first statement speaks to the freedom of an author to do as they wish. The freedom to code as they see fit. Those are compelling reason to NOT change it. However, the reality is that very few individuals will use the code unminified and the question of "correctness" falls to common convention as a matter of pragmatism. The middleground is to add a semicolon for general use of the code. Branch it and have a nice bootstrap-dropdown-minification_safe.js - There's nothing wrong with changing the code as you see fit to meet your needs.

Do not demand to change a tool because you want to use the tool in a way another author has explicitly said they will not support. That's hypocrisy. That's why people are getting upset.

jack9 commented Apr 15, 2012

The simple fact is this code runs on ALL browsers without issue. Regardless if the fact that X version of javascript somewhere in the Y future will stop supporting it (maybe) does NOT give a reason for a javascript minifier to NOT correctly minify it.

Forcing unwanted paradigms has no business in code reviews.

Tools that reformat code can break code if the code is dependent on whitespace. Javascript is dependent on whitespace due to semicolon insertion. Javascript minification is not part of the language. So the code is correct for the author and they should not use a tool that breaks it.

I agree that the code runs and my first statement speaks to the freedom of an author to do as they wish. The freedom to code as they see fit. Those are compelling reason to NOT change it. However, the reality is that very few individuals will use the code unminified and the question of "correctness" falls to common convention as a matter of pragmatism. The middleground is to add a semicolon for general use of the code. Branch it and have a nice bootstrap-dropdown-minification_safe.js - There's nothing wrong with changing the code as you see fit to meet your needs.

Do not demand to change a tool because you want to use the tool in a way another author has explicitly said they will not support. That's hypocrisy. That's why people are getting upset.

@s3u

This comment has been minimized.

Show comment
Hide comment
@s3u

s3u Apr 15, 2012

Learn to interop with existing toolset folks! This is a ridiculous debate.

s3u commented Apr 15, 2012

Learn to interop with existing toolset folks! This is a ridiculous debate.

@devinrhode2

This comment has been minimized.

Show comment
Hide comment
@devinrhode2

devinrhode2 Apr 15, 2012

Semicolons ARE the recommended practice... not just from Crockford, but also in Google's JS style guide: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Semicolons

devinrhode2 commented Apr 15, 2012

Semicolons ARE the recommended practice... not just from Crockford, but also in Google's JS style guide: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Semicolons

@markjreed

This comment has been minimized.

Show comment
Hide comment
@markjreed

markjreed Apr 15, 2012

@eligrey - line break or not, Javascript never ends a statement if the next token is an infix or bracket operator. See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Semicolons for some possibly surprising examples.

So if ! becomes an infix op, then newline + ! will no longer be equivalent to ; + !.

markjreed commented Apr 15, 2012

@eligrey - line break or not, Javascript never ends a statement if the next token is an infix or bracket operator. See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Semicolons for some possibly surprising examples.

So if ! becomes an infix op, then newline + ! will no longer be equivalent to ; + !.

@tszming

This comment has been minimized.

Show comment
Hide comment
@tszming

tszming Apr 15, 2012

nope - that's a bug in IE. Probably should let @billgates know about it though. thanks!

Do you agree with this?

While I agree that JSMin can be improved for this case, but you also :)

tszming commented Apr 15, 2012

nope - that's a bug in IE. Probably should let @billgates know about it though. thanks!

Do you agree with this?

While I agree that JSMin can be improved for this case, but you also :)

@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 15, 2012

If anyone is curious about the TC39 proposed syntax for the ! infix operator, here it is

frewsxcv commented Apr 15, 2012

If anyone is curious about the TC39 proposed syntax for the ! infix operator, here it is

@englishextra

This comment has been minimized.

Show comment
Hide comment
@englishextra

englishextra Apr 15, 2012

Disagree with Mr. @fat approach: you distribute the code to developers and don't want to listen to good practices that are advised. I would have refactored the code when I had faced complaints from the users.

englishextra commented Apr 15, 2012

Disagree with Mr. @fat approach: you distribute the code to developers and don't want to listen to good practices that are advised. I would have refactored the code when I had faced complaints from the users.

@jace

This comment has been minimized.

Show comment
Hide comment
@jace

jace Apr 15, 2012

Thanks to the stand-off on this issue, I have to maintain my own branch of Bootstrap with semicolons inserted so that it minifies gracefully. Keeping my repo in sync is not fun at all, so I'm deploying out-of-date versions with my apps.

Given how much pain making production use of Bootstrap was, it felt like a version 0.2, not 2.0.

jace commented Apr 15, 2012

Thanks to the stand-off on this issue, I have to maintain my own branch of Bootstrap with semicolons inserted so that it minifies gracefully. Keeping my repo in sync is not fun at all, so I'm deploying out-of-date versions with my apps.

Given how much pain making production use of Bootstrap was, it felt like a version 0.2, not 2.0.

@devinrhode2

This comment has been minimized.

Show comment
Hide comment
@devinrhode2

devinrhode2 Apr 15, 2012

Clearly JSMIn isn't changing. That means Bootstrap can either add semicolons, or have people run into this issue again with JSMin. That's stupid, just use semi-colons.

Also, being a hugely popular library, people who have never developed a thing in their life are probably going to learn from bootstrap code - and emulate it. Then this newbie is screwed. Some brave soul decides to get his idea into the real world, finds bootstrap as it's the best thing out there for making beautiful apps, seeks to modify things, and picks up bad habits. Embracing bad habits is a dis-service to the whole JS community.

That's not cool.

Newbies are going to use bootstrap. They are going to learn from bootstrap.

devinrhode2 commented Apr 15, 2012

Clearly JSMIn isn't changing. That means Bootstrap can either add semicolons, or have people run into this issue again with JSMin. That's stupid, just use semi-colons.

Also, being a hugely popular library, people who have never developed a thing in their life are probably going to learn from bootstrap code - and emulate it. Then this newbie is screwed. Some brave soul decides to get his idea into the real world, finds bootstrap as it's the best thing out there for making beautiful apps, seeks to modify things, and picks up bad habits. Embracing bad habits is a dis-service to the whole JS community.

That's not cool.

Newbies are going to use bootstrap. They are going to learn from bootstrap.

@tbranyen

This comment has been minimized.

Show comment
Hide comment
@tbranyen

tbranyen Apr 15, 2012

Don't use JSMin with this project. Write documentation for newbies explaining why they shouldn't use JSMin. Don't tell the maintainer he has to do x or y for his own project. Fork it if you feel strongly enough to change the code.

@fat shouldn't change his code to work with JSMin and @douglascrockford shouldn't change his code so bootstrap can work with it. Just document why it doesn't work and move on?

tbranyen commented Apr 15, 2012

Don't use JSMin with this project. Write documentation for newbies explaining why they shouldn't use JSMin. Don't tell the maintainer he has to do x or y for his own project. Fork it if you feel strongly enough to change the code.

@fat shouldn't change his code to work with JSMin and @douglascrockford shouldn't change his code so bootstrap can work with it. Just document why it doesn't work and move on?

@jyap808

This comment has been minimized.

Show comment
Hide comment
@jyap808

jyap808 Apr 15, 2012

Agreed, if you're making a general purpose tool like Twitter Bootstrap, make it as compliant as possible and use good practices.

Don't be a JavaScript hipster. Add semi-colons.

This is JavaScript. Relying on implicit insertion of semi-colons is stupid.

jyap808 commented Apr 15, 2012

Agreed, if you're making a general purpose tool like Twitter Bootstrap, make it as compliant as possible and use good practices.

Don't be a JavaScript hipster. Add semi-colons.

This is JavaScript. Relying on implicit insertion of semi-colons is stupid.

@chuckbergeron

This comment has been minimized.

Show comment
Hide comment
@chuckbergeron

chuckbergeron Apr 15, 2012

This minifies just fine via Rails' asset precompiling - I've never ran into an issue with it. IMHO, this is my issue with JavaScript as a language being much too flexible and forgiving.

chuckbergeron commented Apr 15, 2012

This minifies just fine via Rails' asset precompiling - I've never ran into an issue with it. IMHO, this is my issue with JavaScript as a language being much too flexible and forgiving.

@ajacksified

This comment has been minimized.

Show comment
Hide comment
@ajacksified

ajacksified Apr 15, 2012

tl;dr: use Coffeescript if you don't want semicolons.

Semicolonless Javascript is an ego-stroking attempt at rejecting standards for the sake of rejecting standards, not for the greater benefit of the community. While the need for hacks exists just to get around using semicolons, the practice does greater harm than good. "Use semicolons at the end of a statement" is a far simpler rule than "never use semicolons, except sometimes you have to use x hack, like prefixing with a !." All this for the benefit of an opinionated aesthetic? I propose that one might as well use Coffeescript instead, if the intent is prettier code by standards set as a lack of syntactic symbols.

Or, just write clean, standard (as defined by not just the specification, but as defined by the developer community) Javascript, if it is to be shared, used, and contributed to by the greater community.

ajacksified commented Apr 15, 2012

tl;dr: use Coffeescript if you don't want semicolons.

Semicolonless Javascript is an ego-stroking attempt at rejecting standards for the sake of rejecting standards, not for the greater benefit of the community. While the need for hacks exists just to get around using semicolons, the practice does greater harm than good. "Use semicolons at the end of a statement" is a far simpler rule than "never use semicolons, except sometimes you have to use x hack, like prefixing with a !." All this for the benefit of an opinionated aesthetic? I propose that one might as well use Coffeescript instead, if the intent is prettier code by standards set as a lack of syntactic symbols.

Or, just write clean, standard (as defined by not just the specification, but as defined by the developer community) Javascript, if it is to be shared, used, and contributed to by the greater community.

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra Apr 15, 2012

@douglascrockford: Regardless of whether you consider this usage of ASI a bug, it'd be ignorant not to acknowledge that there certainly is a bug in JSMin.

michaelficarra commented Apr 15, 2012

@douglascrockford: Regardless of whether you consider this usage of ASI a bug, it'd be ignorant not to acknowledge that there certainly is a bug in JSMin.

@aroc

This comment has been minimized.

Show comment
Hide comment
@aroc

aroc Apr 15, 2012

At the end of the day, the repo maintainers can do whatever they please. We're not paying to use Bootstrap. They can include ASCII fingers all over the place if it makes them happy. If we don't like it, we can use something else or fork it. That said, I still think this discussion is valuable (minus the aggression), as these sorts of conversations get people thinking more deeply about code standards and how they fit into our everyday work as developers.

aroc commented Apr 15, 2012

At the end of the day, the repo maintainers can do whatever they please. We're not paying to use Bootstrap. They can include ASCII fingers all over the place if it makes them happy. If we don't like it, we can use something else or fork it. That said, I still think this discussion is valuable (minus the aggression), as these sorts of conversations get people thinking more deeply about code standards and how they fit into our everyday work as developers.

@stephenhandley

This comment has been minimized.

Show comment
Hide comment
@jrz

This comment has been minimized.

Show comment
Hide comment
@jrz

jrz Apr 15, 2012

Even though a semicolon might be 'better'. The syntax is correct, and jsmin should NEVER change or break working code.
Period. so either stop using jsmin, or start fixing jsmin.

jrz commented Apr 15, 2012

Even though a semicolon might be 'better'. The syntax is correct, and jsmin should NEVER change or break working code.
Period. so either stop using jsmin, or start fixing jsmin.

@courthead

This comment has been minimized.

Show comment
Hide comment
@courthead

courthead Apr 15, 2012

@ChadMoran I believe he's talking about putting the ! in front of that code.

courthead commented Apr 15, 2012

@ChadMoran I believe he's talking about putting the ! in front of that code.

@jonashaag

This comment has been minimized.

Show comment
Hide comment
@jonashaag

jonashaag Apr 15, 2012

@ChadMoran I think the point is function(){...}(); vs !function(){...}()

jonashaag commented Apr 15, 2012

@ChadMoran I think the point is function(){...}(); vs !function(){...}()

@englishextra

This comment has been minimized.

Show comment
Hide comment
@englishextra

englishextra Apr 15, 2012

/* Title: Immediate functions
Description: syntax that enables function execution as soon as it is defined
*/

(function () {
console.log('watch out!');
}());

//alternative with less parentheses
!function () {
console.log('watch out!');
}();

// reference
// http://www.jspatterns.com/
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate

englishextra commented Apr 15, 2012

/* Title: Immediate functions
Description: syntax that enables function execution as soon as it is defined
*/

(function () {
console.log('watch out!');
}());

//alternative with less parentheses
!function () {
console.log('watch out!');
}();

// reference
// http://www.jspatterns.com/
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate

@teiman

This comment has been minimized.

Show comment
Hide comment
@teiman

teiman Apr 15, 2012

The point of using C syntax is to have ";" and "{" "}" to make sysntax and flow intend obvious to other programmers. This code is not obvious to other programmers (its not to me) so fix it by adding ";" on the end of expressions. Thanks.

teiman commented Apr 15, 2012

The point of using C syntax is to have ";" and "{" "}" to make sysntax and flow intend obvious to other programmers. This code is not obvious to other programmers (its not to me) so fix it by adding ";" on the end of expressions. Thanks.

@istvan-antal

This comment has been minimized.

Show comment
Hide comment
@istvan-antal

istvan-antal Apr 15, 2012

I don't think talking this much about a semicolon is worth it.

Does refusing to use a semicolon make the code go faster? NO
Does it make the code harder to read and understand? YES
Will it break in the future? Probably
Does it have the bigger potential for future bugs? YES

Semicolon insertion was a mistake in JavaScript, along with eval, with and function scoping. People should be avoiding these instead of abusing them.

Semicolons are better for readability: if I see a diff, I know exactly where the line ends.

istvan-antal commented Apr 15, 2012

I don't think talking this much about a semicolon is worth it.

Does refusing to use a semicolon make the code go faster? NO
Does it make the code harder to read and understand? YES
Will it break in the future? Probably
Does it have the bigger potential for future bugs? YES

Semicolon insertion was a mistake in JavaScript, along with eval, with and function scoping. People should be avoiding these instead of abusing them.

Semicolons are better for readability: if I see a diff, I know exactly where the line ends.

@pyalot

This comment has been minimized.

Show comment
Hide comment
@pyalot

pyalot Apr 15, 2012

I take it you really read ecmascript262 (and I assume you did because you use it as an excuse for the bad practice of omitting semicolons) then you should realize that JS grammar is ambiguous. It's particularly ambiguous where it's about what constitutes a statement if you omit a semicolon. Browsers implement heuristics when trying to parse it (a fancy word for guessing) and as a result don't always agree between each other. Because humans aren't very good at parsing a context-sensitive grammar and executing an approximate state-machine and if/else decision tree to figure out if something is a statement or not, we punny humans tend to do it wrong every once in a while, even if we're extremely well versed and hold the entire JS grammar in our heads (which would be a considerable feat).

Fortunately, there's a "fix" for this lamentable human condition. The fix is just to insert semicolons, even though technically it's not required in all cases. But I promise you, the time wasted writing out that semicolon is more than compensated by the time you will not spend hunting down heisenbugs due to browsers differing understanding of statements, the time not spent trying to make your JS code compatible to all JS-manglers (like JSmin, closure compiler etc.), the time not spent arguing in favor of an outdated and obviously bad practice with random people on the internet AND the time not spent fixing all your code when a browser implements a newer revision of JS.

pyalot commented Apr 15, 2012

I take it you really read ecmascript262 (and I assume you did because you use it as an excuse for the bad practice of omitting semicolons) then you should realize that JS grammar is ambiguous. It's particularly ambiguous where it's about what constitutes a statement if you omit a semicolon. Browsers implement heuristics when trying to parse it (a fancy word for guessing) and as a result don't always agree between each other. Because humans aren't very good at parsing a context-sensitive grammar and executing an approximate state-machine and if/else decision tree to figure out if something is a statement or not, we punny humans tend to do it wrong every once in a while, even if we're extremely well versed and hold the entire JS grammar in our heads (which would be a considerable feat).

Fortunately, there's a "fix" for this lamentable human condition. The fix is just to insert semicolons, even though technically it's not required in all cases. But I promise you, the time wasted writing out that semicolon is more than compensated by the time you will not spend hunting down heisenbugs due to browsers differing understanding of statements, the time not spent trying to make your JS code compatible to all JS-manglers (like JSmin, closure compiler etc.), the time not spent arguing in favor of an outdated and obviously bad practice with random people on the internet AND the time not spent fixing all your code when a browser implements a newer revision of JS.

@shawwn

This comment has been minimized.

Show comment
Hide comment
@shawwn

shawwn Apr 15, 2012

Hello everyone,

I've forked JSMin and implemented the desired behavior: https://github.com/shawnpresser/JSMin

It scans for "newline [whitespace] exclamation" and replaces the newline with a semicolon.

I hope this proves useful to someone (perhaps to the authors of Bootstrap). It was a fun project.

shawwn commented Apr 15, 2012

Hello everyone,

I've forked JSMin and implemented the desired behavior: https://github.com/shawnpresser/JSMin

It scans for "newline [whitespace] exclamation" and replaces the newline with a semicolon.

I hope this proves useful to someone (perhaps to the authors of Bootstrap). It was a fun project.

@ShaggyDude

This comment has been minimized.

Show comment
Hide comment
@ShaggyDude

ShaggyDude May 25, 2012

@ scryptonite
"whether brackets go on the same, or next line"
Ask crockford about that one also!

ShaggyDude commented May 25, 2012

@ scryptonite
"whether brackets go on the same, or next line"
Ask crockford about that one also!

@freeall

This comment has been minimized.

Show comment
Hide comment
@freeall

freeall Jun 8, 2012

I missed parts of this. What did we all agree on in the end?

freeall commented Jun 8, 2012

I missed parts of this. What did we all agree on in the end?

@englishextra

This comment has been minimized.

Show comment
Hide comment
@englishextra

englishextra Jun 22, 2012

In the end the guy who considers himself a hypster engineer wrapped the stuff into if statemanet:

clearMenus()

  if (!isActive) $parent.toggleClass('open')

Furthermore he twitted that "The only reason I [fat] don't use semicolons is to troll people."

There we are. http://www.youtube.com/watch?v=hQVTIJBZook -- Let the artists troll people and profs go on with the real progress

englishextra commented Jun 22, 2012

In the end the guy who considers himself a hypster engineer wrapped the stuff into if statemanet:

clearMenus()

  if (!isActive) $parent.toggleClass('open')

Furthermore he twitted that "The only reason I [fat] don't use semicolons is to troll people."

There we are. http://www.youtube.com/watch?v=hQVTIJBZook -- Let the artists troll people and profs go on with the real progress

@pete-otaqui

This comment has been minimized.

Show comment
Hide comment
@pete-otaqui

pete-otaqui Jul 4, 2012

I guess this is lost amongst the noise, but I think it's best to listen to Brendan Eich discussing this thread and Automatic Semicolon Insertion (ASI):

ASI is (formally speaking) a syntactic error correction procedure

The point is that semi colons are actually required, it's just that your error in excluding them can be automatically corrected (in most cases). So it seems clear to me that it's better to write correct code, in the format as it will be when actually run, rather than rely on automatic error correction.

pete-otaqui commented Jul 4, 2012

I guess this is lost amongst the noise, but I think it's best to listen to Brendan Eich discussing this thread and Automatic Semicolon Insertion (ASI):

ASI is (formally speaking) a syntactic error correction procedure

The point is that semi colons are actually required, it's just that your error in excluding them can be automatically corrected (in most cases). So it seems clear to me that it's better to write correct code, in the format as it will be when actually run, rather than rely on automatic error correction.

@matthew-dean

This comment has been minimized.

Show comment
Hide comment
@matthew-dean

matthew-dean Jul 4, 2012

It's important to remember that this struggle may lead to the end of all life as we know it.

CHOOSE NOW WHERE YOU STAND.

http://figment.com/books/308826-Dangerous-Punctuation

matthew-dean commented Jul 4, 2012

It's important to remember that this struggle may lead to the end of all life as we know it.

CHOOSE NOW WHERE YOU STAND.

http://figment.com/books/308826-Dangerous-Punctuation

@twickstrom

This comment has been minimized.

Show comment
Hide comment
@twickstrom

twickstrom Jul 5, 2012

@pete-otaqui SO TRUE!

I don't understand why anyone would WANT to depend on "error correction" to "fix" their code for them.

twickstrom commented Jul 5, 2012

@pete-otaqui SO TRUE!

I don't understand why anyone would WANT to depend on "error correction" to "fix" their code for them.

@tunnuz

This comment has been minimized.

Show comment
Hide comment
@tunnuz

tunnuz Jul 6, 2012

Ok, how do I unsubscribe from this?

tunnuz commented Jul 6, 2012

Ok, how do I unsubscribe from this?

@aaronhall

This comment has been minimized.

Show comment
Hide comment
@aaronhall

aaronhall Jul 6, 2012

Just reply with "unsubscribe" in all caps

aaronhall commented Jul 6, 2012

Just reply with "unsubscribe" in all caps

@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Jul 6, 2012

@tunnuz Look at the bottom of this page, below the "Comment on this issue" button

frewsxcv commented Jul 6, 2012

@tunnuz Look at the bottom of this page, below the "Comment on this issue" button

@s4parke

This comment has been minimized.

Show comment
Hide comment

s4parke commented Jul 17, 2012

@NARKOZ

This comment has been minimized.

Show comment
Hide comment
@NARKOZ

NARKOZ commented Jul 30, 2012

@wamatt

This comment has been minimized.

Show comment
Hide comment
@wamatt

wamatt Sep 9, 2012

@NARKOZ epic win on an already hilarious thread :D

wamatt commented Sep 9, 2012

@NARKOZ epic win on an already hilarious thread :D

@tomasdev

This comment has been minimized.

Show comment
Hide comment
@tomasdev

tomasdev Nov 6, 2012

I think this is all about @fat trying to be hipster. You know... step over all style guides currently available at the moment. YAY!

Personally, I like, and I think the only correct answer is the first @douglascrockford comment. There's nothing else to add.

tomasdev commented Nov 6, 2012

I think this is all about @fat trying to be hipster. You know... step over all style guides currently available at the moment. YAY!

Personally, I like, and I think the only correct answer is the first @douglascrockford comment. There's nothing else to add.

@flavius

This comment has been minimized.

Show comment
Hide comment
@flavius

flavius Nov 24, 2012

For the record, this was worth a talk: http://vimeo.com/53218578

flavius commented Nov 24, 2012

For the record, this was worth a talk: http://vimeo.com/53218578

@marcooliveira

This comment has been minimized.

Show comment
Hide comment
@marcooliveira

marcooliveira Dec 6, 2012

Just want to be part of web history. Haha... Hilarious.

marcooliveira commented Dec 6, 2012

Just want to be part of web history. Haha... Hilarious.

@blpiltin

This comment has been minimized.

Show comment
Hide comment
@blpiltin

blpiltin Dec 12, 2012

"For verily I say unto you, Till heaven and earth pass, one jot or one tittle shall in no wise pass from the law, till all be fulfilled." -Matthew 5:18

blpiltin commented Dec 12, 2012

"For verily I say unto you, Till heaven and earth pass, one jot or one tittle shall in no wise pass from the law, till all be fulfilled." -Matthew 5:18

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Dec 12, 2012

You should always use semicolons with curly-brace languages.

ghost commented Dec 12, 2012

You should always use semicolons with curly-brace languages.

@wprl

This comment has been minimized.

Show comment
Hide comment
@wprl

wprl Feb 13, 2013

        You don't have to put periods at the end.
                                At the end of sentences.
 But it can make them easier to read.

 On the other hand 
    there's no real reason not to
        just do whichever you want

wprl commented Feb 13, 2013

        You don't have to put periods at the end.
                                At the end of sentences.
 But it can make them easier to read.

 On the other hand 
    there's no real reason not to
        just do whichever you want
@enrmarc

This comment has been minimized.

Show comment
Hide comment
@enrmarc

enrmarc May 14, 2013

Well, I just want to be part of this;

enrmarc commented May 14, 2013

Well, I just want to be part of this;

@backspaces

This comment has been minimized.

Show comment
Hide comment
@backspaces

backspaces May 14, 2013

Yes, it certainly has become legendary;

On Tue, May 14, 2013 at 4:08 AM, Enrique notifications@github.com wrote:

Well, I just want to be part of this;


Reply to this email directly or view it on GitHubhttps://github.com/twitter/bootstrap/issues/3057#issuecomment-17867291
.

backspaces commented May 14, 2013

Yes, it certainly has become legendary;

On Tue, May 14, 2013 at 4:08 AM, Enrique notifications@github.com wrote:

Well, I just want to be part of this;


Reply to this email directly or view it on GitHubhttps://github.com/twitter/bootstrap/issues/3057#issuecomment-17867291
.

@greg0ire

This comment has been minimized.

Show comment
Hide comment

greg0ire commented May 25, 2013

@vpatryshev

This comment has been minimized.

Show comment
Hide comment
@vpatryshev

vpatryshev Jun 26, 2013

"The only true law is that which leads to freedom" (R.Bach)

Any style question starting with "why don't you..." has an easy answer: "because this is my style".

If you like semis, you use them; if you don't, you don't use them. What can be easier?

vpatryshev commented Jun 26, 2013

"The only true law is that which leads to freedom" (R.Bach)

Any style question starting with "why don't you..." has an easy answer: "because this is my style".

If you like semis, you use them; if you don't, you don't use them. What can be easier?

@chrisharrison

This comment has been minimized.

Show comment
Hide comment
@chrisharrison

chrisharrison Jun 27, 2013

Vlad,

That would be perfectly true if this was just a style issue. And I'd be
100% behind you if that was the case. Unfortunately this is about much more
than styling. JavaScript needs the semicolons to function logically.
On 27 Jun 2013 06:02, "Vlad Patryshev" notifications@github.com wrote:

"The only true law is that which leads to freedom" (R.Bach)

Any style question starting with "why don't you..." has an easy answer:
"because this is my style".

If you like semis, you use them; if you don't, you don't use them. What
can be easier?


Reply to this email directly or view it on GitHubhttps://github.com/twitter/bootstrap/issues/3057#issuecomment-20083328
.

chrisharrison commented Jun 27, 2013

Vlad,

That would be perfectly true if this was just a style issue. And I'd be
100% behind you if that was the case. Unfortunately this is about much more
than styling. JavaScript needs the semicolons to function logically.
On 27 Jun 2013 06:02, "Vlad Patryshev" notifications@github.com wrote:

"The only true law is that which leads to freedom" (R.Bach)

Any style question starting with "why don't you..." has an easy answer:
"because this is my style".

If you like semis, you use them; if you don't, you don't use them. What
can be easier?


Reply to this email directly or view it on GitHubhttps://github.com/twitter/bootstrap/issues/3057#issuecomment-20083328
.

@activars

This comment has been minimized.

Show comment
Hide comment
@activars

activars Jun 29, 2013

There might be something else we want to focus on, leave the semicolons alone.

semicolons

activars commented Jun 29, 2013

There might be something else we want to focus on, leave the semicolons alone.

semicolons

@MathRobin

This comment has been minimized.

Show comment
Hide comment
@MathRobin

MathRobin Jul 23, 2013

Please use semicolons. Readbility is important. Maybe, you, @fat, know how and when using semicolon but it's not the case for all. Rookies, kiddies and even experts could need semicolon to read the code. So, please, add it for readability...

MathRobin commented Jul 23, 2013

Please use semicolons. Readbility is important. Maybe, you, @fat, know how and when using semicolon but it's not the case for all. Rookies, kiddies and even experts could need semicolon to read the code. So, please, add it for readability...

@torifat

This comment has been minimized.

Show comment
Hide comment
@torifat

torifat Feb 24, 2014

Why don't we just get rid of indentations too??? It's really OPTIONAL. And, also MINIMALISTIC.

All the current IDE's are doing it wrong. Either they should give diff background colors to the different scopes or show them AII (AUTO INDENT INSERTED).

torifat commented Feb 24, 2014

Why don't we just get rid of indentations too??? It's really OPTIONAL. And, also MINIMALISTIC.

All the current IDE's are doing it wrong. Either they should give diff background colors to the different scopes or show them AII (AUTO INDENT INSERTED).

@twbs twbs locked and limited conversation to collaborators Jun 9, 2014

mdix referenced this issue in fbrandel/ParisHilton.js Aug 14, 2014

Merge pull request #15 from kevinvincent/master
Minified further - Removed totally unnecessary semicolon

automatic-frog added a commit to osp/osp.tools.visualculture that referenced this issue Jan 1, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.