alternatives to making blocks like { } or other ??

Discussion in 'Python' started by Michael Chermside, May 19, 2004.

  1. Tim Williams writes:
    > I have to put my 2 cents in here. I love Python, but the one thing I
    > miss is using {} or something to enclose blocks. I edit in emacs
    > python-mode, and believe in indentation, but sometimes I'll
    > inadvertently change a line of code's indentation and it throws the
    > logic off. I found a bug in one of my programs recently where a line
    > of code should have been outside of an 'if', but wasn't because I hit
    > TAB one too many times. A {} block would've caught that. I know that's
    > just being careless, but I need all the help I can get!


    I don't mind using C-derived languages occasionally, but one thing that
    bothers me is having to use {} or something to enclose blocks. I use
    various editors, and I believe in both delimiting and indenting, but
    sometimes I'll inadvertently change indentation or move the position of
    a brace and either way it throws the logic off. I created a bug in one of
    my programs recently just by adding logging. It looked like this:

    if (some_complicated_condition)
    log_message("Error has occurred: taking corrective action");
    take_corrective_action();

    When I read through the code it LOOKED like it worked, but of course
    the corrective action was taken even when it wasn't needed. I've also
    seen more complex examples like this:

    if (condition_1) {
    code_1;
    } else if (condition_2)
    if (condition_2_a) {
    code_2_a;
    }
    // nothing to do for 2b
    else {
    code_3;
    }

    But the ones that I hate the MOST are the ones that my unit tests can't
    catch. A typical example looks like this:

    if (condition) {
    code;
    goes;
    here;
    } else {
    more;
    code;
    }

    Notice how that one line ("here;") is indented wrong? Obviously, that
    doesn't meet our coding standards, yet there's no way for the compiler
    to catch it, because the compiler looks only at the braces and ignores
    the indentation! I know that's just being careless, but I need all the
    help I can get! If only there were a better language I could use.

    -- Michael Chermside
     
    Michael Chermside, May 19, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    3
    Views:
    469
    Scott Allen
    Feb 27, 2005
  2. CYBER
    Replies:
    32
    Views:
    729
    Ville Vainio
    May 25, 2004
  3. Michael Chermside
    Replies:
    1
    Views:
    284
    John Roth
    May 19, 2004
  4. matt
    Replies:
    1
    Views:
    295
    George Ogata
    Aug 6, 2004
  5. Steven Taylor
    Replies:
    9
    Views:
    279
    Brian Candler
    Apr 27, 2009
Loading...

Share This Page