Please indent your code

One of the most importants purposes of the code tags is to preserve indentation.

It doesn't matter if you use spaces or tabs. But try to not mix them, because different tabs width will give different results (this page use 8 characters)

It doesn't matter the widht that you use, but please be consistent.

In fact, you shouldn't worry about that. Just let your IDE do the work.
gg=G

PS: The other day I was reading some javascript. ¿Is there a good reason for 'one liners'?
"Users don't read anything."
closed account (S6k9GNh0)
ne555, to obfuscate. Seriously.
Last edited on
PS: The other day I was reading some javascript. ¿Is there a good reason for 'one liners'?


smaller file size, saving bandwidth and faster load times. It's not much really, but if you have thousands even millions of people trying to view your site it adds up. That's why there's also a minimal version of the jquery library, which is basically the jquery library jammed into a single line or something. It also applies to CSS code so you'll also see most CSS rules crammed into a line of their own instead of spreading it out.

Something like:

1
2
body { background-color: #fff; font-family: Arial; margin: 0 auto; }
#container { position: relative; margin: 0 auto; width: 960px; padding: 20px; } 


instead of

1
2
3
4
5
6
7
8
9
10
11
12
body {
    background-color : #fff;
    font-family : Arial;
    margin : 0 auto;
}

#container {
    position: relative;
    margin: 0 auto;
    width: 960px;
    padding: 20px;
}


Although, both work the same way.
Last edited on
¿But why stop halfway then? (for compresion or obfuscation)
Well for compression, I think it's mostly because eventually someone has to read or maintain it. Especially for CSS codes, so it's more about striking a balance. You only save on the newline characters anyway, so like in the first example.

1
2
body { background-color: #fff; font-family: Arial; margin: 0 auto; }
#container { position: relative; margin: 0 auto; width: 960px; padding: 20px; } 


We only have 2 newline characters, whereas on the second example

1
2
3
4
5
6
7
8
9
10
11
12
body {
    background-color : #fff;
    font-family : Arial;
    margin : 0 auto;
}

#container {
    position: relative;
    margin: 0 auto;
    width: 960px;
    padding: 20px;
}


We have 12 newlines characters.

The first example isn't that much harder to read though cause we know the selector is on the left side, so it's easy to find the styles for the body, and it's also quite easy to find the style for the html element with an id of "container". So you get something that's not so difficult to maintain, yet not bloated. Having that balance is usually good in my opinion, cause then you'd somewhat have the best of both worlds.

That probably doesn't work well with javascript though cause I don't think it would help with readability anyway. So compressed javascript code would most likely be all placed on a single line in my opinion.

As for obfuscation, I don't really see any reason not to put obfuscated code all in a single line either.

Edit:
Oh lolz, I just looked up this site's css and javascript file and both have their code on a single line for maximum compression. I think even spaces have been removed.

http://www.cplusplus.com/main29g.css
http://www.cplusplus.com/main29f.js

I think most of the time the purpose is for compression though instead of obfuscation. You can easily tell if it's not obfuscation when the code has descriptive variables and function names I mean.

Last edited on
Topic archived. No new replies allowed.