(** This post was inspired by a recent post I read where a reply suggested the indenting of all code.)

I am guilty of this, I'll be honest. I know it is important to indent and indent properly, it is industry standard, and it is simply utilitarian.

I always think: "Well, I'll do that at the very end to all my files when the prog is complete." and I do, but, for instance, when I post here it would be much nicer for everyone to read and analyze including myself.

I had a influencial programming professor (Dept. Chair, actually) who would say:"Indenting? Nah, that's a waste of time-- I don't care if its all pretty. It just matters that it runs." And, of course, all the students listened to him on this matter (as opposed to the ultra-strict professor who graded heavily on indentation).

I wish to learn proper indentation practices and have them become a part of my real-time coding, as I write code, not as an end project before I finalize the build.

What do you think? I would like to hear all opinions on this subject, helpful hints, and suggestions.

Thanks.

had a influencial programming professor (Dept. Chair, actually) who would say:"Indenting? Nah, that's a waste of time-- I don't care if its all pretty. It just matters that it runs."

Tell him he is an idot and has no business trying to teach anything but maybe a basket weaving course and he may not even be qualified to teach that. I would also report him to the head of the department ---- oops! he is the deparment head? Then I would transfer to a different university where they have competent instructors.

Tell him is is an idot and has no business trying to teach anything but maybe a basket weating course.

Ancient Dragon: LOL, yes, true! "basket weaving":lol:

I knew what you meant-- I earned the basket weaving merit badge in Boy Scouts back in the day! :o :lol:


I am guilty of this, I'll be honest. I know it is important to indent and indent properly, it is industry standard, and it is simply utilitarian.

...

I wish to learn proper indentation practices and have them become a part of my real-time coding, as I write code, not as an end project before I finalize the build.

What do you think? I would like to hear all opinions on this subject, helpful hints, and suggestions.

Thanks.

There are a number of indent styles/conventions around. Most are listed on this wikipedia page. I myself use Banner style, simply because that is what was the first I came across.

For most languages, it doesn't matter at all which style you choose to use. In Haskall, Occam and Python however the indentation is actually part of the programming syntax. And then there is Whitespace, in which the whole program is written in patterns of indentation.

Indentation (and whitespace in general) is important for anyone who ends up reading the code. That includes the person who wrote it.
The readability of properly indented code is very much greater than unformatted code.

I just let the editor do the auto-indenting for me!
At least my code LOOKS like i know what I'm doing...

I think i would go crazy trying to line all that stuff up manually.

Especially the curly braces-ARRRRGH!!!! :eek:

Is that some sort of college torture/discipline thing that they won't let you use a code editor or IDE?

I have been guilty of the same crime. One time I said that I would format the indentation later and then forgot and accidentally turned it in. My teacher was really picky about indentation and using spaces instead of tabs. My suggestion would be to use an editor that fixes it for you (like Visual C# Express.) Its easy to have proper indentation once you get used to looking at code that is properly formatted. If I had to go back and look at my code that I used to do I would probably have a hard time reading it.


(** This post was inspired by a recent post I read where a reply suggested the indenting of all code.)

I am guilty of this, I'll be honest. I know it is important to indent and indent properly, it is industry standard, and it is simply utilitarian.

I always think: "Well, I'll do that at the very end to all my files when the prog is complete." and I do, but, for instance, when I post here it would be much nicer for everyone to read and analyze including myself.

I had a influencial programming professor (Dept. Chair, actually) who would say:"Indenting? Nah, that's a waste of time-- I don't care if its all pretty. It just matters that it runs." And, of course, all the students listened to him on this matter (as opposed to the ultra-strict professor who graded heavily on indentation).

I wish to learn proper indentation practices and have them become a part of my real-time coding, as I write code, not as an end project before I finalize the build.

What do you think? I would like to hear all opinions on this subject, helpful hints, and suggestions.

Thanks.

I am guilty of this, I'll be honest. I know it is important to indent and indent properly, it is industry standard, and it is simply utilitarian.

Well sharky_machine you're correct upto a point. Industry standard however depends on the industry and company you work for. "Good" indencing is not if you place brackets before, at the end, or after something. It depends on how consistent your indencing is!! I could easily write

void myFunction(){
}

void MYFUNCTION(){
}

void MyFunction
{
}

and you will agree they will probably be doing the same thing, its just how consistent you are with your indencing but also naming as well. If you're consistent, you're right.. How right you are depends on how other people write their consistent code ;-)

