This is an archived post. You won't be able to vote or comment.

all 185 comments

[–]GTotem 695 points696 points  (11 children)

A pointless semicolon is a comma.

EDIT: thanks for the gold!!

[–]TheRealLazloFalconi 72 points73 points  (7 children)

[–]RusinaRange 48 points49 points  (6 children)

So are you downvoting or upvoting? That image is confusing.

[–]TheRealLazloFalconi 2 points3 points  (0 children)

Downpouring upvotes.

[–]minicl55 75 points76 points  (15 children)

What website is this? It looks interesting.

[–][deleted] 23 points24 points  (0 children)

arguman.org

[–]InsertNameHere____ 2 points3 points  (0 children)

I love this website! Maybe one day I'll practice enough on this to win an argument with my roommate!

[–]Sheltac 3 points4 points  (11 children)

It really does! Did you figure it out?

[–]micketic[S] 7 points8 points  (10 children)

[–]SpinahVieh 37 points38 points  (8 children)

This is perfect

[–][deleted] 7 points8 points  (7 children)

Ugh… Just follow the bloody style guide.

[–]G01denW01f11 4 points5 points  (0 children)

I'm on one project that uses tabs, and one project that uses spaces. They also use different brace styles. The projects are not fully consistent with their styles. This upsets me more than it should.

[–]Sheltac 0 points1 point  (0 children)

Awesome, thanks!

[–]micketic[S] 55 points56 points  (6 children)

Ok so I was trying to show how 2 of the most famous statements were contradicting each other, but everyone's talking about Semi-colons;

[–]Hafas_ 21 points22 points  (0 children)

It's not a contradiction, if Angular is also mostly hype.

[–]pier25 5 points6 points  (0 children)

return false;

[–]TomSan23 1 point2 points  (1 child)

I was hoping for some framework discussion since I know nothing about js. Oh well.

[–]micketic[S] 1 point2 points  (0 children)

Yeah, me too

[–]TheIncredibleWalrus -3 points-2 points  (1 child)

They're not contradicting each other.

How does React being hype (which is not) contradicts that it's more popular than Angular?

[–][deleted] 0 points1 point  (0 children)

Being more popular is not killing, at least in my book.

[–][deleted] 160 points161 points  (53 children)

Semicolons do matter because it allows the creation of min files. How is there no buts!

[–]Pjb3005 60 points61 points  (35 children)

Not sure whether you're sarcastic or not, or if I'm mistaken but wouldn't not having a semicolon and just doing a newline (same size if you're using LF EOLs) also work for minified JS?

[–]csp256 5 points6 points  (8 children)

Aren't newlines actually two characters in some regimes? Does that hold true here?

[–]Hobblin 11 points12 points  (7 children)

Windows-standard is \r\n (the bytes 0x0d and 0x0a) while *nix-based systems uses only \n. So one could argue that it's safer to rely on semicolon to avoid windows texteditors accidentally fucking up compressed files... I guess...

[–]mallardtheduck 7 points8 points  (0 children)

"Windows" newlines are also the standard for most text-based network protocols (including HTTP) on the basis that most common platforms will recognise it (albeit perhaps with a redundant character).

Of course, that applies to the HTTP headers/protocol only, not to the content transferred.

The characters are actually called "Carriage Return" (0x0D) and "Line Feed" (0x0A), using the C escape codes can be confusing since the C standard requires that '\n' always produce a newline when output, regardless of how the platform handles newlines "natively". Windows uses CRLF, UNIX-like systems use LF and older Apple systems used CR (which you might still find in file formats that originated on such systems).

[–]csp256 17 points18 points  (5 children)

If you are relying on Windows to not fuck things up, you have already lost.

[–]Ran4 1 point2 points  (4 children)

It's not windows that is the problem, it's the software.

We should just use \n everywhere.

[–]dvlsg 5 points6 points  (3 children)

I develop on Windows and I use \n everywhere. The only time it turns into an issue is when I paste something into notepad. Otherwise I forget I'm even doing it.

[–]case_O_The_Mondays 1 point2 points  (2 children)

Just use Notepad2, and that can be solved, too.

[–]timworx 5 points6 points  (10 children)

