Closed Thread Icon

Preserved Topic: Coding Style (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=21243" title="Pages that link to Preserved Topic: Coding Style (Page 1 of 1)" rel="nofollow" >Preserved Topic: Coding Style <span class="small">(Page 1 of 1)</span>\

 
Kriek
Maniac (V) Inmate

From: Florida
Insane since: Jul 2001

posted posted 04-01-2003 16:05

I've been meaning to poll you guys concerning coding style for awhile.
This mainly deals with control structures.

C-Style

code:
<?php
if ($a > $b)
{
print "a is bigger than b";
}
elseif ($a == $b)
{
print "a is equal to b";
}
else
{
print "a is smaller than b";
}
?>



Java-Style (PEAR Coding Standard)

code:
<?php
if ($a > $b) {
print "a is bigger than b";
}
elseif ($a == $b) {
print "a is equal to b";
} else {
print "a is smaller than b";
}
?>



VB-Style (PHP Alternative syntax)

code:
<?php
if ($a > $b): print "a is bigger than b";
elseif ($a == $b): print "a is equal to b";
else: print "a is smaller than b";
endif;
?>



__________________

Kriek says '[SYSTEMWIDE_MESSAGE] PHP Meetup'
What we do is never understood; only praised and blamed

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 04-01-2003 16:23

not a big programmer really (just mess around with it), but I like the Java Style the best.
Easier for me to read and not so long and cluttered. More logical

Later,

C:\


~Binary is best~

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-01-2003 16:24

drawback of java style: You have to actually count the braces. Ok, any decent editor does this for you. still easier when you can just view where they line up. I prefer the c style. Also helps when you got 'bad' developers on your team that have lot's of nested levels and long methods...

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 04-01-2003 16:51

I started out using c-style but ended up being more comfortable with the java style, and although the VB-style is more economical I think it makes the code very hard to read.

Just my 2 anyway.

-Butcher-

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 04-01-2003 17:05

I always go 'c-style'

I like seeing my brackets in line the whole way down the page =)



Kriek
Maniac (V) Inmate

From: Florida
Insane since: Jul 2001

posted posted 04-01-2003 20:08

Thanks for your input guys, btw I personally use a program called Beautify PHP which outputs in either C-Style or Java-Style with proper spacing/tabs which I find very handy for large bodies of code.

__________________

Kriek says '[SYSTEMWIDE_MESSAGE] PHP Meetup'
What we do is never understood; only praised and blamed

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-01-2003 20:31

Didn't we have this thread before?

Anyway I've long used the Java (PEAR) style. I haven't had an issue with braces matching, maybe just since I've used it for so long but It's just as easy for me to match if statements with closing braces etc.

I do use the C alternate syntax sometimes (without the colons however ) for small one line if statements:
if ($something) $something = "something else";

While some lanuages allow you to do this with other controls I've never liked a for loop without braces (I know this is okay in C++ but not sure about PHP or C)

my $.02



.:[ Never resist a perfect moment ]:.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-01-2003 20:34

hmm apparently it works in php, still don't like it though



.:[ Never resist a perfect moment ]:.

Suho1004
Maniac (V) Inmate

From: Seoul, Korea
Insane since: Apr 2002

posted posted 04-01-2003 23:49

C style for me. I like my code to be both effective and aesthetically pleasing. I seek balance and harmony in all things.

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 04-02-2003 01:25

Definatley a C style coder. I don't have any problems with braces matching becuase I've gotten into the habit of whenever I open a bracket or open a brace I immediatley close it again. Saves counting the braces. I always know they're closed.

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 04-02-2003 02:22

This is relevant.

I personally use what the Jargon File calls Allman Style. With Homesite, I ease the container-matching by automatically inserting a }, ), or ] beyond my insertion point whenever I type a {, (, or [.

This means that if I type {

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 04-02-2003 09:48

I prefer the Java-style (called K&R in the Jargon File). I've never had to count the brackets since I close them as soon as I open them, so I know that every thing is closed.

For 1 line statements I often end up using the vb-style: if ($something) $something = "something else";

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 04-02-2003 15:44

I have to use the "Java-Style" if I don't my mind blows up. I like it as opposed to the C-Style because I don't have a waste line with a bracket ({) in it, and I find the "Java-Style" far more readable, XEmacs also follows "Java-Style" conventions by default, which I don't bother changing.

I don't believe there is a real advantage / disadvantage in any method other than that PHP one you mention, which makes the code completely unreadable.

I also stopped using the if(true) false; type statement as

if(true){
false;
}

allows you to easily expand on blocks of code at a moments notice, making it nice so you don't lose your train of thought while you step out of mode to modify syntax.


Me

« BackwardsOnwards »

Show Forum Drop Down Menu