in reply to Re: Grokking Compile Error Messages
in thread Grokking Compile Error Messages

My way of solving this is to write out:
if( condition ) { }
Yes, that's helpful. However, I often have more complicated conditions, such as:
if ( ( $flag1 or $flag2 ) and ( length( $string ) )
[Note the missing ')']

and that was the case this time as well.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^3: Grokking Compile Error Messages
by FoxtrotUniform (Prior) on Jul 21, 2004 at 23:36 UTC
    if ( ( $flag1 or $flag2 ) and ( length( $string ) )

    This is where lining up your delimiters makes a lot of sense. Had you lined up the interior parens, giving

    if ( ( $flag1 or $flag2 ) and ( length( $string ) )
    the unbalanced leading paren would be a bit more obvious; in fact,
    if ( ( $flag1 or $flag2 ) and ( length( $string ) )
    might be even better: the if's leading paren isn't "masked" by the and.

    In this case, though, I'd be sorely tempted to break the if's condition out into a small sub with a meaningful name. I think

    if ( &condition( $flag1, $flag2, $string ) )
    is plenty readable, and gives you less punctuation to worry about.

    --
    F o x t r o t U n i f o r m
    Found a typo in this node? /msg me
    % man 3 strfry

Re^3: Grokking Compile Error Messages
by Aristotle (Chancellor) on Jul 27, 2004 at 15:42 UTC

    That can still be helped by better formatting rules. The way I write complex conditionals that would be too long to fit on one line is to treat the parens like curlies and line them up the same way, indenting the content.

    See what your mistake would look like then:

    if( ( $flag1 or $flag2 ) and ( length( $string ) ) { # ... }

    It still isn't perfectly obvious, but it's much easier to see now.

    It also helps to have an editor that will match brackets/parens/curlies for you; go through your delimiters one by one and check that there is a matching one where you expect it.

    Makeshifts last the longest.