Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
How do you indent yours? 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
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?

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Feb 21, 2010 5:34 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
LOL, just found out that they all have names :D

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

Mine is the Allman style :D

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Feb 21, 2010 5:47 pm
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:25 pm
Posts: 10691
Location: Bramsche
Reply with quote
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();
    }
}

_________________
"Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari

Executive Producer No Agenda Show 246


Sun Feb 21, 2010 6:17 pm
Profile ICQ
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
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.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Sun Feb 21, 2010 6:34 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
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.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Feb 21, 2010 6:49 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
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.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Sun Feb 21, 2010 6:51 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
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.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Feb 21, 2010 6:54 pm
Profile WWW
Doesn't have much of a life

Joined: Wed Aug 19, 2009 1:45 pm
Posts: 994
Reply with quote
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:


Sun Feb 21, 2010 7:19 pm
Profile
Spends far too much time on here

Joined: Thu Apr 23, 2009 6:12 pm
Posts: 2020
Location: Mute City
Reply with quote
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 :)


Sun Feb 21, 2010 9:00 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
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).

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Sun Feb 21, 2010 9:07 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
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

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Mon Feb 22, 2010 3:18 pm
Profile
Moderator

Joined: Thu Apr 23, 2009 6:13 pm
Posts: 7262
Location: Here, but not all there.
Reply with quote
OT: Another thread that would fit nicely into a programming forum, don't you think?

_________________
My Flickr | Snaptophobic Bloggage
Heather Kay: modelling details that matter.
"Let my windows be open to receive new ideas but let me also be strong enough not to be blown away by them." - Mahatma Gandhi.


Mon Feb 22, 2010 3:19 pm
Profile
Site Admin
User avatar

Joined: Fri Apr 24, 2009 6:12 am
Posts: 7011
Location: Wiltshire
Reply with quote
HeatherKay wrote:
OT: Another thread that would fit nicely into a programming forum, don't you think?

But we don't have one :D

_________________
<input type="pickmeup" name="coffee" value="espresso" />


Mon Feb 22, 2010 3:21 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
HeatherKay wrote:
OT: Another thread that would fit nicely into a programming forum, don't you think?

Why aye!

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Mon Feb 22, 2010 3:23 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
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!


Mon Feb 22, 2010 3:29 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 32 posts ]  Go to page 1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.