What's Your Coding Style?

Programming, for all ages and all languages.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: What's Your Coding Style?

Post by Owen »

Creature wrote:
NickJohnson wrote: looks pretty much just as clean as this:

Code: Select all

for (i = 0; i < 10; i++) {
}
Agreed. I'm pretty fond of this style myself too. The first one doesn't really bother me but I think the last one is a bit too cramped to read it easily. I also don't know why people like to use Java-style braces:

Code: Select all

if(condition) {
...
}
I've never liked this way of doing things. Especially with the whole tab/space debate (it doesn't matter which one you're using), it is very nice to have a new-line for this kind of statement because this way the braces will be on exactly the same indentation level. This makes it easier to see what ends where.

Code: Select all

if(condition)
{
...
}
is far easier to read IMHO.

The first style is actually K&R style. It only becomes Java style when you do the same after function definitions.

As for why I don't do it: I spot the depth of the code by it's indentation level, rather than that of the surrounding braces, and putting the { on the same line as the condition saves vertical space (Which means I can look at more code at once without it becoming cramped)
User avatar
paolodinhqd
Posts: 5
Joined: Mon Mar 01, 2010 2:29 am

Re: What's Your Coding Style?

Post by paolodinhqd »

my coding style is quite different

constant: MY_CONSTANT

numeric variable: my_numeric_variable
(pointer variable is considered as numeric,
coz it's actually numeric)

structured variable: My_Structured_Variable

class name: my_class_name
(different to most of u guys, my class name is not capitalized)

function name: my_function_name

indent of 2 spaces for levelling
Synon
Member
Member
Posts: 169
Joined: Sun Sep 06, 2009 3:54 am
Location: Brighton, United Kingdom

Re: What's Your Coding Style?

Post by Synon »

Owen wrote:The first style is actually K&R style. It only becomes Java style when you do the same after function definitions.

As for why I don't do it: I spot the depth of the code by it's indentation level, rather than that of the surrounding braces, and putting the { on the same line as the condition saves vertical space (Which means I can look at more code at once without it becoming cramped)
I used to do what you're calling "Java style" (I've never used Java, so I wouldn't know) but I decided K&R/1TBS is more readable. Originally I used ANSI/Allman style, though.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: What's Your Coding Style?

Post by Combuster »

For the record, I'll just go for the ANSI +1

What matters more to me is the presence of comments, documentation, designs and readable names. I have the tendency to just copy over the formatting when working on existing code.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: What's Your Coding Style?

Post by Owen »

Combuster wrote:For the record, I'll just go for the ANSI +1

What matters more to me is the presence of comments, documentation, designs and readable names. I have the tendency to just copy over the formatting when working on existing code.
I agree there. I only reformat code when the original style is unreadable.

I do tend to miss things like spaces before parentheses though; for projects which do that and I haven't noticed, I tend to get the patch tossed back at me till I fix that ;-)
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: What's Your Coding Style?

Post by VolTeK »

when it comes to me, im use to it bein just me readin it, cus im so messy with my work. theres barely ever a space. makes it harder to define the problems.. but it all works out some how in the end
User avatar
AaronMiller
Member
Member
Posts: 81
Joined: Thu Mar 06, 2008 1:26 pm
Location: Roseville, California (USA)
Contact:

Re: What's Your Coding Style?

Post by AaronMiller »

This link explains my style quite well.

http://www.nuclearglory.com/php-bin/for ... forum_id=4
Last edited by AaronMiller on Thu Mar 04, 2010 9:02 pm, edited 1 time in total.
Synon
Member
Member
Posts: 169
Joined: Sun Sep 06, 2009 3:54 am
Location: Brighton, United Kingdom

Re: What's Your Coding Style?

Post by Synon »

That isn't convenient, it's just annoying. I don't mean to be rude, but I don't want to have to scroll through all that text I'm not going to read just to read the posts below. Could you remove it, please? The link is fine.

Thanks.
Post Reply