Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 24th, 2006, 1:51 AM   #1
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
brace/paren matching scheme

the thread on lisp made me think of this, do you prefer:

if(blaah) {
       code here...
}

or:

else if(blahhhh)  {
       code here...  }

or:
else
    {
        code here...
    }

or something else?

personally, i prefer the last in most cases.


[/code]
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Jun 24th, 2006, 1:56 AM   #2
v0id
Hobbyist Programmer
 
Join Date: Apr 2006
Posts: 155
Rep Power: 3 v0id is on a distinguished road
When I just started programming i did use the first method, but now i use the last.
You get a better view of your code, imo.
v0id is offline   Reply With Quote
Old Jun 24th, 2006, 2:01 AM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3 Jimbo is on a distinguished road
I use the last, but I don't indent the braces
else
{
   // code here
}
Jimbo is offline   Reply With Quote
Old Jun 24th, 2006, 2:29 AM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
I use the first. It saves a line. You get more code on the screen at once without a sacrifice of readability. I also omit braces whenever possible, and open/close them on one line when there's a one line method.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Jun 24th, 2006, 2:36 AM   #5
v0id
Hobbyist Programmer
 
Join Date: Apr 2006
Posts: 155
Rep Power: 3 v0id is on a distinguished road
Actually I don't only use the last, It's varying of the situation.
If I'm f.ex. making a class with a constructor there's initalizing a value I also make it on one line.
class myClass 
{
    private:
        std::string myString;
    public:
        myClass(){ myString = "Hey!"; }
        ~myClass(){};
};

Last edited by v0id; Jun 24th, 2006 at 2:48 AM.
v0id is offline   Reply With Quote
Old Jun 24th, 2006, 3:04 AM   #6
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 224
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
2nd one for If statements up to 4 lines or so. Anything longer and I use the first or last. Last is best for readability if you dont mind whitespace.
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote
Old Jun 24th, 2006, 3:50 AM   #7
Tedd
Newbie
 
Tedd's Avatar
 
Join Date: Jun 2006
Location: New York.
Posts: 11
Rep Power: 0 Tedd is on a distinguished road
Send a message via AIM to Tedd
I started PHP using the first, now I usually use the last.
__________________
The Blog

The Webcomic
Tedd is offline   Reply With Quote
Old Jun 24th, 2006, 6:00 AM   #8
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by Dameon
I use the first. It saves a line. You get more code on the screen at once without a sacrifice of readability. I also omit braces whenever possible, and open/close them on one line when there's a one line method.
I disagree, the readability is worse when trying to save a line in my opinion.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jun 24th, 2006, 7:41 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I began with the first and shifted to the last. I don't indent the brace (same as Jimbo). I think the first method sacrifices readability and leads to mismatches. I don't use braces for a one-liner block, but I recommend that novices do so until their facility increases. My idea about stylistic issues such as this can be seen in my sig.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 24th, 2006, 8:01 AM   #10
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
I prefer the last one as I think it's more readable IMO.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC