🔒 Locked
indentation
Advertisement
Original Post
Let your IDE do it for you.
CM
CM
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.
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.
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
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
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.
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.
I hand indent with spaces, and usually 2 spaces per block.
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]
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.
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?
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.
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.
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.
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.
Advertisement