Comments
Good advice

I am guilty of this, I'll be honest. I know it is important to indent and indent properly, it is industry standard, and it is simply utilitarian.

Well sharky_machine you're correct upto a point. Industry standard however depends on the industry and company you work for. "Good" indencing is not if you place brackets before, at the end, or after something. It depends on how consistent your indencing is!! I could easily write

void myFunction(){
}

void MYFUNCTION(){
}

void MyFunction
{
}

and you will agree they will probably be doing the same thing, its just how consistent you are with your indencing but also naming as well. If you're consistent, you're right.. How right you are depends on how other people write their consistent code ;-)

Yes, well said. Agreed

>>Now I would really like to know who writes functions that way !!!

Placement of the opening curly bracket on the same line as the function definition or the loop control is a standard style. I believe it is used in such notable references as K&R and from past discussions is the favored style of some well respected members of this board.

Use of all caps for function names is a bit extreme, IMHO, but not an illogical approach.

(And if you are refering tongue in cheek to functions that do nothing, well, they can be fun to toss into the mix once in a while for a sense of levity.)

Personally I capitalize the entire name of constant variables but not function names and I find it easier to match curly brackets when each curly bracket is on it's own line, but then indentation and naming styles is very subjective.

Most people agree that indenting is better than not indenting, but how to indent leads to expression of opinions that almost borders on a religious fervor at times.

My advice is follow your own style if you are writing for yourself, and follow the style of the people you work for if you aren't writing for yourself.

>>Now I would really like to know who writes functions that way !!!

Placement of the opening curly bracket on the same line as the function definition or the loop control is a standard style. I believe it is used in such notable references as K&R and from past discussions is the favored style of some well respected members of this board.

I wasnt referring to brace placements.

Use of all caps for function names is a bit extreme, IMHO, but not an illogical approach.

Can you quote any logical situation where all caps are used for function names. All caps are a standard ( almost universal std ) for constants and #defines . A function writtein in all caps will confuse each and everyone who sees it, thinking that it is either a macro or constant.

>>Can you quote any logical situation where all caps are used for function names

Can't say as I can. But it makes as much sense as capitalizing constants or defines or macros. I wouldn't do it, but as a convention, it would work as long as you are consistent with it.

>>All caps are a standard ( almost universal std ) for constants and #defines . A function writtein in all caps will confuse each and everyone who sees it, thinking that it is either a macro or constant.

Agreed upon conventions are very convenient and can be useful, but in the end they are conventions, not mandates intrinsic to the language. One employer may require one convention and another employer may require another.

Agreed upon conventions are very convenient and can be useful, but in the end they are conventions, not mandates intrinsic to the language. One employer may require one convention and another employer may require another.

I wasnt trying to justify why conventions are important, just trying to prove my previous point.

BTW though conventions are not mandatory, no employer would like to see his employee write variables like:

int CoUnteR ;
string _NaMe__ ;

In the end it depends on the employer whom you are working with, and all employers and companies would like to stick with the standard conventions, so in the end logically it becomes mandatory for you to follow a convention. ;)

Now I would really like to know who writes functions that way !!!:eek:

Thats got Java written all over it.

Thats got Java written all over it.

I think there is a misunderstanding. I was not refering to the indentation but to the fact that the function name was written in all Uppercase letters.

> "Indenting? Nah, that's a waste of time-- I don't care if its all pretty. It just matters that it runs."
That might work in the "write once, read once, run once" code which is the average student assignment, but in industry where code has a much longer lifetime (and many more people working on it), good code layout is a prime consideration.

Plus if you post unidented code
- a lot of people will just ignore you
- some people will just reply saying indent your code
- on some rare occasion, you might get lucky.

This article has been dead for over six months. Start a new discussion instead.