SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help
View Poll Results: Coding Style
C-Style 12 54.55%
Java-Style 10 45.45%
VB-Style 0 0%
Voters: 22. You may not vote on this poll


Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 1st, 2003, 02:51 PM
Kriek Kriek is offline
Integer Doctor
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Florida
Posts: 21 Kriek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Kriek Send a message via AIM to Kriek Send a message via Yahoo to Kriek
Coding Style

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

C-Style

PHP 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)

PHP 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)

PHP 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;
?>

Reply With Quote
  #2  
Old April 2nd, 2003, 12:49 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
C 4 me
__________________
-- Jason

Reply With Quote
  #3  
Old April 2nd, 2003, 04:19 PM
Kriek Kriek is offline
Integer Doctor
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Florida
Posts: 21 Kriek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Kriek Send a message via AIM to Kriek Send a message via Yahoo to Kriek
Just for the record, there are several styles and probably more than I can find information about, but I just listed the two most popular being C-Style and Java-Style along with the disputed VB-Style that has stirred up so much commotion.

Allman-Style Named for Eric Allman, a Berkeley hacker who wrote a lot of the BSD utilities in it (it is sometimes called `BSD style'). Resembles normal indent style in Pascal and Algol. It is the only style other than K&R in widespread use among Java programmers. Basic indent per level shown here is eight spaces, but four (or sometimes three) spaces are generally preferred by C++ and Java programmers.

K&R Style Named after Kernighan & Ritchie, because the examples in K&R are formatted this way. Also called kernel style because the Unix kernel is written in it, and the One True Brace Style (abbrev. 1TBS) by its partisans. In C code, the body is typically indented by eight spaces (or one tab) per level, as shown here. Four spaces are occasionally seen in C, but in C++ and Java four tends to be the rule rather than the exception.

Whitesmiths Style popularized by the examples that came with Whitesmiths C, an early commercial C compiler. Basic indent per level shown here is eight spaces, but four spaces are occasionally seen.

GNU style Used throughout GNU EMACS and the Free Software Foundation code, and just about nowhere else. Indents are always four spaces per level, with { and } halfway between the outer and inner indent levels.

Reply With Quote
  #4  
Old April 3rd, 2003, 09:51 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Mine's a mixture of C & java style.. I just write the code and then go back later and clean it up..

Reply With Quote
  #5  
Old April 6th, 2003, 12:34 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Well, when I first started out... I used the C style... But having coded in Java for the last 2 years, I strictly use the Java style coding...

I find it easier to read, and less messy... Especially with having the { brace on the same line as the IF statement, as opposed to having it underneath.... But that's just a personal preference!

This is a great thread... Kriek, where did you learn about all these different styles? They're quite extensive.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #6  
Old April 10th, 2003, 10:52 AM
saltlakejohn saltlakejohn is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 1 saltlakejohn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I learned to program in the 70's when structure was more rigidly imposed. I picked up PHP more by OSDN examples than from any formal text so I saw many different 'looks.' Personally, I like the braces on a separate line and a default indent of 4 or 5 spaces per level. For me any style is okay if it is consistent and readable.

Methods of applying commentary reduce readability more than the code style itself. Those little comment tags hanging onto the end of a code line are usually too splintered to be meaningful. They're like roadside litter.

Reply With Quote
  #7  
Old April 10th, 2003, 01:26 PM
diablero diablero is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 diablero User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I use C++ style! Teached by a great teacher I had! I still use it depply inspired by Borland's VCL code style!

After I made a couple of 'jobs' in Java I got the felling that that is the best code style (personal opinion)!

I don't use it still! But probably will! One of the major subjects on the diference is not (to me) on the indentation or the controls structures but in one small detail! In C++ code style the class name begins with a capital letter and an instance of an object also begins with a capital letter! This raises a problem with is visible both on VCL and MFC:

//class defenition - there's a need for the T (or C on MFC)
class TCar
{
}

//becuse of the intantiation of the class so it can hava a 'natural' name
TCar Car;

This doesn't happend with Java because class defenition and instationtion is done like:

class Car
{
}

Car car;


regards

Reply With Quote
  #8  
Old April 22nd, 2003, 07:17 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to avit
Java style for me. Just because it's vertically shorter, I guess.

I also like this style, because all the nested lines are beautifully aligned with their braces. It looks easier to read, but I haven't used it myself:

PHP Code:
<?php
foreach ($results as $row)
  {
  
$name $row[0];
  
$age $row[1];
  
$sex $row[2];
  if (
$sex == 'F')
    {
    
$prefix 'Mrs. ';
    }
  else
    {
    
$prefix 'Mr. ';
    }
  echo 
"$prefix $name is $age old.<br/>";
  }
?>


Something like that... Not sure what it's called.

Reply With Quote
  #9  
Old April 22nd, 2003, 11:36 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
ack!,...I hate that style,...

Reply With Quote
  #10  
Old April 23rd, 2003, 03:15 PM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm starting a "Support the ternary campaign!"
PHP Code:
print ($a $b) ? '$a is bigger' '$b is bigger'

Reply With Quote
  #11  
Old April 23rd, 2003, 07:05 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
ack,..thats even worse

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Coding Style


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway