Author |
Message |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
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... i.e. 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... 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?
|
Sun Feb 21, 2010 5:34 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
LOL, just found out that they all have names http://en.wikipedia.org/wiki/Indent_styleMine is the Allman style 
|
Sun Feb 21, 2010 5:47 pm |
|
 |
big_D
What's a life?
Joined: Thu Apr 23, 2009 8:25 pm Posts: 10691 Location: Bramsche
|
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
_________________ "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 |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
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.
|
Sun Feb 21, 2010 6:34 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
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... Similarly if a function has several params I'll align them on each line with the opening parenthesis of the parameter list.
|
Sun Feb 21, 2010 6:49 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
Now I always indent blocks, so your example would look more like: assuming that's legal in the language. And I align parameters with the first parameter.
|
Sun Feb 21, 2010 6:51 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
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.
|
Sun Feb 21, 2010 6:54 pm |
|
 |
phantombudgie
Doesn't have much of a life
Joined: Wed Aug 19, 2009 1:45 pm Posts: 994
|
I use Python and FORTRAN  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" 
|
Sun Feb 21, 2010 7:19 pm |
|
 |
soddit112
Spends far too much time on here
Joined: Thu Apr 23, 2009 6:12 pm Posts: 2020 Location: Mute City
|
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 |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Here's a wiki of the language I use. http://en.wikipedia.org/wiki/OpenEdgeIts called OpenEdge or Progress (depending on which version you are using  ).
|
Sun Feb 21, 2010 9:07 pm |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
In visual studio C#, write code, then Ctrl+k, Ctrl+d Does all of it for you 
_________________TwitterCharlie 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 |
|
 |
HeatherKay
Moderator
Joined: Thu Apr 23, 2009 6:13 pm Posts: 7262 Location: Here, but not all there.
|
OT: Another thread that would fit nicely into a programming forum, don't you think?
_________________My Flickr | Snaptophobic BloggageHeather 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 |
|
 |
AlunD
Site Admin
Joined: Fri Apr 24, 2009 6:12 am Posts: 7011 Location: Wiltshire
|
But we don't have one 
_________________ <input type="pickmeup" name="coffee" value="espresso" />
|
Mon Feb 22, 2010 3:21 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
|
Mon Feb 22, 2010 3:23 pm |
|
 |
forquare1
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 6:36 pm Posts: 5150 Location: /dev/tty0
|
I use this method: 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". We should have one!
|
Mon Feb 22, 2010 3:29 pm |
|
|