in reply to Grokking Compile Error Messages

so I went looking for missing }s and )s, as this is one of my frequent failings

My way of solving this is to write out:

if( condition ) { }

And then go back and fill in the block. I almost never miss a curly. I tend to be lazier about doing the same with parens, since those are usually much shorter (and likewise tend to get bitten by unbalnced parens more often).

----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Replies are listed 'Best First'.
Re^2: Grokking Compile Error Messages
by QM (Parson) on Jul 21, 2004 at 17:24 UTC
    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

      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

      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.