in reply to Re^4: curly braces around a lexical file handle
in thread curly braces around a lexical file handle

Again, print $variable EXPRESSION is not realistic code.

I'm saying the real problem is bad naming conventions. You can't argue against that by altering the name of the variables you used. (I'm assuming your didn't actually use "$variable" as the name of your file handle.) What's your actual code?

Update: Clarified.

Replies are listed 'Best First'.
Re^6: curly braces around a lexical file handle
by moritz (Cardinal) on May 31, 2010 at 17:51 UTC
    I said I believe this is a problem that's caused by bad naming conventions.

    If you need to rely on proper variable names to recognize a construct as what it is (like you seem to imply), then the syntactic distinctions (here: presence or absence of a comma) between the constructs is too small.

    The reason is that when you debug stuff, you can't rely on the fact that code you read is sane or correct.

    What's your actual code?

    One piece that caught my eye in the grep/ack output was print $response, $/;

    Which (when read inaccurately) could either print to a response file handle, or print a response.

    And don't tell to call that variable $response_fh instead if it's a file handle. For foreign code I have no influence on the naming, and I don't like that for my own code. If I want type annotations, I use a statically typed language which actually checks the type.

      The reason is that when you debug stuff, you can't rely on the fact that code you read is sane or correct.

      I don't know why you brought up debugging again. We're discussing code readability. Readable code is code that's aligned with the natural assumptions of the reader. Like you said, you can't rely on those assumptions when debugging, so it's not relevant to this conversation.

      Which (when read inaccurately) could either print to a response file handle, or print a response.

      You'd never see print $response $/; alone. One only writes a line ending to a handle if one just wrote to the handle or if you're about to write to the handle. Out of context, this looks pretty ambiguous, but there's no way I'd get it wrong in context.

      Prints to file handles tend to occur in series and usually right after an open. The pattern is highly visible, and tends be noticed instantly.

      The arguments for mandating curlies sound reasonable, but in practice, even with all the bad code I debug on PerlMonks, I don't believe curlies would ever have helped me. Quite the opposite, they distract me when I do see them because almost noone uses them.

      For foreign code I have no influence on the naming

      You can't add curlies to foreign code either, so that's not relevant.

        I don't know why you brought up debugging again.

        Because I need to read code to debug it. So debugging is an important "use case" of readability.

        Perl 6 - links to (nearly) everything that is Perl 6.