PDA

View Full Version : Ext coding standards



Animal
27 Nov 2008, 12:19 AM
I've noticed a lot of indenting with tabs creeping into recent SVN commits.

I remember Jack encouraging me to indent with spaces, and on his recommendation, I changed my Eclipse setup to use spaces for indenting.

This mean more predictable layout in code when displayed across a variety of media and software.

This is especially noticeable when debugging in Firebug. Tabs cause the code to fly off to the right much more, and if a routine has mixed indenting characters then it's not readable in Firebug.

Can a standard be set for Ext committers to use spaces? It's a simple grep/search-replace operation to fix the code.

mystix
27 Nov 2008, 12:30 AM
ditto this request.

i've got my editor set to use spaces for indentation, and to trim empty trailing spaces on save.

i also make it a point to save any file i poke with unix line endings before committing.

eggspencer
27 Nov 2008, 5:47 AM
Definitely, spaces are much better. I guess the question then is how many to use? I know some people use 4 but I really can't see the point, I find 2 greatly preferable. Opinions?

Condor
27 Nov 2008, 6:21 AM
Can somebody tell me why spaces would be better than tabs?

You can shrink ext-all-debug.js by 25% (http://extjs.com/forum/showthread.php?t=44497) by replacing leading spaces with tabs!

And, yes, tab indentation is different on various systems: HTML (this forum) shows 8 spaces, Firebug shows 6 spaces etc.
But I don't see this as a big problem. Most editors even allow you to customize tab indentation to your own needs (the default is often 4 spaces).

Animal
27 Nov 2008, 6:52 AM
But of course yuicompressor+GZIP doesn't care about a repeated whitespace character, so that's neither here nor there in the real world of live apps.

Have you tried debugging code which uses tabs in Firebug? It indents way too much.

And its even worse when several coders have been at work, and the indenting characters are mixed. Each line is at a different level.

Just post code in code tags here, and you'll see a difference.

The problem is one of consistency. A tab character is open to interpretation. Spaces just require that you use a fixed width font

jay@moduscreate.com
27 Nov 2008, 8:58 AM
spaces are better than tabs because not every application renders a tab with the same amount of space.

Regardless of size, it's the preferred 'standard' way for developers to have code indented. I remember learning this in my early unix/linux years.

mankz
27 Nov 2008, 11:56 AM
+1 for spaces.

Let's do a whitespace vs tabs poll :)

Jaitsu
27 Nov 2008, 12:58 PM
Have you tried debugging code which uses tabs in Firebug? It indents way too much.

I can't say I've ever had this problem...

I don't know which is better, but tabs are easier, you know its consistent (hitting one tab after function declarations etc.) rather than having to bash the space bar numerous times, we hit enough keys in a day

danh2000
27 Nov 2008, 2:55 PM
I can't say I've ever had this problem...

I don't know which is better, but tabs are easier, you know its consistent (hitting one tab after function declarations etc.) rather than having to bash the space bar numerous times, we hit enough keys in a day

I think you miss the point - your IDE can be configured to create 4 spaces automatically when you hit the tab key.

My preference is spaces too, but I wouldn't lose any sleep over using tabs - the important things is that everyone in your team is using a consistent approach.

Jaitsu
27 Nov 2008, 2:57 PM
yeah i misunderstood that bit, I may change to spaces then!

evant
27 Nov 2008, 6:01 PM
I have my editor set to convert tabs to whitespace.

mxracer
27 Nov 2008, 6:27 PM
I have just set Eclipse to insert spaces for tabs :)

mjlecomte
27 Nov 2008, 7:44 PM
You should perhaps have the number of spaces in your poll, 2, 3, or 4. I suspect most will say 4, but who knows.

mystix
27 Nov 2008, 10:50 PM
You should perhaps have the number of spaces in your poll, 2, 3, or 4. I suspect most will say 4, but who knows.

poll updated (and unfortunately reset)

the 7 other ppl (besides me) who voted whitespace, pls leave a message stating how many spaces exactly and i'll update the poll accordingly.

danh2000
27 Nov 2008, 11:06 PM
I had voted whitespace - Can you please add this to the 4 spaces vote.

Thanks.

Animal
28 Nov 2008, 12:29 AM
I can't say I've ever had this problem...

If you've been stepping through Ext code, that's because Jack began with consistent space indentation, so it was never a problem to display on any medium, in any software.

Condor
28 Nov 2008, 1:14 AM
Yeah! I'm no longer the only one that voted for tabs!

For all those who voted for spaces:
Is one of you actually using an editor that doesn't allow specifying how big a tab should look?

A consistent look across viewers/editors was the original reason for choosing spaces, but I think the concept is outdated by the new IDEs.

Jaitsu
28 Nov 2008, 1:15 AM
I've never noticed it in my own code either, but then again I may just not be paying attention!

Animal
28 Nov 2008, 2:19 AM
Yeah! I'm no longer the only one that voted for tabs!

For all those who voted for spaces:
Is one of you actually using an editor that doesn't allow specifying how big a tab should look?

A consistent look across viewers/editors was the original reason for choosing spaces, but I think the concept is outdated by the new IDEs.

The problem is not all software or media behave as well as a nice, well behaved, modern IDE.

Firebug doesn't allow specification of how big a tab should be.

This forum doesn't allow specification of how big a tab should be.

This is why a lot of code posted here is unreadable. It flies off the end of the screen, and I have a 26" monitor!

eggspencer
28 Nov 2008, 4:10 AM
The problem is not all software or media behave as well as a nice, well behaved, modern IDE.

Firebug doesn't allow specification of how big a tab should be.

This forum doesn't allow specification of how big a tab should be.

This is why a lot of code posted here is unreadable. It flies off the end of the screen, and I have a 26" monitor!

Agreed. Which is also why I advocate 2 spaces - I just can't see any benefit in using 4, whereas there are clear downsides, especially with deeply nested code or config objects.

Note that the same argument can't be made for using 1 space instead of 2 - when you get down to 1 space for indentation the opportunity for misreading the code is high, but 2 spaces makes it very clear what's going on.

Maybe there are people who really can't see code indented with two spaces, and actually need 4 spaces to even register the indentation? I find that hard to believe, but perhaps there are people here who could shed some light on that.

watrboy00
28 Nov 2008, 10:48 PM
I use dual 24" monitors at home so extra spacing caused by a tab versus a space makes no difference to me.

Additionally in a development team I find it very hard for everyone to follow the same coding standards 100%. Using and configuring the IDE exactly the same for all generally helps but everyone develops their own way so generally there are always going to be differences.

Animal
29 Nov 2008, 2:12 AM
Additionally in a development team I find it very hard for everyone to follow the same coding standards 100%.

Big sticks! ;)

mjlecomte
29 Nov 2008, 4:29 AM
I have three 30" widescreen monitors. >:)

The tab vs. space thing is primarily firebug and forum posting as Animal said. Also sometimes if you're doing diffs some software will pick up on differences for line feeds and tabs vs. spaces (sometimes you can say ignore these though).

I suppose there are people that will always want to do it their own way, but the poll is useful to see how you can best fit in if you choose to. My IDE came with 4 spaces as the default and Ext library is using 4 spaces, so it just seems easier to go with the flow, ya know.

Animal
29 Nov 2008, 4:52 AM
At the end of the day, Jack is the boss for official Ext code, so we'll see if he can wield a big stick at his developers!