Skip to content
This repository

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

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

162 participants

Serguei Shimansky

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

Jacob
Owner
fat commented April 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.

Jacob fat closed this April 14, 2012
Douglas Crockford

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

Douglas Crockford

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.

Jacob
Owner
fat commented April 14, 2012

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

Kit Cambridge

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

Zzzzing!

Erik Michaels-Ober sferik referenced this issue from a commit April 14, 2012
Erik Michaels-Ober Add semicolon
Closes #3057.
de31365
Erik Michaels-Ober sferik referenced this issue April 14, 2012
Closed

Add semicolon #3069

backspaces

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

Adrian Sinclair

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 ... ||.

AJ ONeal

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)

Zac Stewart

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 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?

david karapetyan

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

Zac Stewart

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.

Mark Otto
Owner
mdo commented April 14, 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
jack9 commented April 14, 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.

Subbu Allamaraju
s3u commented April 14, 2012

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

Devin Rhode

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

@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 ; + !.

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 :)

Corey Farwell

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

Serguei Shimansky

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.

Kiran Jonnalagadda
jace commented April 14, 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.

Devin Rhode

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.

Tim Branyen

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?

Julian Yap

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.

Chuck Bergeron

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.

Jack Lawson

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.

Michael Ficarra

@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.

Eric Anderson
aroc commented April 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.

Joris Verschoor
jrz commented April 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.

Courtland Allen

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

Jonas Haag

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

Serguei Shimansky

/* 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

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.

István Miklós Antal

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.

Florian Bösch

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.

shawnpresser

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.

Kiran Jonnalagadda
jace commented April 15, 2012

@shawnpresser This means deploying your version of JSMin on all my systems, plus ensuring your version is in sync with upstream JSMin.

Why can't we instead just replace all \n! with \n;! in Bootstrap? It's easier and doesn't affect production environments.

Jarin Udom

Writing JavaScript without semicolons is like doing all of your HTML in quirks mode, with improper nesting, unclosed <li> tags, and unquoted attribute values.

Just as HTML was designed so that a webpage would still probably look ok even with a sloppy idiot writing markup in HotDog, JavaScript was designed so that people writing code in Notepad would still probably get something workable if they forgot a semicolon here and there.

Doesn't make it the "right" way to do it.

Florian Bösch

@shawnpresser that's wonderful, can you please implement it as well for the YUI compressor, googles closure compiler, dean edwards packer and microsoft ajax minifier?

Damien McMahon

Having experience using Bootstrap 1.4 on a large JS application, I can tell you that Bootstrap (1.4 at least) falls apart when uglified.

Manoj

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ~Martin Fowler

Julian Raschke
jlnr commented April 15, 2012

Couldn't @douglascrockford's JSMin just output an explanatory fatal error in this case, for the reason outlined in the third reply here?
All programs that pass JSMin would still be syntactically intact. And JavaScript non-wizards (like me) would not sit there with broken code produced from two parts which we thought we could rely on.

(And a big thanks to unknown for deleting all the meme/boobs.gif crap replies!)

shawnpresser

@pyalot I could try.

Michael Champanis

#401

"fat: The reason it was closed is because semicolons were added to the end of lines in 1.4. In 2.0 we removed them again when we introduced the downloader as it safely concats and minifies these files for you. I'm adding semicolons to the end of files in 2.0.1 - which will likely be released tomorrow, to support this mobile oddity."

cvn
cvn commented April 15, 2012

“Be liberal in what you accept, and conservative in what you send.”

lcdt
lcdt commented April 15, 2012

@shawnpresser Your fork does not minify this example correctly:
if (confirm('Are you sure?') &&
!false)
{
alert('ok');
}

shawnpresser

@lcdt fixed; thanks.

Thomas Fuchs

tl;dr Someone finds bug in JSMin, people that use Bootstrap (for free) make demands and lecture the authors about the one true way to write JavaScript.

Luis Lobo Borobia

+1 to @istvan-antal @ajacksified @pyalot
Egos does not do any good to community. When you are a library developer, sometimes you have to go with the not so nice implementation to support as many users as possible. If you just don't want this, then, don't share your code, remove it from GitHub, and continue close-sourced. The main goal of open sourcing, sharing, GitHubbing... is being open to real facts. Javascript uses semicolons, everywhere. Its like the issue on leaving a comma at the end of an array definition in javascript. Its valid, but... IE breaks. So, just delete them.
(I can't imagine this people getting married )

Florian Bösch

@madrobby TL;DR two tools are incompatible to each other with each author claiming what they do is the one true way. However one tool (JSmin) is deployed across the entire JS ecosystem at countless locations site authors have no influence whatsoever, and the other is ignoring sage advice from one of our elders, you decide!

P.S. we now also have a gazillion forks of JSmin and bootstrap, both of which are virtually useless for different reasons. If you fork JSmin you'd have to convince everybody in the foodchain to use the forked JSmin or you're still gettting screwed at places you have no choice about, and the bootstrap forks would have to keep up with the primary upstream (bootstrap) or they're quickly getting to a derelict unmaintained state.

William B

What is with this new group of JS developers that refuse to use a semi colon? You're idiots. Use the semi colon like you're supposed to do.

Ben Alman

The solution to a problem like this is very simple. Project maintainers need to consider who the target audience for their project is, and maintain their project in such a way as to properly set and meet the expectations of that target audience.

I would imagine that the target audience for Twitter Bootstrap generally:

  • doesn't know the rules of JavaScript ASI
  • doesn't know how to choose the right tools
  • doesn't understand how to debug errors in the tools they use
  • needs all the help they can get

Which means that it might be a good idea to consider:

  • adopting a coding style that does as much as possible to help keep them out of harm's way
  • documenting things the project does that might not conform to their expectations
  • making explicit recommendations on tools and processes

Ever since I started actually teaching JavaScript, I've learned a lot about how to help reluctant JavaScripters (read: the 99%) read and write code. Omitting all semicolons except where absolutely necessary for proper ASI definitely doesn't help them.

Also, when responding to a user issue like this one, consider the first list. The user doesn't know what tool they should be using. The user doesn't know what's really going on. They've most likely inherited some arcane stack of tools that they can't discard, and need all the help they can get.

(and passing the buck isn't really "help")

Thomas Fuchs

Looking for a technical solution ("just use semicolons everywhere") is not going to help with a social problem (reluctance to properly learn JavaScript).

Ben Alman

Also, regarding the setting of expectations, one of the most prominent headers on the Twitter Bootstrap homepage is Designed for everyone, everywhere.

Just in case there was any confusion as to whom this project was designed for.

Serguei Shimansky

documenting things the project does that might not conform to their expectations

Like mentioning in the INSTALL or README that th script MAY NOT be compatible with this or that minifier.

Would sound like a compromise solution to all three parties -- the Bootstarp,the JSmin and some developper.

But it isn't. Have to keep my own readme.txt for every library with notes upon their potential bad behavior then implementing into production.

joelcoffey

@madrobby that's pure arrogance. What about people in the process of "properly learning" Javascript?

Florian Bösch

@madrobby funny you should say that because I always considered "properly learning javascript" to involve reading the spec, subsequently being horrified about the ambiguity in statement interpretation and henceforth using semicolons. Obviously there's a different level of comprehension, the one which doesn't read the entire ecmascript262 and stops at the paragraph about 1/4th down in the document that states semicolons are optional, but doesn't actually make it down to the grammar.

Mike Sherov

@madrobby Are you seriously implying that users of either JSMin or bootstrap shouldn't be making recommendations to the authors of said libraries? Come on now... that's how open source works.

Crockford, while abrasive and aggressive, has pointed out that bootstrap has a high likelihood of breaking in the future with in standard JavaScript if they continue to use a specific "style". The point being that relying on ASI (a set of rules that change, at least according to TC39) is not as reliable and future-proof as just using semicolons. Presenting it as an argument about the "one true way" is spurious. Here we have someone who, for better or worse, is helping shape the future of JavaScript telling someone their code will break, and that advice being ignored. For what reason? So the code looks pretty? This isn't about the "one true way"... this is about saying that using semicolons is a best practice, because it'll mean your code has a better chance of staying semantically correct in the future.

Ricky Elrod

+1 semicolons.

joelcoffey

Apart from the semicolon issue, what's wrong with signifying your intent in your code rather than abusing the logical operators:

if(!isActive) {
    $parent.toggleClass('open');
}
Mike Sherov

It's a tough issue either way. If Crockford changes JSMin to accept this input, JSMin is helping devs write code that'll possibly break in standard JS in the future. If he doesn't, he'll be not accepting input that works in all flavors of JS right now.

Scott Rubin

Reason to use semicolons - code will work properly and people will be able to get work done.

Reason not to use semicolons - aesthetics and ego.

Are you adults or children?

Tibor Szász

Entertaining thread :) You clearly have first world problems. Come on, it is just some extra characters which is also best practice. Not fixing a problem that you otherwise could in 2 seconds is not very smart move for whatever reason.

Alex Marandon

For the folks out there using Django compressor, see this issue: django-compressor/django-compressor#237

Tom Green

+1 semicolons

dubcanada

You guys are all really angry lol...

It's simple, you want a semicolon there. Fork the repo and add it yourself and shut your mouth. Problem solved.

It's fat's choice, and let it be. Don't try and shove your ahole lectures on why semicolons are used in herpy derps javascript library therefore must be used in everyones.

There are plenty of forks that solve this problem, or you could just open notepad and add one at this spot.

Nobody has any right of demanding someone who does something for his free time to change anything (assuming Twitter doesn't sponsor this, which I don't think they do?). If you have a problem with it, that's why they invented open source... so you can download it and add myfacesmells_ to the beginning of every variable.

mvrak
mvrak commented April 15, 2012

Semicolon insertion is a backup... a bonus.... relying on it is insanely stupid.

Piotr Okoński

@dubcanada, Twitter does not sponsor it, as per Mark and Jacob's words in some other thread.

Tibor Szász

If you have pigeon shit on your shoulder and I dare to mention it to you then you can say that "Hmm, I see it but it looks good there, I also know that pigeon, his name is Dave, now move on." or you can just say "Thanks dude, I didn't notice it".

Btw you are right there should be a different branch called "Twitter bootstrap (with semicolons)"

Mike Sherov

Here, I'll fix this thread:

s/insanely stupid/potentially incompatible and therefore not advised/g
s/dumb down JSMin/allow JSMin to accept input that goes against TC39 because it might break future compat/g
s/learn to use semicolons properly/please start using semicolons, as that will help ensure future compatability./g

Woody Gilk

Add the stupid semicolon already. The longer the delay, the more painful it will become.

Piotr Okoński

Or just use UglifyJS? I don't recall it having problems with that issue.

dubcanada

It's not painful to fat. He doesn't give a crap... it's painful to the morons in this thread trying to force him to add it, rather then just adding it themselves when they download.

Also saying that some possible change in the future might break this is stupid. That's like saying you shouldn't use X function in php because it may be deprecated in 2020. Or you shouldn't use any HTML5 attribute because the spec is not done and it might change.

Darren Bounds

Regardless of whether semicolons are best practice or not, the fact jsmin is breaking existing, functional non-minified code is a flaw.

dubcanada

It also works with http://slimit.org/ I believe and http://slimit.org/ is actually smaller then jsmin.

Both are positives!

Or you could just not minify your javascript, in this day and age with the amount of bandwidth we all have. It really would not be a big deal.

Mike Sherov

@dubcanada , why so angry? I personally don't care if bootstrap adds the semicolon. I can easily add the semicolon myself. What I care about is other people having their stuff break because neither crockford nor fat are willing to budge here.

The advice I gave about future compat might be a case of YAGNI, or it might not be. Only time will tell. But look at the possible outcomes:

Crockford adds support: 1. Accept input that may break in the future. 2. Accept more input that works right now. 3. Crockford acknowledges that while it's harder and potentially riskier to not use semicolons, it's still perfectly valid right now, and his tool should just be minifying, not enforcing a standard (that's what JSLint is for).

Fat adds semicolon: 1. Have your code be potentially more future-proof. 2. Make your code work with JSMin. 3. Bow to the practice that adding semicolons increases compatability with existing tools and is easier than not using semicolons.

Neither budges: 1. Other forks must be constantly maintained to add semicolons to make it work with JSMin, or otherwise abandon JSMin as a reliable minifier.

I personally think @fat should just add the semicolon given the options above. If you disagree, fine, but it doesn't make either of our arguments stupid.

Ross Allan

@dbounds I think you might want to try http://slimit.org/. I think it would successfully minify this, although I haven't tested myself.

Marco Chomut

"Or you could just not minify your javascript, in this day and age with the amount of bandwidth we all have. It really would not be a big deal." @dubcanada

Someone's clearly never heard of a mobile data plan, or lived in a country that doesn't happen to have one of the fastest pipes in the world.

Ross Allan

@Pewpewarrows

Even on fast connections, minifying is important. Of course, other things should also be done for maximum increase in speed - minify, concatenate, gzip.

Marco Chomut

@nallar Of course, I was just pointing out the obvious.

Nick Kwiatek

Whether or not one agrees with ASI, it is in the current spec. Therefore, that JSMin does not support this line of code would make it non-compliant. Imagine if you used the same argument to try and get out of paying taxes? "That rule is stupid and I don't follow it"?

Douglas Crockford, bless his soul, is known for not being overtly diplomatic. I don't think he should change JSMin because in my view that would be compromising "Crockford". However, that does make his product less universal -- and that's good. People should be using JSMin because Crockford wrote it, not because it's expected to work everywhere. The idea is that if JSMin doesn't work on a given codebase, it's probably because Crockford wouldn't approve of that codebase -- and if that's important to you, then you know what to do: avoid Bootstrap!

Then again, I have to wonder if this battle of integrity is worth losing potential Bootstrap users. Besides, it wouldn't be too hard to prefix punctuation on the beginning of newlines with ; -- a technique often employed by proponents of ASI. Changing the code to ;!isActive would satisfy concerns while having neither person sacrifice on their ideals.

EDIT: or just do what @jed below me says, which is smarter. I think the world would run a little smoother if we all felt, ASI and semicolon users alike, that punctuation on the beginning of a new line that doesn't have a semicolon in front of it is a code smell in javascript.

Jed Schmidt
jed commented April 15, 2012

i'm 100% with @fat on the semicolons, but don't understand the benefit of writing the very fragile

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

when

isActive || $parent.toggleClass('open')

is shorter and

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

is clearer, and neither break as easily.

ryangrahamnc

@fat shouldn't be adding a semicolon because it makes the codebase too big.
People keep complaining "Boo hoo hoo, twitter is so bulky and laggy!", and then they contradict themselves by requesting the codebase get larger with needless semicolons. smh, people these days....

Oscar Godson

@fat You opened this as open source. When you do that you should be respectful of the people who will be using your code. That means adding semi-colons so we can all pick whatever minifier we want. But hey, i guess being a dick about the code you released as open source works too.

Florian Bösch

@jed

Object f has no method 'forEach'

var foo = 'asdf'
[1,2,3].forEach(function(value){console.log(value)})

undefined is not a function

var foo = function(){}

(function(){
})()

number is not a function

var foo = 1+2
('asdf' + 'blubb').toUpperCase()

will compress wrong

var foo = /asdf/
console.log('here');
var foo = function(){}
var bar = function(){}
Matthew Dean

Yes, @fat, if you give me a free sandwich, I DEMAND THAT YOU GIVE ME THE PROPER SERVING OF MAYONNAISE, as dictated in Proper Sandwich Specification JB-332. To withhold the proper serving of mayonnaise, as dictated by the sandwich community, clearly means that you are a dick, whereas I am a simple and humble masticator who's just trying to consume the sandwich that you handed me for free without any loss of mayonnaise taste that I desire. I shall toss your free sandwich aside until you give me the sandwich that I clearly deserve. After all, Douglas Crockford gave me a free sandwich, and it had exactly the right amount of mayonnaise and it creamed my mouth just right. The problem is obviously you, so hurry up and FIX MY FREE SANDWICH, and don't you dare ever try to hand me free food again without meeting these minimum sandwich specifications.

Mike Sherov

@jed +1. Also, @nkwiatek, you're right. I think you've just reversed my opinion. Also, David Herman, another TC39 member, has indicated that TC39 will not be breaking existing code.

In this case, @douglascrockford should support this correct code, even if it's against his preference, or he shouldn't call it a JS Minifier, he should call it a "Douglas Crockford Flavored JavaScript minifier".

But also, @fat should change the code in the way @jed suggested. A bit of compromise on both sides so we can move on already.

Jed Schmidt
jed commented April 15, 2012

@pyalot none of which appear in the offending snippet. let's stay on topic.

Kit Cambridge

"...making a snippy response like that just makes you look like an immature hipster smarting off to a battle worn professional."
"You're idiots. Use the semi colon like you're supposed to do."
"Are you adults or children?"
"But hey, i guess being a dick about the code you released as open source works too."

Really?

What's immature are the needless personal attacks against @fat over a coding style.

Oscar Godson

@kitcambridge No, he released it as open source. Being disrespectful to the developers using it and then other developer's tools because it doesn't work with your code is wrong. It's not even about if he likes semi-colons or not or his coding style. It's open source. Be nice to the people who are using your code for god's sake.

Ross Allan

@nkwiatek

As far as I can see, JSMin doesn't claim to follow the spec - it claims to work on what jslint says is ok. I think http://slimit.org/ works on the spec, although I haven't tried it. I believe the reason JSMin doesn't is to make it smaller(and faster!).

@ryangrahamnc

Can't tell if serious. If you are... a minifier gets rid of a newline character instead... and much more. Otherwise, carry on! :)

Oscar Godson

@matthewdl Telling developers who are legitimately trying to use your code that they just dont know how to use semi-colons and that everyone else needs to work around their coding style is wrong in the open source world. It's about working together not trying to boost your ego.

Oscar Godson

@matthewdl If you want to talk about "sandwiches" and how it relates, it'd be like giving away a free one (great!) and when they ask for a napkin you respond with "well, I know how not to spill it on myself, maybe you should learn to not make a mess on yourself too."

Ross Allan

@nallar

Just a minor correction on my previous comment - apparently https://github.com/mishoo/UglifyJS is good.

adam j. sontag

In his talk at at JSConf, @fat basically stated that he sometimes uses semicolons, and sometimes doesn't, and that he omits semicolons from Bootstrap in a deliberately enigmatic attempt to troll the community...

Mission accomplished!

backspaces

I have to admit to being one lazy bastard, and also like languages that have gone past C syntax just a little bit. Really, ;'s should just be for separating two statements on one line. Design for the rule, not the exception.

It took me way to long to find out that coffee-script was popular partly because it tries to protect you from JS by removing ambiguities and avoiding The Bad/Ugly Parts.

Don't get me wrong, I am a huge fan of JSEverywhere: client, server, datacom (JSON). I think async is the safest, easiest understood multiprocessing technique. Fork/Join is just too hard for humans .. I watched Sun struggle through 3 years getting Solaris multi-threaded. Nightmare.

Damn. Now I gotta learn all the Ugly parts of coffee-script I suppose.

Rajesh Pillai

People coming from different programming background are trying to adapt or style JavaScript to the environment they are familiar with. There's nothing wrong in that. JavaScript already has some bad things, but it also has many good things as well.

Let the language be as it is and adapt it to what is best suited without breaking things that are already present. Love the language for the good and respect the quirkiness as this language has evolved from a toy language to one of the most used and talked about language in the world.

Respect the members who have been trying to put sanity to the language and come up with guidelines and tools to make it work and understandable across various segments.

Style and beauty comes later. What matters is the language's consistency. So, if that means putting a semicolon, why can't that be? Again not for flaming this discussion.

It has taken ages to make people realize the good and bad parts of the JS language, so why not respect that and move ahead.

If opensource is about sharing, then its also about caring (caring for all the apps already running which has been developed years before some developers were born)..

Definitely one can fork and move ahead, but that's not the point of this discussion, I guess.

By the way.. I love bootstrap as being a non-designer it helps me quickly build beautiful websites :)

Jacob
Owner
fat commented April 15, 2012

fwiw, this was patched in bootstrap way before i even encountered this issue - otherwise i wouldn't have closed it outright.

Sorry for the confusion everyone.

You can see the code here in 2.0.3: https://github.com/twitter/bootstrap/blob/2.0.3-wip/js/bootstrap-dropdown.js#L63

I still maintain this is a bug in jsmin, but as others have pointed out - mark and I do our best to make bootstrap flexible with other great tools out there (like jsmin). This includes adding semicolons where necessary or changing minor stylistic things.

@englishextra 2.0.3 should work fine for you - and will be released while mark and i are in london (april 21-25). cheers!

Isaac Z. Schlueter

@douglascrockford If TC-39 makes ! an infix operator, which causes \n to not terminate the statement, then that will be a syntax change that is incompatible with current code in the wild, which would be an insanely stupid move on their part.

The fact of the matter is that JSMin isn't parsing JavaScript correctly. I thought the separation of concerns was that JSLint tells you about stupid code, and JSMin correctly parses JavaScript according to the ES standard and minifies it safely.

dukeofgaming

Wow, @fat is such a brogrammer

TJ Holowaychuk

meow

Steven Roussey

The fact of the matter is that JSMin isn't parsing JavaScript correctly. I thought the separation of concerns was that JSLint tells you about stupid code, and JSMin correctly parses JavaScript according to the ES standard and minifies it safely.

Whatever gave you the idea that either of those tools actually parse JavaScript? UglisfyJS does for minifying. Esprima does in general, as do others. @douglascrockford created wonderful tools back before many others even thought to, but JSMin has been superseded by many alternatives, that I'm frankly surprised that it is used anymore.

John Papa

@fat - Kudos for making the change. Agree or disagree with semi colons ( FWIW I agree) , it's nothing but positive when JavaScript code libraries work together. There are too many out there that don't integrate. I love bootstrap and an thrilled to see this change. Thanks.

Serguei Shimansky

In his talk at at JSConf, @fat basically stated that he sometimes uses semicolons, and sometimes doesn't, and that he omits semicolons from Bootstrap in a deliberately enigmatic attempt to troll the community...

I suspectedthat from the start -- that's what it was.

@englishextra 2.0.3 should work fine for you - and will be released while mark and i are in london (april 21-25). cheers!

HAHAHA

Thanks, gents

Isaac Z. Schlueter

@sroussey parse !== "build a complete and accurate syntax tree"

JSMin walks through the JavaScript code maintaining state and taking actions based on that state. It is removing a \n character where doing so causes a change in program behavior.

Stupid code or not, this is a broken minifier, because it's not adhering to the contract it claims to.

Caio Gondim

Thank for not using semicolons =)

Semicolons -1

Steven Roussey

@isaacs I love your choice of !== rather than !=

:)

I'd say (which is not at odds with your assertion):

parse == "build a complete and accurate syntax tree"

After all, ! has side effects and a more complex AST on the client. Play with http://esprima.org/demo/parse.html and see.

Anyhow, back to taxes...

Thomas Fuchs

See also this related issue madrobby/semicolon.js#2

Thierry Koblentz

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.

When I joined Yahoo! I had the habit of not including semi-colons after the last declarations in declaration blocks. I know that's CSS, but it does relates to this thread...

Not adding ";" was against company best practices, but I thought there was no reason to add them since they are not required. It turned out that Safari 2 had a bug that made it drop a whole styles sheet after a missing semi-colon.

At the time, I didn't spend energy trying to defend myself; I added the semi-colon and moved on. Imo, the point is not about finding out who's right or wrong, it's about doing the right thing. It's about the outcome.

matzero

"Don't be a JavaScript hipster. Add semi-colons." I love this one!

Seriously, use the f@#king semicolons.

Jason Palmer

For fucks sake people - if using ugly semicolons and a few extra parenthesis will guarantee current AND future compatibility then what is the problem? I don't find code written in this fashion difficult to read.

Alex Sexton

I heard semicolons killed @fat 's family and now he's using the left-over wealth from his father's fortune to fight against them. Seems legit.

Mike Sherov

Wow, so both @fat and @douglascrockford made changes to support interop. Bravo.

stereobooster

Take a look http://mislav.uniqpath.com/2010/05/semicolons/ by @mislav
I'm personally prefer semicolons

Andrew Hubbs

Everyone wins! Both libraries get a little better. Thanks @fat and @douglascrockford for working to make the internet more awesome.

Piotr Okoński

@leeoniya hm that's weird. I'm using uglifyjs in Rails asset pipeline and never had issues.

Terry Rosen

Semicolons cause an equal amount of debate in English grammar circles and although it's yet to be proven I believe they partially caused the first World War.

Clearly the solution to all the world's problems is to remove semicolons from the global character set.

backspaces

@stereobooster .. you have made me feel clean! I use ;'s as separaters and {}'s only for multi-line blocks, not single line blocks. I've come out of the closet!

TJ Holowaychuk

@maxogden wow, that's a great shed haha

Why on earth is this discussion even happening?

JSMin is a specific program that performs a task. It has a contract with the user. It gets an input (your js) and produces an output (minified js), following some rules. Nobody (AFAIK) said this is going to work perfectly with any possible valid JS code.

@isaacs said:
(..) Stupid code or not, this is a broken minifier, because it's not adhering to the contract it claims to.

Let's see... Is it really broken? What contract does it claim to adhere to?
Please read: http://www.crockford.com/javascript/jsmin.html (And/or any other documentation I might not be aware of).

Pay attention to the "Caution" section. It's not explicit, but give you the heads up: not any random code will work... you have to watch out for some special situations. Valid JS code might fail when being processed through JSMin.

This situation is kinda the same. It doesn't matter whether ommiting that semicolon is a stupid decision. That's irrelevant in this discussion, imo.

What I think DOES matter, is:
Perhaps JSMin should have better documentation about specific valid JS code that might break while minifying (maybe that piece of documentation exists, and I don't know it).

Tony Ford

Github threads are becoming so epic we need like buttons now.

+1 on the bike shed @maxogden

Piotr Okoński

@tony4d first of all we need "unsubscribe" option :D

Piotr Okoński

@kitcambridge but they still appear in the top right corner forever. Or maybe Github fixed that, will see once someone posts a reply ;)

toastyghost

wtb namespace keyword and a bunch of inane reasons why this is somehow torvalds' fault

Matthias Kühnle

@SlexAxton: "I heard semicolons killed @fat 's family".

My deepest condolences. I can totally understand his fight against semicolons than!

-1 semicolons

Aaron Hall

@fat could take the high ground, add the semicolon until JSMin is fixed and have his pissing contest off in the corner while the rest of us get shit done. But being practical doesn't pump your ego quite like religious posturing does. Trolls gon' troll.

Aaron Hall

@fat thanks, missed this in the sea of comments.

Ravi Sarma
ravi commented April 15, 2012

@fat props to you on the maturity in the face of stuff like "insanely stupid code" and the flames that seems to have cued. Thank you for work.

John Tantalo

From JavaScript::Minifier,

The primary requirement developing this module is to not break working code

backspaces

@fat +1
Semicolons -1

If the damn language allows it, so be it. Best practices == Cleanest Code.

Jason Palmer

@backspaces sorry... Best practices === Cleanest Code

Tom Robinson

LOUD NOISES!

zero-
zero- commented April 15, 2012

After reading this I feel like I don't want to use semicolons. If you can't read code without semicolons, you shouldn't be coding in the first place... If minifier breaks the code because it doesn't agree with not using semicolons, f*ck that minifier, it's obviously broken, get a minifier that actually does what it's supposed to do.

Stokestack
István Miklós Antal

"Functional" code, valid syntax:

  #define true false
  #define false true

  #define true 0
  #define false !true

  #define if while
  #define continue break
undefined = true;

So you think we should write code like these just because it has a valid syntax?

Stokestack

No, I don't think anybody should be writing code with sloppy, ignorant, or obfuscated syntax. Hell, I reformat open-source code so braces line up and if statements are properly enclosed in braces and so forth.

But the fact remains: If the language compiler accepts it, then it should still compile after any preprocessing. It may suck stylistically, but take that up with the language author.

Julian Yap

Guys, more background from 'Fat' on why he doesn't use semicolons written back in October 31st 2011:
http://wordsbyf.at/2011/10/31/i-dont-write-javascript/

Quotes:
On the use of '&&' instead of an 'if' statement: "If you were really having fun with it you could lose the if all together... Each is perfectly valid. Each behaves the same. It’s just a matter of preference and finding the style that makes most sense to you."
JSLint is described as a "unnecessarily strict linter".
"The majority of lines however don’t end with semicolons because they simply aren’t necessary and I prefer the minimalist aesthetic. For me, \n character is enough and the semicolon character is redundant."

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

Gareth Bradley

LOL -- This has made me giggle :)

Use Dart if you dont like JS :P Google wont complain.......

Emin Kura
emin commented April 16, 2012

Javascript is neither pyhton nor ruby.. Learn to use semicolons, actually learn language you use properly. I can't understand why everybody is talking about semicolon everywhere. Before starting to code, learn language..

Matthias Kühnle

Mikeal wrote a very good post about - why no semicolons - and I agree 100%

http://www.mikealrogers.com/posts/two-things-about-semicolons.html

iwiznia

Wow, wasn't much more simple to just click the Merge button and add the fucking semicolon? So much wasted time....

Matthias Kühnle

@iwiznia Some people take the way of the least resistance ( click Merge button ) and some stand for there beliefs @fat.

I like people that stand for there beliefs.

(And fyi: @fat changed the code 2 days ago to a way that that doesn't fail in jsmin - the discussion is more general about ;+ oder ;- )

markjreed

@nivoc - Thanks, but while that Mikeal post starts out promisingly enough, it sort of trails off without really going anywhere.

It's really off-topic, but I do think it's perfectly reasonable not to use semicolons in JS where the implied statement termination is obvious; unfortunately, the ASI rules make it "obvious" in cases where there actually isn't one inserted. IM(ESH)O, the character after the newline shouldn't play any part in whether or not the newline is treated as a statement separator. But since it does, you get surprises like this one. So I'd rather see more "extra" semicolons in the interest of readability, just as I like to see "extra" parentheses in many cases where the precedence rules don't require them.

Regardless, I'm glad that both @fat and @douglascrockford have modified their respective codebases in the direction of greater interoperability.

fadzlan

Someone please correct me if I am wrong. Isn't writing codes that depends on the quirks of the language (because it is designed to be forgiving in some situation) is also akin to write codes that depends on the quirks of a browser (because well, it is also designed to be forgiving in a lot of cases)?

Since the forgiving part may change in the future, because its well.... not the intention of the language (its just tries to accomodate omission on the coders part), it seems that to me we can also say the same thing for browsers. Different versions of browsers tend to have different quirks of dealing on being forgiving.

What do anyone think of the parallels here? Is it a correct one to draw or is it nowhere near being right?

Jacob Groß

Just a short question: Why JSMin? Why not UglifyJS?

Scott  Koon
skoon commented April 16, 2012

Is writing JavaScript without semi-colons Web 3.0?

teiman

You can learn java in one day, but you are not productive until you learn the library, and the java-isms. Perhaps Javascript is similar, with the exception that the Javascript-ism have changed over time, and there are different Javascript-isms depending on what Javascript culture. Theres more than one Javascript culture (maybe as much different ways to describe a object in Javascript).

The minifier is from a C like culture, where ";" is usefull to describe intend. And the Bootstraping.js library is from a Ruby culture where ";" on the start helps avoid bugs.

Perhaps I was wrong, and the author of bootstraping don't need to change his code. While the author of jsmin is free to either support this Ruby-ismised-Javascript or ignore it. Being all cool.

zero-
zero- commented April 16, 2012

Anybody else find all those "you need to learn the language - use semicolons" comments ironic?

The fact is that ecmascript doesn't require semicolons. If you don't approve it, I'm afraid nobody really cares.

Trevor Roll
Trevr commented April 16, 2012

The level of Asperger-fueled pedantry on display here makes me feel sick. Just shut up please, JavaScrHiptsters.

Dustin Dawes
gu3st commented April 16, 2012

This is why automatic semicolon insertion sucks

Yes.. it's a speech by Douglas Crockford, but he's right.

Trevor Roll
Trevr commented April 16, 2012

This is why automatic semicolon insertion sucks

JavaScrHiptsters should take note at 0:34:30 and seriously ask themselves the same question.

zero-
zero- commented April 16, 2012

@Trevr

So writing non-working code relates to semicolons how? If you follow Crockford's guidelines to the dot, soon you can't take a dump without semicolons to tell you when to stop pushing - the man is fanatic about his semicolons. Like I said before, if you can't write valid javascript without semicolons you are doing it wrong.

Matt Vickers
envex commented April 16, 2012

I'm impartial about how this ends up, but for the love of god @Trevr, please stop trying to get "JavaScrHiptsters" to catch on.

Trevor Roll
Trevr commented April 16, 2012

@zero- Actually I was just trolling. The Crockford video was quoted from the guy above. But could you be any more smug? Does it make you feel smart to tell people they're "doing it wrong"? Your epenis must be enormous.

@envex Yeah you're right. javaScrHiptsters use lower camel case.

Gregory Perry

Refusing to use optional syntax is a perfectly valid position to hold.

Insisting upon always using the optional syntax is also perfectly valid.

Unfortunately, picking one or the other (arbitrarily, I might add) and arguing incessantly on the internet about it is neither valid nor pragmatic.

Please, stop shitting all over my activity feed.

Trevor Roll
Trevr commented April 16, 2012

but is it

flogDeadHorse()

or

flogDeadHorse();

?!?

Erik Michaels-Ober

More like:

while(horse.isDead())
  console.flog(horse)
Alex Chaffee

Resolved! All languages should be s-expressions.

) > ;

;-)

@douglascrockford jsmin.c is insanely stupid code. Seriously... action(1), action(2), action(3)? Really?

Sorry, but nobody should dumb down their code to play at Doug's level.

https://github.com/douglascrockford/JSMin/blob/master/jsmin.c#L122

This guy deserves serious code shaming. Why do people even listen to him and his rants?

chee rabbits
chee commented April 16, 2012

;

Max Ogden

@sferik except console methods are expected to not have side effects. flogging will leave visible lacerations on skin, even tough horse skin

@jldailey you can't be serious.

Gregory Perry

@jldailey I'm guessing that you missed that cases in action() don't have breaks?

thpoul

@boxofrad your work here is done

Matthias Kühnle

@fadzlan nope. quirks-things where never any standard. it's old non-standard-wild-grown-browser-specific stuff.

Automatic Semicolon Insertion in contrast is not wild-grown at all. It's part of the official standard by intention and supported by every javascript-runtime in the same way. In the way that is specified in the spec.

And as mikeal points out:
"There is no error in your JavaScript that is being “corrected,” the AST generated from semicolon-less JavaScript is identical to its semicolon riddled counterpart. "
"ASI is a basic part of the language, it’s not an amendment."

http://www.mikealrogers.com/posts/two-things-about-semicolons.html

Stokestack
Jake Wharton

@Stokestack there's a notification toggle at the bottom of the page.

Walter Zheng

@JakeWharton you got it!!!

Stokestack
Jake Wharton

Look for this:

With your eyes.

Stokestack
Trevor Roll
Trevr commented April 16, 2012

P.S. javaScrHiptsters is now a thing.

@lotyrin I did miss that. It does make it slightly better; so it's not completely stupid. It is still insanely terrible code, just not stupid.

Art Pai

http://semicolonfree.tumblr.com/

A collection of resources to write semicolon-free JavaScripts.

Christopher Hunt
huntc commented April 16, 2012

This'll probably get lost in the noise, but the problem isn't confined to Jsmin. My webminifer plugin (which can use Closure or YUI for minification), also suffered the problem. The resolution was to ensure that a semicolon always appears between each file that is appended to each other (I append all files of my project and then minify).

My recommendation to the Bootstrap boys is to think about linting the code and avoid ambiguities. I love bootstrap, but the JS is not so intuitive.

Trevor Roll
Trevr commented April 16, 2012

@jldailey Berating someone much smarter than you might make you feel better but you're not impressing anyone nor are you changing the reality that you are a clueless, talentless hipster.

Trevor Roll
Trevr commented April 16, 2012

@jldailey You were just trying to score geek cred by talking down someone who is clearly much smarter than you. He was accurate and to-the-point.

It's kind of sad to see so many clueless hipsters like yourself masquerading as serious software developers and desperately trying to be taken seriously. Instead of acknowledging and improving upon what people like Crockford have built, you seem to prefer bikeshedding and picking apart trivial crap like this to make yourself feel relevant.

Trevor Roll
Trevr commented April 16, 2012

@kitcambridge You really need to sort that face out.

egeozcan

The question is, what do we lose if we ended this infinite argument and added a single character that would make thousands of developers happy? Bandwidth or pride?

Trevor Roll
Trevr commented April 17, 2012

Haven't you javaScrHiptsters got anything better to do? How about writing some revolutionary, world-changing software?

nfaiz
nfaiz commented April 17, 2012

;

Anthony Short

Or just use coffeescript instead of trying to make a fundamentally shit language look like the cool kid languages?

Writing code like this is like a fat, red-headed kid putting gel in his hair to impress the ladies.

Trevor Roll
Trevr commented April 17, 2012

Writing code like this is like a fat, red-headed kid putting gel in his hair to impress the ladies.

That is so racist.

Todd

If Javascript didn't require semicolons, then it wouldn't be called "Automatic Semicolon Insertion". Just because you don't need to put it in your code prior to that code being interpreted doesn't mean that semicolons aren't added for you before the script is actually run.

@Apreche "Are we adults or children?"

Are we painters or plumbers? If all one cares about is how many holes the shit will go down, that's just a plumber.

@egeozcan The original code was a bug, and was changed, that isn't the issue. The issue is whether a painter, working on his own art, on his own time, for his own enjoyment, has any reason to sacrifice anything (his aesthetic or ego or anything else) to please a bunch of plumbers.

scott romack

Can someone please create an unofficial branch of this library.
The authors have done an excellent job of creating it but this is not the first time they have been overly opinionated about trivial stuff.

egeozcan

@jldailey I wouldn't give credit to such a weird (sick, even) analogy but I need to say that if a painter is causing problems that would require bunch of plumbers to solve, that painter is doing something terribly wrong.

Scott Mathis

I'm glad this was changed in 2.0.3. When I used Bootstrap in Django, the dropdown.js broke in compressor as well. I saw what was going on, understood why they did it but added semi-colons anyway because it was a bad decision to hoist a personal vendetta against Javascript onto those who use Bootstrap.

I added the semi-colons myself. Not a great practice, forking the code like that. But whatever. I'm not afraid of semi-colons.

Should be known, though, that this broke the Django compressor plugin as well.

Daniel Upton

Wow, its amazing how somebody can put so much effort and work into something that makes the lives of developers easier..

Then the community hate him because he misses a semi colon.

I agree the semicolon should be there, but wont somebody please think of the children!

egeozcan

@jldailey this is one of the many points where your analogy fails as only a few painters would work with tools that have terrible glitches. Also, you cannot assume that a problem doesn't exist, when it's just not valid for yourself. Does "works on my machine badge" ring a bell? These problems should worry you especially when you consider that this is the project with the most followers on GitHub, taking huge contributions. Ignoring community would make sense in few cases ( http://www.codinghorror.com/blog/2012/02/listen-to-your-community-but-dont-let-them-tell-you-what-to-do.html ), especially when there is a clear conflict of interest for the main maintainers but I don't see that here. Fixing problems like this would also bring no maintainability burden, if they don't already reduce it.

egeozcan

@jldailey so makers of Prototype.js, underscore.js and bootstrap value code beauty over utility? Well, you seem to know these people very well; I can't comment on that. However, you calling a programming language (which also happens to be the number one on GitHub, even though it doesn't need to be) "excrement" tells a lot about your "painting skills" =)

Matt Kersley

ಠ_ಠ

teiman

I don't think the author has much options. I mean, look at the code. The lack of ";" is everywhere.
The author could add a ";" there, but down the line the code will break again, perhaps in other file, perhaps with a different minimizer making similar asumptions.

http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js

  Dropdown.prototype = {

    constructor: Dropdown

  , toggle: function ( e ) {
      var $this = $(this)
        , selector = $this.attr('data-target')
        , $parent
        , isActive

      if (!selector) {
        selector = $this.attr('href')
        selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
      }

      $parent = $(selector)
      $parent.length || ($parent = $this.parent())

      isActive = $parent.hasClass('open')

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

      return false
    }

  }
egeozcan

@jldailey my whole point was you didn't have any arguments except some snobby attitude towards a programming language. Against someone just going further and declaring a language unpleasant and calling who embrace it "plumbers", what am I supposed to argue? Start categorizing you or calling names? Whatever. I just had to state my opinion on a project that I hold some interest and this is going out of control. Have fun with painting, plumbing or whatever your thing is.

Isaac Z. Schlueter

Can someone at @twitter please block @trevr? This user is a child getting off on trying to incite ill will.

Erik Michaels-Ober

To those who believe nothing positive came from this debate, I offer this.

Gareth Bradley
Isaac Z. Schlueter

For maximum safety, use the semicolons module in npm. When you require('semicolons'), they are required.

https://github.com/isaacs/semicolons

egeozcan

@jldailey you better don't judge them, I just didn't like that you tried to categorize people. You just can't, the people in the JavaScript community are just too diverse. You called a tool, which a lot of people love to work with, an "excrement". How do you decide that "interoperating with jsmin.c is worth $0 and no cents to a painter"? I never defended anyone calling others names. Maybe they know each other and they are close enough to be able to say those things; who knows. However most of the people here are just trying to break a resistance which they see (or think) is unnecessary. They are not just "painters", "plumbers" or "hipsters". They are just making valid arguments to make a change in a project in which they have some interest or even contribution, perhaps. If you think that code beauty is more important in this project which has the slogan "designed for everyone, everywhere" and mainly used as a quick boilerplate for websites, I can only agree to disagree. It is not a war on semicolons. It's about making this project work "everywhere" as the slogan states.

Ravi Sarma
ravi commented April 17, 2012

For those responding to @jldailey, especially with the "Crockford is smarter than you" type stuff, please scroll all the way back and see where this tone ("insanely stupid code") was set.

Additionally, I don't see the problem with the painter vs plumber analogy. Plumber is clearly not being used in a derogatory sense, unless you think @jldailey means Van Gogh when he says "painter".

FWIW, I may be a minority of one here for I think the semicolon is a good idea because of aesthetic reasons!

Tugberk Ugurlu

Nobody has any right of demanding someone who does something for his free time to change anything (assuming Twitter doesn't sponsor this, which I don't think they do?).

@dubcanada you might want to check out under which organization account this repo is hosted. If you provide a software for people to use, then you should listen to them and adopt their needs. On the other hand, you are right about the forking part. Just fork the repo and use it as you see fit. But this is not gonna change the fact that omitting semicolons is a bad practice.

On the other hand, you might wanna watch this part of this video http://www.youtube.com/watch?feature=player_detailpage&v=hQVTIJBZook#t=1847s

@egeozcan Of course no individual is ever a perfect instance of a class. That doesnt mean you can't talk about classes of people and the things that make them more similar to each other than they are to others. It is naive to think otherwise, and it's a strawman to assert that I believe it (and possibly you were offended by a thought you only assumed I had).

semicolons4eva

The un-official fork of Bootstrap for all your semicolon needs: https://github.com/semicolons4eva/bootstrap

Submit pull requests at your convenience!

Jason Schertz

I came here to say this;

travis

Why would anyone want to take away Zoidberg's eyes?

(V) (;,,;) (V)

Ryan Tenney

+1 to @douglascrockford for "That is insanely stupid code."

Tugberk Ugurlu

+1 to @ryantenney for +1ing @douglascrockford's beautiful words.

teiman

Some PHP...

function g($tag,$code){  return "<$tag>".$code. "</$tag>"; } 

echo g(table,g(tr,g(td,"hello world").g(td,"!")));

this output:

<table><tr><td>Hello world</td><td>!</td></tr></table>

Actually, nobody on the PHP community write code like that. Because all PHP programmers know better...

Matthew Dean

This comment thread is long and pointless enough to be worthy of Reddit. </FLAMEBAIT>

On the other hand, if it keeps going, this dramatic story of semi-colons could be novelized and eventually turned into box office gold. Hmm... no time to start like the present...


Jacob Thornton leaned back in his chair, folding his hands behind his head. He was left with another free afternoon in the offices of Twitter from all the time saved in not inserting unnecessary semi-colons. Yes, life was beautiful.

Suddenly, Douglas Crockford stormed into his office, red-faced and sweating. "You asshole!" shouted Doug. Jacob sat up quickly and jolted the desk, nearly toppling his mocha frappuccino. Doug continued his tirade: "What's this lack of semi-colon shit that broke JSMin? It's insanely stupid code. Learn to write JavaScript properly or I will fucking end you." ...

(to be continued)

Serguei Shimansky

@matthewdl We need illustrators for that memorable story.

alekop

Over 200 comments over a missing semicolon?? For fuck's sake people, don't you have any work to do?!

Matthew Dean

@englishextra That's a good idea. Got ideas for some? In the meantime, I've moved the story here: http://figment.com/books/308826-Dangerous-Punctuation

Edit: I have since extended this scene and I expect David Fincher to call any second with a movie deal.

Ryan Tenney

Who could have guessed that missing semicolons would lead to the creation of Thornton/Crockford slash fiction?

Tugberk Ugurlu

@alekop apparently you don't have one either.

Ravi Sarma
ravi commented April 18, 2012

+1 on @englishextra suggestion -- definitely the comic route is the way to go. Who knows, perhaps there shall be a SuperColon... no wait...

@alekop congratulations on the 201st comment. And it's not even 5:01 yet. :-)

backspaces

@alekop .. just consider /. maybe we can be as OT and pointless!

tomByrer

While I myself don't care so much either way about semicolons (whatever performs fastest is best IMHO), I imagine someone can write a tool to + or - ; to their preference. I also find it ironic that the pro-; is on GitHub:

Do your best to never use a semicolon. This means avoiding them at line breaks and avoiding multi-statement lines.

https://github.com/styleguide/javascript
But, "Style Guides" are just that; guides.

元彦

Be careful with Semicolon-free!

Tugberk Ugurlu

@tomByrer that's a horrible reference and one should never look at that page. As @haliphax indicated, If Javascript didn't require semicolons, then it wouldn't be called "Automatic Semicolon Insertion". This sentence should end the discussion but apparently didn't .

Debjit Biswas

I need to teach some programmers JavaScript and make sure they are ready in 3 weeks. Should I explain them all the rules of ASI? Aren't we supposed to make our fellow developers' lives easier? Who do we code for really?

John Loy

Ok, just because it's Friday and this thread is so entertaining:
Alt text

Stephen Bussard

Someone with power (@douglascrockford ?) needs to set things in motion to make semicolons required in the spec. QED

Isaac Z. Schlueter

@sbussard Do you know what QED means?

Making semicolons required in the spec would be a web-breaking change. TC-39 will never do that.

Tugberk Ugurlu

@sbussard right, then all of the people's code will break. Changing something drastically would be the same as stabbing someone as @douglascrockford said. That's why they cannot do that.

Stephen Bussard

@isaacs this argument is the best reason to add semicolons to the spec. QED — as was demonstrated by this argument. A couple regex replacements could fix pretty much all of that. Wasting time on dumb little disagreements is the real web-breaking problem. ■

Isaac Z. Schlueter

@sbussard HAHAHAHa, dumb disagreements are web-breaking, that's what the web is FOR.

Stephen Bussard

yet we consider ourselves engineers... :/

Stephen Bussard

"You cannot make progress without making decisions." -- Jim Rohn

Diego Barros

If the reason for not including a semicolon was aesthetics, then one wouldn't do something like this:

Dropdown.prototype = {

    constructor: Dropdown

  , toggle: function (e) {
      var $this = $(this)
        , $parent
        , selector
        , isActive

Those dangling commas, in the middle of nowhere, really do look bad.

Najam

If you're still reading this.. you really should go out and PLAY!

Miclovich

damn these notifications I've been getting lol! #PLAY

Nate Cavanaugh

Mr. Madison, what you've just said is one of the most insanely idiotic things I have ever heard. At no point in your rambling, incoherent response were you even close to anything that could be considered a rational thought. Everyone in this room is now dumber for having listened to it. I award you no points, and may God have mercy on your soul.

Greg Tczap
gtczap commented May 02, 2012

Seeing how @fat responded to this reminds me of how dumb it would be to use a library maintained by someone who doesn't value quality and reason, but makes decisions merely 'because they feel like it'. Pretty things built on a poor foundation aren't worth much to me. This is a great way to prune your user base.

Matthew Dean

The drama of this Github thread has now been forever immortalized.

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

Serguei Shimansky

@matthewdl

The drama of this Github thread has now been forever immortalized.

Read the story with pleasure

Seth Aldridge

This thread can be summarized in two images:

Crockford:
Arg

Fat:
Deal wit it

Maxime Haineault
h3 commented May 03, 2012

Ugly code that works > nice looking code that doesn't work.

Stop being a dick and put a god damn semicolon already, it's the best practice anyway.

Daniel Landsverk

Yep, congrats, you guys are now famous. Twitter devs fighting over a semicolon in a code that apparently isn't broken is pretty hilarious. You should probably finish off this disussion before (and if) Twitter's shares goes public on the stock market.

Zack Siri

only geeks can fight over something like this.

teiman
teiman commented May 14, 2012

FTFY Only greeks can fight over something like this.

"You will go you will return not in the battle you will perish"
http://www.ancient-greece.org/history/delphi.html

Tymon Sturgeon

Someone should just create a library that can semi-colon-ify the semi-colon free code, then we could use lint, and minifiers without extra work. And, no standards need broken, and this code can be considered valid. Much the same as having a opinion on whether brackets go on the same, or next line, or the method of indentation (# spaces, or tabs, etc...)

I personally use semicolons, 2 or 4 spaces for indenting, and keep my brackets on the same line. I don't see any reason to crucify fat for his style of code, and I also don't see why douglascrockford needs to have JSMin parse this kind of code. At this moment, JSMin not parsing the code is not a bug, but a choice.

backspaces

They did. Its called CoffeeScript

Matthew Dean

What we need is more fat / crockford fan fiction.

Chris Harrison

Can you please just add semicolons? By omitting them you are causing me and my team a big headache. Thanks!

scott romack

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

Tobias Baunbæk

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

Serguei Shimansky

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

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

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

Tim Wickstrom

@pete-otaqui SO TRUE!

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

Tommaso Urli
tunnuz commented July 05, 2012

Ok, how do I unsubscribe from this?

Aaron Hall

Just reply with "unsubscribe" in all caps

Corey Farwell

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

Nihad Abbasov
NARKOZ commented July 30, 2012

Matt Tagg

@NARKOZ epic win on an already hilarious thread :D

Tomas

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 Aspra

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

Marco Oliveira

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

blpiltin

"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

fcntl

You should always use semicolons with curly-brace languages.

joshcartme joshcartme referenced this issue in django-compressor/django-compressor December 12, 2012
Closed

Incorrect handling of semicolon less js #345

Rod Vagg rvagg referenced this issue in rvagg/node-worker-farm January 01, 2013
Closed

Tried to jslint this. It complained about semicolons. #1

William P. Riley-Land
        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
Eli Skeggs skeggse referenced this issue in fvdm/nodejs-youtube April 21, 2013
Closed

Update youtube-feeds.js #6

Enrique
enrmarc commented May 14, 2013

Well, I just want to be part of this;

backspaces
Alex vogdb referenced this issue in vogdb/Leaflet.ActiveLayers June 05, 2013
Closed

Douglas Crockford 101 ;) #1

Vlad Patryshev

"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?

Chris Harrison
Jing Dong

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

semicolons

Mathieu ROBIN

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...

Minko Gechev mgechev referenced this issue in mgechev/angularjs-style-guide October 07, 2013
Closed

Update the AngularJS wiki instead of a standalone repo #14

Rifat Nabi

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).

Scott van Looy scottbert referenced this issue in chill117/express-mysql-session March 20, 2014
Closed

Adding in code to deal with disconnects #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.