Wich indent style do you use?
category: general [glöplog]
something()
{
code
code
}
- or -
something() {
code
}
?
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?
{
code
code
}
- or -
something() {
code
}
?
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?
first of all, i usually use indents
something() {
code
}
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).
tabs
code
}
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).
tabs
i don't care my lines being more than 80 char.
The first one, with tabs. And yeah, lines >80 chars is no problem at all :-)
I really dislike the other indent style...
I really dislike the other indent style...
But the real question is, what editor do you use? I say emacs!
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] ;
}
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.
Preacher: YOUR EMACS SUCKS! I SAY SUCKS BECAUSE IT SUCKS! BLOAT AND CONSTANTLY SWAPPING SO USE VIM VIM VIM VIM VIM!
INFIDEL!
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.
Most of my coding style is born in reaction of the way the development tools work.
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
two spaces.
First style with tabs here. And I go mad when Gargaj's and my code mix :D
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.
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.
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...
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...
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();
}
}
}
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();
}
}
}
fuck. what the hell is wrong here?
anyway: http://www.demoscene.no/kusma/forum_images/code_style.txt
anyway: http://www.demoscene.no/kusma/forum_images/code_style.txt
Quote:
something()
{
code
code
}
- or -
something() {
code
}
?
The second one, but with proper indents for the code. I just like to see the brackets in the same x-pos.
Quote:
Do you use spaces of tabs?
Spaces. Looks the same everywhere. But I'm not really consistent about it.
Quote:
Do you leave spaces between variable names and operators?
Yes. It just looks better. Especially long formulas.
Quote:
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.
Quote:
Do you leave spaces between function name and bracket?
No. That would be just plain weird.
Quote:
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.
Erm, THE FIRST ONE. (first question) :)
adok: where did you learn that silly style? ive never seen any code in that way
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.
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.
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.
I don't leave spaces, but my editor for code is usually Visual Studio and it inserts the spaces automatically.
and about EMACS:
and about EMACS: