in reply to Re^2: Coding styles using if/else
in thread Coding styles using if/else

Interesting.

I just make sure the conditional as clear as possible, so I'll have if ( SomeCondition) { .. or unless ( SomeCondition ) { ..; then the blocks follow logically after that.

Under your guideline, my code

if ( SomeCondition ) { $this = 'that'; $foo = 'bar; $quux{'quaz'} = [ $this, $that ]; # More code follows .. } else { $this = 'the other'; }

would be rewritten as

if ( !SomeCondition ) { $this = 'the other'; } else { $this = 'that'; $foo = 'bar; $quux{'quaz'} = [ $this, $that ]; # More code follows .. }

I find that harder to read, because I would need to take the condition, reverse it, and then follow what's going on in the first block. For the second block, I'd have to go back to the original, un-reversed condition.

It's just not the way my brain works. ;)

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^4: Coding styles using if/else
by jdporter (Paladin) on Apr 06, 2007 at 18:27 UTC

    What's all this if/else business?

    ( sub { # false $this = 'the other'; }, sub { # true $this = 'that'; $foo = 'bar; $quux{'quaz'} = [ $this, $that ]; # More code follows .. } )[ SomeCondition ]->();

    :-) :-) :-) :-) :-) :-) :-) :-)

    A word spoken in Mind will reach its own level, in the objective world, by its own weight