Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 24th, 2005, 3:36 PM   #1
G.I.Josh
Programmer
 
G.I.Josh's Avatar
 
Join Date: Aug 2004
Location: Eastern U.S
Posts: 51
Rep Power: 4 G.I.Josh is on a distinguished road
Send a message via AIM to G.I.Josh
1 line if code blocks; easier to read

This sounds a bit odd, but for realy short if code blocks, I actually find it easier to read. For example:

if ($class eq "Warrior") { @stats = (10, 15, 7, 9) }

is a bit easier for me to read then:

if ($class eq "Warrior") {
@stats = (10, 15, 7, 9)
}

Now, on longer if code, I certainly dont' find that the same is true. Anyway, am I the only one that thinks this. I've been finding it especially useful for when I have an if statement that's in an if statement. But I don't want to get in the habbit of doing that if the rest of the world can't read it.
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog!
G.I.Josh is offline   Reply With Quote
Old Jan 24th, 2005, 4:50 PM   #2
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 206
Rep Power: 4 BlazingWolf is on a distinguished road
It's all a just a matter of opinion. I personally like everything nice and spaced out and indent where other people like very little space and few indentions.

In this case that if statment is entirely readable because it's so short obvouisly if it was longer than one line it would need to be space out so the rest of the world could tell what is going.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Jan 24th, 2005, 7:34 PM   #3
Lance
Programmer
 
Lance's Avatar
 
Join Date: Oct 2004
Location: Chicago, IL USA
Posts: 74
Rep Power: 4 Lance is on a distinguished road
Send a message via AIM to Lance
Even better are ones without those unsightly curly brackets:

<statement> if <expression>;

Such as this useful one:

print "foo = $foo\n" if $DEBUG;

So then you can just define $DEBUG as 1 and easily use it to print out debug-only messages. Although, it's all quite surprising it doesn't work like in C:

if (<expression>) <statement>;

I find the C way the easiest, because if you need to add more statements later, simply add curly brackets. But noooo, Larry Wall has to go and make things backwards! Oh well, it's still readable...
__________________
/* LANCE */
C++;  /* this makes C bigger but returns the old value */
char *site = "slackwise.net",
     *home = "lance.slackwise.net",
     *pics = "flickr.com/photos/slackwise";
Lance is offline   Reply With Quote
Old Jan 25th, 2005, 10:14 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,453
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I like spacing and indentation... irregardless of the language or complexity of the line of code.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Nov 6th, 2007, 11:26 PM   #5
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 145
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
Re: 1 line if code blocks; easier to read

Lance: Its probably not a common pet peeve, but i *hate* those if statements, because they hide the condition. If you need to make a change to someone else's code and you're reading it quickly its entirely too easy to miss the condition altogether, which can really screw up your understanding of the code.

... Then again, I suppose readability has never been one of Perl's strong suits, but they've recently put a similar construct into Python, and I hate it too.
ZenMasterJG is offline   Reply With Quote
Old Nov 6th, 2007, 11:30 PM   #6
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 145
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
Re: 1 line if code blocks; easier to read

Huh... Apparently I've just revived a long, long dead thread. How in the world did I get here? I was just on the front page....

Weird.
Sorry, everybody!
ZenMasterJG 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 8:52 AM.

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