Skip to main content
gamedev.net
🔒 Locked

indentation

Started by ascii Sep 24, 2005 at 5:33 PM 16 replies 1.6k views
Original Post
ascii
ascii
What tool do most of you people use to indent your code? Doing so by hand is a bit tedious, I think.
Sneftel
Sneftel
Any decent code editor will, at the very least, automatically tab new lines to the same level as the previous line. That keeps it from being tedious.
SiCrane
SiCrane
I don't see how anyone could write good code without indenting as they go. Almost every IDE will happily auto indent lines as you write, so how does it get tedious?
doynax
doynax
Using hard tabs helps a bit too. And many editors support indenting whole blocks of code (try selecting a few lines and pressing tab/shift+tab in MSVC for instance).
If that's too hard then there are utilities available to clean up your code automatically. The classic Unix program indent for instance, I assume a google session would turn up a few C++ equivalents.

Code formatting shouldn't take more than a fraction of the development time however, and is something that you can hopefully learn to do subconsciously while thinking about the problem at hand.
Vopisk
Vopisk
Personally, even when planning my programming out on paper I apply my indentation rules to what I'm writing. Then it's just a matter of typing it into the text-editor/IDE and going to town. Considering it takes a mere fraction of a second to reach up and hit a tab, I don't consider it a tedium, considering how many thousands of lines of code itself you may be typing at any given time.

Also, at least with Dev-C++ (which I use), all lines say, within a curly brace are auto-indented unless you reach a new level of scope. What I mean to say is that it auto-indents everything to keep it within scope resolution, making for easy reading and understanding of what is going on where.

Vopisk
hplus0603
hplus0603
Hard tabs are outlawed on most modern projects, because they cause more problems than they solve. Stick with a fixed tab size (2, 3 and 4 seem popular), and expand tabs to spaces as you enter them (most editors can do this).

For indenting sloppily copy/pasted code, I just do v-move-== because I'm a VIM guy, but most editors can similarly re-indent the selected code.
enum Bool { True, False, FileNotFound };
Inmate2993
Inmate2993
I hand indent with spaces, and usually 2 spaces per block.
william bubel
sit
sit
Quote:
Original post by hplus0603
Hard tabs are outlawed on most modern projects, because they cause more problems than they solve. Stick with a fixed tab size (2, 3 and 4 seem popular), and expand tabs to spaces as you enter them (most editors can do this).

For indenting sloppily copy/pasted code, I just do v-move-== because I'm a VIM guy, but most editors can similarly re-indent the selected code.

we have had the tabs versus spaces arument already

we use hard tabs where I work, with a fixed size for everybody [4 spaces]. A decent editor will treat 4 spaces as a hard tab when you delete it... and will convert to the configured tab when you indent/de-indent

[in python you need to pick one method [hard or soft tabs] and size and be consistent through a file, it is only an issue for display... the code compiles and runs fine]
H_o_p_s
H_o_p_s
I use hard tabs, mainly because I like the white space. You can always go back later and replace the hard tabs with 2/3/4 spaces if thats the way the people you are working with want it.
BRING BACK THE BLACK (or at least something darker)
Sneftel
Sneftel
Quote:
Original post by hplus0603
Hard tabs are outlawed on most modern projects, because they cause more problems than they solve.

I agree, to some extent. Hard tabs are a problem on widely distributed open source projects, since everyone uses their own editor and has their own fiercely guarded beliefs in the One True Tabsize. For commercial projects where all the programmers are in the same building and use the same IDE, though, there's very little reason to prefer spaces to tabs.
Zahlman
Zahlman
Quote:
Original post by Sneftel
Quote:
Original post by hplus0603
Hard tabs are outlawed on most modern projects, because they cause more problems than they solve.

I agree, to some extent. Hard tabs are a problem on widely distributed open source projects, since everyone uses their own editor and has their own fiercely guarded beliefs in the One True Tabsize. For commercial projects where all the programmers are in the same building and use the same IDE, though, there's very little reason to prefer spaces to tabs.


OTGH, do you really want to work for a company which mandates your IDE?

Promit
Promit
Quote:
Original post by Zahlman
OTGH, do you really want to work for a company which mandates your IDE?


If you refuse to use the same IDE everybody else is using, you'll probably get fired anyhow. And you deserve to be, because you are just making things hard for everybody else.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Sneftel
Sneftel
Quote:
Original post by Zahlman
OTGH, do you really want to work for a company which mandates your IDE?

It's pretty common for companies to standardize on a single IDE if the build process is integrated with the IDE. Also, if you're smart enough to decide you like a particular IDE better than the one everyone else uses, you're also smart enough to go into the options menu for your IDE and set the appropriate tabsize.
JohnBolton
JohnBolton
Quote:
Original post by Zahlman
OTGH, do you really want to work for a company which mandates your IDE?

On a previous project, we had some people using Visual Studio, some people using Code Warrior, and some people using GCC on Linux and there were a lot of problems.

Finally, we standardized on Visual Studio (for practical reasons) and if anyone wanted to use a different IDE/compiler, they would have to maintain compatibility themselves.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Nypyren
Nypyren
I use the method described by Roboguy. I think it's called scope-only tabbing or something.
Zahlman
Zahlman
Quote:
Original post by Sneftel
Quote:
Original post by Zahlman
OTGH, do you really want to work for a company which mandates your IDE?

It's pretty common for companies to standardize on a single IDE if the build process is integrated with the IDE. Also, if you're smart enough to decide you like a particular IDE better than the one everyone else uses, you're also smart enough to go into the options menu for your IDE and set the appropriate tabsize.


My preferred IDE is 'none'; I use a text editor (and yes, I'm smart enough to set vim's tabsize etc. as needed, but it's not particularly enjoyable - neither is working on someone else's differently-indented code, although there are certainly worse things). I find IDEs are nasty and the idea of a build process being integrated into it even nastier (how would you script it for nightly builds?) Besides which, I think it says something about the corporate culture if the company doesn't want to let programmers use what they're comfortable with (though of course the onus is on the programmer to stay current and to actively seek out what s/he considers better tools).

How about issuing a pretty-printer to the team, and standardizing settings for check-in to SVN, but letting people work on the code as they'd like? Perhaps it could somehow be set up to run automatically as part of the check-in/out procedure - so each programmer automatically receives code indented as they'd like it, and checks it in with standardized formatting (so that there won't be huge diffs for whitespace changes).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.