x404.co.uk
http://www.x404.co.uk/forum/

How do you indent yours?
http://www.x404.co.uk/forum/viewtopic.php?f=4&t=6439
Page 1 of 3

Author:  Fogmeister [ Sun Feb 21, 2010 5:34 pm ]
Post subject:  How do you indent yours?

A question for any programmers out there.

Every programmer, no matter what the language, uses blocks of some sort. Be they if blocks, for loops, switch, else, try, catch, do, while, repeat, etc...

My question is simply, how do you indent yours?

Personally my indentation method follows the pattern...

Code:
<block name> <conditions>
{
    <stuff goes here>
}


i.e.
Code:
for (int i = 1 ; i <= 5 ; i++)
{
    System.out.println(i);
}


I find it a lot easier that way to recognise where blocks start and finish.

I ask because I have recently started using XCode and the blocking in the templates follows no standard whatsoever.

There is the odd time when it is blocked the same as my above example but the a lot of the time it is done thus...

Code:
<block name> <conditions>{
    <stuff goes here>
}


and when the conditions number into the tens it gets to the point where you can't even see the opening bracket.

So, how do you indent yours?

Author:  Fogmeister [ Sun Feb 21, 2010 5:47 pm ]
Post subject:  Re: How do you indent yours?

LOL, just found out that they all have names :D

http://en.wikipedia.org/wiki/Indent_style

Mine is the Allman style :D

Author:  big_D [ Sun Feb 21, 2010 6:17 pm ]
Post subject:  Re: How do you indent yours?

It is also language dependent. Some languages remcommend different styles.

I prefer the first method, althoug a lot of language recommend the second.

A mixture is also often used

Code:
void functionName()
{
    int a;
    for(a = 1; a <= 30; a++) {
        doSomething();
    }
}

Author:  EddArmitage [ Sun Feb 21, 2010 6:34 pm ]
Post subject:  Re: How do you indent yours?

I prefer the second, but I can't give a justifiable reason why. When there's many parameters I run onto multiple lines, with one aligned parameter per line.

Author:  Fogmeister [ Sun Feb 21, 2010 6:49 pm ]
Post subject:  Re: How do you indent yours?

EddArmitage wrote:
I prefer the second, but I can't give a justifiable reason why. When there's many parameters I run onto multiple lines, with one aligned parameter per line.

That's true, I do that at work but at work we use a non "curly bracket" language.

I would run a query like this...

Code:
for each ordsubline where ordsubline.kco = 1
and ordsubline.kdoctype = "S"
and ordsubline.knote = 123456789
and ordsubline.kmob = 1
and ordsubline.kline = 3
no-lock:

    disp ordsubline.itemcode ordsubline.qty.

end.


Similarly if a function has several params I'll align them on each line with the opening parenthesis of the parameter list.

Author:  EddArmitage [ Sun Feb 21, 2010 6:51 pm ]
Post subject:  Re: How do you indent yours?

Now I always indent blocks, so your example would look more like:

Code:
for each ordsubline where ordsubline.kco = 1
    and ordsubline.kdoctype = "S"
    and ordsubline.knote = 123456789
    and ordsubline.kmob = 1
    and ordsubline.kline = 3
    no-lock:
        disp ordsubline.itemcode ordsubline.qty.
end.


assuming that's legal in the language. And I align parameters with the first parameter.

Author:  Fogmeister [ Sun Feb 21, 2010 6:54 pm ]
Post subject:  Re: How do you indent yours?

EddArmitage wrote:
Now I always indent blocks, so your example would look more like:

Code:
for each ordsubline where ordsubline.kco = 1
    and ordsubline.kdoctype = "S"
    and ordsubline.knote = 123456789
    and ordsubline.kmob = 1
    and ordsubline.kline = 3
    no-lock:
        disp ordsubline.itemcode ordsubline.qty.
end.


assuming that's legal in the language. And I align parameters with the first parameter.

That would make sense also and would be legal.

I suppose it's what you get used to reading.

My first curly bracket language was Java and my lecturer always indented my first way so I find it hard to read code done other ways now.

Author:  phantombudgie [ Sun Feb 21, 2010 7:19 pm ]
Post subject:  Re: How do you indent yours?

I use Python and FORTRAN :shock: :D and indent every successive loop or if statement, pretty much in the Wikipedia link under "Python style" with every sub block indented by one tab. Thankfully there are few brackets to be seen so there's less possibility for complexity in the layout. It's mostly numerical modelling so very little in the way of OOP is required, so I've never had to move on to more recent/fashonable/bracket-obsessed languages :)

My final answer to the question "How do you indent yours?"

"python style" :lol:

Author:  soddit112 [ Sun Feb 21, 2010 9:00 pm ]
Post subject:  Re: How do you indent yours?

im learning C# at the minute, and the book im reading recommends the first method. Makes sense to me, as its clearer where the block starts :)

Author:  Fogmeister [ Sun Feb 21, 2010 9:07 pm ]
Post subject:  Re: How do you indent yours?

Here's a wiki of the language I use.

http://en.wikipedia.org/wiki/OpenEdge

Its called OpenEdge or Progress (depending on which version you are using :P).

Author:  finlay666 [ Mon Feb 22, 2010 3:18 pm ]
Post subject:  Re: How do you indent yours?

soddit112 wrote:
im learning C# at the minute, and the book im reading recommends the first method. Makes sense to me, as its clearer where the block starts :)



In visual studio C#, write code, then Ctrl+k, Ctrl+d

Does all of it for you :D

Author:  HeatherKay [ Mon Feb 22, 2010 3:19 pm ]
Post subject:  Re: How do you indent yours?

OT: Another thread that would fit nicely into a programming forum, don't you think?

Author:  AlunD [ Mon Feb 22, 2010 3:21 pm ]
Post subject:  Re: How do you indent yours?

HeatherKay wrote:
OT: Another thread that would fit nicely into a programming forum, don't you think?

But we don't have one :D

Author:  EddArmitage [ Mon Feb 22, 2010 3:23 pm ]
Post subject:  Re: How do you indent yours?

HeatherKay wrote:
OT: Another thread that would fit nicely into a programming forum, don't you think?

Why aye!

Author:  forquare1 [ Mon Feb 22, 2010 3:29 pm ]
Post subject:  Re: How do you indent yours?

I use this method:
Code:
<block name> <conditions>{
    <stuff goes here>
}


If the bracket drops down a ling I feel the file get's longer and somehow feels more complicated, without adding any readability. Seems to be coined the "One TrueBrace Style".

AlunD wrote:
HeatherKay wrote:
OT: Another thread that would fit nicely into a programming forum, don't you think?

But we don't have one :D


We should have one!

Page 1 of 3 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/