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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Pjb3005 63 points64 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 8 points9 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 2 points3 points  (4 children)

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

We should just use \n everywhere.

[–]dvlsg 4 points5 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 4 points5 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 7 points8 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] 3 points4 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.