How to format/indent your code properly.

Author Topic: How to format/indent your code properly.  (Read 6979 times)

Hello, I'm going to teach you how to properly format your code, using the style i prefer, Allman style (See more styles here http://en.wikipedia.org/wiki/Indent_style).

Rules
•Every bracket should have it's own line.
•Indent after each bracket.

First things first, everything inside of an open bracket, before the closing bracket should be indented (press tab once). Look at the example below.



Now, let's throw a couple more brackets in there by using an if statement.



Finally, if you ever forget how to indent, or need help, just know, indent after each bracket. Here is a little model of how indenting works.




Any questions/concerns just drop a post!
« Last Edit: April 18, 2012, 12:39:17 AM by elm »

I'm going to teach you how to properly format your code, using the style i prefer
Really?

Really?

Its probably the most used around here so yes. Im not going to go through each style obviously, you can if you want.

Why? I can format my code fine. People have different styles.

Why? I can format my code fine. People have different styles.

This isnt for you then obviously?? Its for new scripters..

Why? I can format my code fine. People have different styles.
Then this thread is not for you.
Its for the people who don't indent at all, or do, but make a total mess of it


Anyways I think it's decent, it could use a few additions, such as a short description of why proper formatting is important

Its probably the most used around here so yes. Im not going to go through each style obviously, you can if you want.
Don't say there's a proper way for casual programmers to format code, even if theirs is terribly ugly. Try suggesting the way that they format their code. You'll be surprised how worked up some people get about formatting styles, it's almost as bad as starting a Mac. vs. Windows debate.

Oh good, a thread about this that we can link to

Also, who are you elm?

Code formatting is a matter of taste. Different things work for different people.

a better way to put this would be

"how to format/indent your code in a way most people can probably read easily"

Who is elm?

Anyway, put more emphasis on using tab to indent, not spaces.

Who is elm?
He's made 19 posts, and been registered for around 2 months.
He has more posts in coding help than he has in all other sections combined, and there are only 3 other sections he's actually posted in.
For every around 6 posts he's made, he's made one topic. That's 2.5x more than average.
And this.

In conclusion, I have no flipping idea who this guy is.


alt?
possibly - but that is to find out on other topics, very irrelevant

Yes I noticed him on his second or third post, hadn't had a chance to ask who he was before

Oops right suppose to be in different topik