![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
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. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 155
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3
![]() |
I use the last, but I don't indent the braces
else
{
// code here
} |
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 155
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#7 |
|
Newbie
|
I started PHP using the first, now I usually use the last.
|
|
|
|
|
|
#8 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#10 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
I prefer the last one as I think it's more readable IMO.
__________________
PFO - My daily dose of technology. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|