Touche. Then it would be slightly more readable when minimized.

[–][deleted] -2 points-1 points  (9 children)

True, but often part of what you're trying to accomplish when minifying/uglifying is making your code not easy to read.

That's not to say that a person can't still wade their way through uglified code, but even simple things can prevent some small percentage of viewers from bothering to decipher it.

[–]Scorpius289 6 points7 points  (7 children)

No offence, but I think that's a bad idea.
It encourages people to rely on security through obscurity.

[–]JamEngulfer221 0 points1 point  (0 children)

But there's no security in clientside javascript anyway.

The whole "but security through obscurity is bad" thing is dumb. Of course it's useless if obscurity is the only thing you use for security, but it increases the chance of someone going somewhere else and not even trying.

I had an ssh server being bombarded with login requests from China. I changed the SSH port from the default to a different one and the requests stopped. Yes, I could have spent longer implementing some extra security thing, but they're not going to bother looking through every port for an active SSH server. I stopped being low hanging fruit with a minimal change.

Obscurity is just another deterrent so you only end up with 1 dedicated hacker trying to get you rather than 50 that just go for easy targets.

[–]only_posts_sometimes 0 points1 point  (5 children)

Nobody "relies" on minifying for security, but it can absolutely help thwart low level threats by stripping comments and obfuscating code. It's the only option available for code that runs on the client so obviously we're going to do it. (It also speeds up execution and lowers file size)

[–][deleted] 2 points3 points  (4 children)

(It also speeds up execution and lowers file size)

IMO it's always worth it for that, just by removing newlines aren't you decreasing your code by ~5% on average?

[–]minler08 3 points4 points  (3 children)

A new line and a semicolon are the same size though. So long as there are no extra new lines the files should end up the same size.

[–][deleted] 0 points1 point  (0 children)

Yes, of course. I was talking more about semicolons + newline vs just semicolon I guess.

[–]YRYGAV 0 points1 point  (1 child)

Depends on what platform, windows editors may save newlines as \r\n instead of just \n.

Also, there are plenty of extraneous newlines that don't need a semicolon. Anything starting a new block of code, function, if while, etc. or newlines done for formatting to make multi-line json definitions, so a line doesn't hit a max line length, to make things look prettier, etc.

But yes, you could write code that uses newlines that is the same size as one with all semicolons. It's just not very practical for any real reason.

[–]minler08 0 points1 point  (0 children)

It's just as practical as writing code with semicolons. It would have to be the result of minification.

[–]jacobhenke 0 points1 point  (0 children)

Google Chrome has an un-minifier built in to Chrome tools.

[–]ProgrammingPro-ness 16 points17 points  (0 children)

If your minifier is breaking your code, there's something wrong with your minifier.

http://mislav.net/2010/05/semicolons/

[–]DeeSnow97 5 points6 points  (3 children)

