Go to bottom

Wich indent style do you use?

category: general [glöplog]

- or -

something() {


Any of you using any other?
Do you use spaces of tabs?

And, if any of you write css code (even being offtopic), how do you do it?
added on the 2006-08-28 08:20:55 by texel texel
first of all, i usually use indents
added on the 2006-08-28 08:32:04 by raymon raymon
something() {

Why? Because the first language with a C-like syntax we had to code at school was Java, and not knowing what kind of code I should write, I just followed the code conventions from Sun. Guess it just kinda stuck after that (bad habits die hard or whatever).

added on the 2006-08-28 08:44:39 by Sverker Sverker
i don't care my lines being more than 80 char.
added on the 2006-08-28 09:09:29 by Zest Zest
The first one, with tabs. And yeah, lines >80 chars is no problem at all :-)

I really dislike the other indent style...
added on the 2006-08-28 09:22:11 by jua jua
But the real question is, what editor do you use? I say emacs!
added on the 2006-08-28 09:25:10 by Preacher Preacher
Code: int function(int a, char b, void *d) { if(a < 10) if(b == 'p') if(((char *)d)[a] != b) return a << ((char *)d)[a+1] ; return a & ((int *)d)[a+1] ; }
added on the 2006-08-28 09:44:00 by rmeht rmeht
I was using the second one. Now am using the 1st style, just because the codebase at work is written this way. Use tabs. Don't care about 80 chars in the line (IIRC we have column markers set up at 110 or so). Code editor: VC+VAssist, XCode, sometimes SciTE or SubEthaEdit.
added on the 2006-08-28 09:59:42 by NeARAZ NeARAZ
added on the 2006-08-28 10:00:57 by waffle waffle
added on the 2006-08-28 10:03:55 by Preacher Preacher
I put the curly braces on the same vertical position because in my text editor I can highlight the matching symbols, so I immediately know if everything is fine just with a simple visual clue.

Most of my coding style is born in reaction of the way the development tools work.
added on the 2006-08-28 10:20:38 by Dbug Dbug
I currently program in Python where the indentation is part of the syntax. Really nice, because all code looks the same and I barely use curly braces anymore.

Code: def something(): code
added on the 2006-08-28 11:19:45 by noname noname
two spaces.
added on the 2006-08-28 11:28:49 by Gargaj Gargaj
First style with tabs here. And I go mad when Gargaj's and my code mix :D
added on the 2006-08-28 11:47:02 by BoyC BoyC
In my own programs, I always use the first indent style as I believe it's more logically consistent. But when I have to contribute to a program started by someone else, I'll try to stick to this person's formatting "rules".

BTW, some other questions:
2. Do you leave spaces between variable names and operators? (i.e. do you write "a + b" or "a+b"?)
3. Do you leave spaces between array name and index? (i.e. "a [0]" or "a[0]")?
4. Do you leave spaces between function name and bracket? (i.e. "f (" or "f(")?
5. Do you leave spaces before ";" at the end of a code-line?

I usually follow 2, 3, 4, while I don't follow 5.
added on the 2006-08-28 11:52:32 by Adok Adok
tabs suck!!! please, somebody make all tabs magically disappear from the world (except the tab key itself, that's useful ofcourse). let's start with gnu make...

to be more ontopic: 1st style, two spaces. in asm, i indent temporary hacks. in python, it's easy to choose :)

to Adok's questions (omg, Adok the coder):
2: sometimes, 3,4,5: never.

but all these do not really matter as i don't really code these days at all :) and when i "code" it's usually maple...
added on the 2006-08-28 12:13:55 by blala blala
I usually adopt the bracket-style from the projects I work on. When I get to choose, I usually go for
Code: void poop() { for (int i = 0; i < 10; ++i) { if (yes) do_shit(); else { dont_do_shit(); } } }
added on the 2006-08-28 12:17:16 by kusma kusma
hmm. something messed that up. let's try again.
Code: void poop() { for (int i = 0; i < 10; ++i) { if (yes) do_shit(); else { dont_do_shit(); } } }
added on the 2006-08-28 12:18:27 by kusma kusma
fuck. what the hell is wrong here?
anyway: http://www.demoscene.no/kusma/forum_images/code_style.txt
added on the 2006-08-28 12:20:06 by kusma kusma


- or -

something() {


The second one, but with proper indents for the code. I just like to see the brackets in the same x-pos.


Do you use spaces of tabs?

Spaces. Looks the same everywhere. But I'm not really consistent about it.


Do you leave spaces between variable names and operators?

Yes. It just looks better. Especially long formulas.


Do you leave spaces between array name and index?

No. That would just leave the impression that the index is somehow a command of its own.


Do you leave spaces between function name and bracket?

No. That would be just plain weird.


Do you leave spaces before ";" at the end of a code-line?

No. That would be just plain weird.

I also tend to structure pieces of code using sane amounts of line breaks. I also tend to comment a lot, because I know that I might not look at a piece of code for 3 years.
added on the 2006-08-28 12:25:16 by tomaes tomaes
Erm, THE FIRST ONE. (first question) :)
added on the 2006-08-28 12:26:13 by tomaes tomaes
adok: where did you learn that silly style? ive never seen any code in that way

added on the 2006-08-28 12:29:10 by the_Ye-Ti the_Ye-Ti
IMHO the TAB key is useful and should be preserved.

On the one hand, the TAB character itself isn't a bad idea IMHO since it permits a more logical structure of the document.

On the other hand, I understand arguments against using TABs in formatted texts very well. Sometimes I have trouble formatting articles for Hugi that contain code with multiple appearances of the TAB character. I'm used to expanding TABs by means of search & replace. (Now don't ask me if that's really necessary; I'll investigate that at home.) As a matter of fact, I have to insert a special tag to mark code since code is preformatted. This <pre> tag must be inserted in the first line of the code. Now it may happen that, if the first line is already indented with a TAB, search & replace will cause a misformatting. As a consequence, I always have to use search & replace before inserting the tags. It's not a big deal, but still, it makes my routine work a bit more complicated.

An editor could also be implemented in such a way that pressing the TAB key would be interpreted as the command to insert a certain number of spaces.

So, the conclusion is:

Don't use the TAB character in texts that are to be formatted (e.g. for Hugi).

However, as pressing the TAB key is a very comfortable way for identing text, it would be a pity to give this up. The solution is simple: Use a text editor that allows you to insert a certain (perhaps even user-defined) number of spaces by pressing the TAB key.
added on the 2006-08-28 12:29:48 by Adok Adok
Yeti: I invented it myself. But I'm not sure if leaving a space before "(" or "[" is really a good idea. That's why I'm asking.
added on the 2006-08-28 12:32:03 by Adok Adok
I don't leave spaces, but my editor for code is usually Visual Studio and it inserts the spaces automatically.

and about EMACS:

BB Image
added on the 2006-08-28 12:33:42 by jua jua


Go to top