![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
|
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! |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#3 |
|
Programmer
|
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"; |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
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. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|