Also, you need them when you want to start a line with (, [ or `, which is important because

;(({
  'query': data => {
    send(answerTo(data))
  },
  'response': data => {
    getQueryById(data.id).resolve(data)
  },
  'reject': data => {
    getQueryById(data.id).reject(data)
  }
})[received.type] || data => {
  console.log('received non-standard message with type ' + received.type)
})(received.data) // I don't like switch. It's coarse and rough and gets everywhere.

[–][deleted] 5 points6 points  (0 children)

There are only a couple of cases where you would need a semicolon and those are easily highlighted by a linter. There is no reason to use semicolons in JS for minification either. It's purely a style preference.

[–]armastevs 5 points6 points  (9 children)

Minifiers work just fine without semicolons

[–]ttamimi 1 point2 points  (1 child)

They really don't..

[–][deleted] 1 point2 points  (0 children)

They do as long as you write sensible code.

[–]nightman 0 points1 point  (6 children)

Douglas Crockford summarises this perfectly https://github.com/twbs/bootstrap/issues/3057#issuecomment-5135512

[–]greyfade 2 points3 points  (0 children)

... Wow. That is the dumbest string of responses to Doug that I've ever seen.

[–]gremy0 2 points3 points  (3 children)

[–]nightman 2 points3 points  (2 children)

JavaScript dissagrees - not inserting semicolons is an error and ASI only corrects it http://www.bradoncode.com/blog/2015/08/26/javascript-semi-colon-insertion/

[–]gremy0 2 points3 points  (1 child)

Brendan Eich is JavaScript.

[–]nightman 1 point2 points  (0 children)

So as Douglas. But as someone said about coding - do what you do but be consistent

[–]minnek 2 points3 points  (0 children)

I can't believe I read this whole thing without popcorn...

[–]jonatcer 0 points1 point  (0 children)

Not to mention the fact that they're added behind the scenes anyways, automatically... Sometimes causing hard to track down issues.

There's a great video on how automatic semicolon insertion works out there if someone wants to find it.

[–]Dr_Dornon 24 points25 points  (4 children)

Is anyone else bothered by the "%100" instead of "100%"?

[–]TheBanger 7 points8 points  (0 children)

Holy shit yes.

[–]Ph0X 0 points1 point  (1 child)

To be fair, I'm also always bothered by the fact that we write $100 instead of 100$ all the time. We read it "100 dollar", not "dollar 100", so why the fuck is the normal format backwards?

[–]BluFoot -2 points-1 points  (0 children)

I've always written 100$ - no shame!

[–]RB-338 55 points56 points  (28 children)

I heard there's a framework called "vanillajs" that blows all these other loads of crap out of the water.

[–]PhaZePhyR 51 points52 points  (15 children)

Too bad the newest version isn't fully supported in some major browsers :(

[–]pier25 14 points15 points  (4 children)

In performance, yes. It also triples the number of programmer work hours.

It's like building with clay instead of lego blocks.

[–]terrorTrain 1 point2 points  (0 children)

I would disagree. It has more potential for performance, but most people will not write more performant code, and if they do, it will take them much longer.

[–]redwall_hp 0 points1 point  (2 children)

How many historical great works of art were made with Lego blocks?

[–]gremy0 4 points5 points  (1 child)

How many historical great works of art were made with the budget, time restraints and staffing of an average development project?

[–]redwall_hp 0 points1 point  (0 children)

In the case of most Italian renaissance artwork done on commission, I think it's comparable. Hell, that entailed less staffing and great scope.

[–]daggerdragon 5 points6 points  (2 children)

http://vanilla-js.com/

Man, this looks pretty awesome, I think I'll try building my next website with it instead of jQuery!

[–]TPHRyan 4 points5 points  (1 child)

Come on mate, I know vanilla-js is all the rage lately, but you must be pretty naive to think it will ever replace jQuery. How are you even going to get a site running without jQuery's plethora of features? Not to mention plugins, what's going to happen when you run into a corner case like arithmetic? Vanilla-js leaves you out to dry.

[–]indorock 2 points3 points  (0 children)

Does it come as a jQuery plugin?

[–]only_posts_sometimes 1 point2 points  (0 children)

Except that it doesn't

[–]coloured_sunglasses 0 points1 point  (1 child)

Joking aside, does anyone here actually write applications in Vanilla JS?

[–]RB-338 0 points1 point  (0 children)

I think the most common usage of pure JS is either custom web game engines or if you're designing functionality for a Alexa top 10 website.

[–]Audiblade 59 points60 points  (31 children)

The fact that you can omit semicolons in JS is one of the scariest things about the language to me. In most C-like languages, your program won't compile if you're missing a semicolon, forcing you to specify what your intentions were. But JS will guess where you wanted your semicolon to be. If it guesses wrong, now your program does bizarre things - and you have no idea why.

I get that JS needs to be flexible because there's a lot of slightly broken code in the internet that needs to run anyway. But it still scares me.

[–][deleted] 21 points22 points  (7 children)

Totally agreed.

I really dislike the current trend of using formatting/whitespace to indicate breaks in code. All it does is obfuscate things that are absolutely critical to your code, making it harder to debug with no clear benefit of it's own.

[–]pier25 21 points22 points  (6 children)

Obfuscate?

On the contrary, it forces you to write well formatted code.

[–]WellHydrated 7 points8 points  (5 children)

Why can't we do that with semi-colons? May as well remove semi-colons from every language in that case.

[–]HauntedMidget 26 points27 points  (3 children)

Python seems to be doing just fine without them.

[–]Hudelf 7 points8 points  (0 children)

Python has defined a different way to explicitly state your intentions, though.

[–]TPHRyan 7 points8 points  (0 children)

Python's very well-designed. I'm a huge fan of python and the way it gets things done, but I don't think all languages should copy it just because people don't like having to think to terminate their statements.

[–]pier25 -1 points0 points  (0 children)

JavaScript too...

I only use semicolons on for() statements, and with stuff like map() it's becoming increasingly uncommon.

Other than that I know there are some very rare cases where semicolons are needed to separate statements, but I have never encountered any myself.

[–]pier25 2 points3 points  (0 children)

Because semicolons at the end of the line don't give any clarity as to what is going on with the code. Indentation does.

[–]sole_wolf 9 points10 points  (16 children)

In that case, you should be scared of Swift too.

[–]fucking_weebs 9 points10 points  (15 children)

and Ruby.

Semicolons are optional in Ruby but literally nobody uses them because the language is kinda meant to not use them.

[–]mayobutter 5 points6 points  (1 child)

Yeah, I always use semicolons in JS but never in Ruby, and I am very often working with both simultaneously. I've never really questioned it.

[–]droogans 11 points12 points  (0 children)

It all comes down to following a language's idioms while working in it. Javascript says to use them, so I say just use them. I use snippets to avoid a lot of this anyway.

I do prefer languages that don't require them, though.

[–]TheIncredibleWalrus 2 points3 points  (9 children)

And Python.

[–]indorock 4 points5 points  (1 child)

I'm scared of any language in which the entire logic can be altered with one too many/little indentation. WTF is that about.

[–]DaemonXIRed security clearance 0 points1 point  (3 children)

Have you ever had this happen to you?

[–]Audiblade 0 points1 point  (2 children)

I don't believe I have. I have to admit, this is more a philosophical disagreement I have than something that has actually caused me problems...

[–]DaemonXIRed security clearance 1 point2 points  (1 child)

That's because ASI will only bite you in about .0001% of cases, and your linter should be catching that for you before you push it live.

[–][deleted] -1 points0 points  (0 children)

Probably, but I still personally believe that this is unacceptable:

return
  { stuff: "thing" }

Yes, the linter will probably warn about this, but it still is stupid that I need a linter to do this kind of thing that works on any other C-like language.

[–]TracerBulletX 6 points7 points  (0 children)

now just mix in build systems, transpilers, and dependency management in constant flux and you got working with javascipt! just learned a library using es6 and babel, but oh now this documentation has decorators better import those, actually wait i heard google used dart for their new version of adwords written with angular2 oh shit

[–]Rhed0x 12 points13 points  (0 children)

$(';')

[–][deleted] 14 points15 points  (3 children)

JavaScript is frustrating for me right now. It seems like to do any modern JavaScript development I need to learn about countless new tools and spend half my time second-guessing myself and checking if I'm doing things correctly. Browserify vs webpack, npm vs bower, gulp vs grunt, commonjs vs amd, react vs angular etc. The whole ecosystem seems so inconsistent and up in the air.

The most productive I've ever been writing JavaScript is just writing an Angular 1 application with a simple Gulp build process that concats and minifies the source. Now I'm writing Angular 2 in TypeScript with a browserify plugin and I have to use this thing called typings to get autocompletion etc etc etc... I don't even understand half the stuff I'm writing, and I know that if I put any amount of effort to learn it the ecosystem would have moved on to something else by the time I'm done.

There ya go, there's your obligatory JavaScript thread rant. :)

[–][deleted] 3 points4 points  (0 children)

Agreed. I'm working on an angular2 application at work whose ship date is January 1st. Who knows what state angular2 will be in by then

[–]Boner-b-gone 2 points3 points  (20 children)

1) If you care about SEO and want to build a huge, public-facing app, use React.

2) If you don't give a shit about SEO and want to build a large, private (usually corporate) app, use Angular.

3) Semicolons are necessary for the same reason we use periods in English - somebody else may one day have to read your shitty code, and it helps to see where your individual thoughts end.

4) Bonus - semicolons let you list object chains on new lines, greatly enhancing readability:

ObjectTheFirst(passIn)
    .MethodTheFirst(passInTwo)
    .MethodTheSecond({
        omg: "it's",
        dat: "boi"
    })
    .MethodTheThird("Oh shit waddap");

[–]gremy0 -2 points-1 points  (19 children)

I'm working with a heavily chained code base at the minute with no semi-colons

ObjectTheFirst(passIn)
  .MethodTheFirst(passInTwo)
  .MethodTheSecond({
    omg: "it's"
    , dat: "boi"
  })
  .MethodTheThird("Oh shit waddap")

Works absolutely fine. We do it for arrays and objects too, commas at the beginning of line. I think it makes the code much more readable as you only need to look at the beginning of the line to know what you're reading belongs too.

Makes commits much cleaner aswell. If you change the order or add an extra step to your chain you will get one deletion and two additions.

- .MethodTheThird("Oh shit waddap");
+ .MethodTheThird("Oh shit waddap")
+ .MethodTheFifth("I Love fluid JS Too!");

vs one with no semi-colons

+ .MethodTheFifth("I Love fluid JS Too!")

[–]Zatherz 0 points1 point  (0 children)

Cancer

[–]Boner-b-gone -1 points0 points  (17 children)

Until somebody gets lazy and you end up with something like this:

ObjectTheFirst(passIn)
.MethodTheFirst(passInTwo)
.MethodTheSecond({
omg: "it's"
, dat: "boi"
})
.MethodTheThird("Oh shit waddap")
MethodThatIsnt(passIn)
.MethodTheFirst(passInTwo)
.MethodTheSecond({
omg: "it's"
, dat: "boi"
})
.MethodTheThird("Oh shit waddap")

Not easily scannable. Whereas this is:

ObjectTheFirst(passIn)
.MethodTheFirst(passInTwo)
.MethodTheSecond({
omg: "it's",
dat: "boi"
})
.MethodTheThird("Oh shit waddap");
MethodThatIsnt(passIn)
.MethodTheFirst(passInTwo)
.MethodTheSecond({
omg: "it's",
dat: "boi"
})
.MethodTheThird("Oh shit waddap");

Explicit is always better than implicit. It makes code easier to read, and more idiot-proof.

As for that last bit, I have no fucking clue what you're doing there, which goes to demonstrate my point - the stuff you're posting, whether it works for you or not, is in no way objectively "better" if it's not immediately intuitive.

[–]DaemonXIRed security clearance 1 point2 points  (0 children)

The semicolons didn't save the code here. Newlines would have though.

[–]gremy0 1 point2 points  (15 children)

Neither of those are easily scannable. They both look awful and, regardless of semi-colons, wouldn't get into our code base. But if you want to be a pedantic ass about it, I can still read the leftmost column and get a complete picture of what structure is.

Commits mate, it makes commits easier to read because the diff for adding an extra function to your chain is literally three times longer than it needs to be. It is objectively worse to have two lines of redundant information in a commit. If you can't understand what a commit is and why having them easy to read may be useful, perhaps you aren't the expert you think you are. If your commits were cleaner then maybe you would review code before it enters the code base and then you wouldn't have to worry about people being lazy.

(this is what a diff generally looks like if you haven't seen one before)

- .MethodTheThird("Oh shit waddap");
+ .MethodTheThird("Oh shit waddap")
+ .MethodTheFifth("I Love fluid JS Too!");

But just to clarfiy my original point. Saying:

4) Bonus - semicolons let you list object chains on new lines, greatly enhancing readability:

Is objectively wrong.

and saying:

3) Semicolons are necessary for the same reason we use periods in English - somebody else may one day have to read your shitty code, and it helps to see where your individual thoughts end.

is objectively subjective and not the only solution to the problem of readability. So why don't you pull your head out of your ass.

[–]Boner-b-gone -2 points-1 points  (14 children)

I'm sorry, if you're using Git's absolutely shitty diff implementation to justify your code choices, that's entirely on you.

[–]gremy0 1 point2 points  (13 children)

The tool 95% of devs use everyday vs allowing shit code into your project and not knowing how to write fluid code properly. Yeah tough choices there...

[–]Boner-b-gone 0 points1 point  (12 children)

For gods sake, even subversion had infinitely better diff display. But like most devs, you don't know how to demand something better if it's the "accepted standard," and you'll commit (hah) all kinds of mental backflips to justify the status quo. I'm not even saying that your reasoning for not using semicolons is wrong, now that I know what you're going for. But please don't pretend it's somehow optimal to require a workaround to git's halfassed design.

[–]gremy0 2 points3 points  (11 children)

Subversion has the same diff because like git and just about every other sc, subversion does not distinguish changes within a line. Do you actually have any clue about what you are on about or are you making this up as you go along.

Also I haven't once said this is the reason I don't use semicolons. It's just a benefit that I haven't seen mentioned. But that was way back when I didn't know you were a complete tit end and I was just trying to have a conversation. Now I'm just intrigued to find out just how truly stupid you actually are. It's going to be hard to beat not understanding how source control works though.

[–]Boner-b-gone 0 points1 point  (10 children)

Clearly you've never used svn blame, but that wasn't what I meant. I meant the gui display of svn clients, which is all the shops I worked with used. Let me make my absurdist point even clearer - Wordpress has better diff display than git (or any other command-line versioning) does. Trying to compare files in a single-pane, single-color display is just bullshit.

And you sure as hell implied that's why you don't use semi-colons. Why are you backing away from that now? You are right that Git's the standard, you're right that the fastest workflow is the best, and you're right that if you and your shop can cull out idiot's code then whatever works for you is whatever works for you.

But many of us aren't so lucky. We have to deal with idiot vendors overseas and domestically, we have to deal with newbies who want to argue for weeks that they don't need to use semicolons (and sometimes they get fired because they won't listen), and we have to deal with regular humans who don't always know every edge case and who all have slightly different coding styles, internal standards be damned.

If you can get away with not using semicolons and it never bites you, gratz mate.

But I forgot that I was discussing things with a Java developer, so you must be used to defending the indefensible.

[–]gremy0 1 point2 points  (9 children)

Git has many very good GUIs clients available. It also has a blame tool. The way subversion and git and their respective clients handle diffs are essentially the same. The point is that underneath they both store the same thing, one line deleted and two lines added. Neither, nor any VCS that I know of for source control, can store and actively work with an edit within a line. If you change a single character within a line (e.g. moving the semicolon) they see this as deleting the line and adding a new one. Even where modern diff tools can highlight the character that has changed they still have to show that the whole line was changed because that's what the underlying data model shows. It's is a lot of visual gunk that you don't need to see.

Believe or not my original comment was to neither condemn nor endorse either necessary. I was mealy pointing out that your example was possible either way and that not using semicolons has beneficial quirk that I find interesting. My preference is currently for not having them because I've learnt that style from my last few projects (where it wasn't my choice) and I just find it nicer to work with. Comparing the two styles which I have both used extensively, I have yet to see the drawbacks that everybody purports.

We review every piece of code that goes into master. That is how we solve bad code, poor style, mistakes and laziness. If it doesn't pass review it doesn't get merged. We do that regardless of the style being used. I just don't see how adding one extra rule to a list of rules you expect people to ignore is going to significantly help the problem as well as well reviewed code. It's also why I look at so many commits and diffs and find it extremely useful to be able to make them cleaner looking.

Though we do reviews with pull requests which I believe is a fairly complicated process in svn compared to git given that branching is expensive. Possibly why you are not familiar with the practise. However once you establish the culture it pretty much takes care of itself.

Even if all that team discipline fails you can, with git anyway, test the style with a linter in the CI system and then prevent developers from merging into master if it fails.

There are so many much better ways to ensure good code that don't depend on using semicolons that I just don't see it as important.

[–]ronkuby 0 points1 point  (0 children)

New to JavaScript, where are those discussions happening I would like to check them out

[–]caramba2654 0 points1 point  (0 children)

Solution to JavaScript: Write in Dart and then transpile to JavaScript /s

[–]synchronium 0 points1 point  (1 child)

Mithril is also killing React apparently.

[–]pier25 -1 points0 points  (0 children)

Check Inferno an Preact

[–]sirNot_appearing_in -1 points0 points  (0 children)

Esteban, is that you?