Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Tuesday August 08, 2006
08:22 PM

Cargo Cult Advising

[ #30569 ]

I swear, I really do, that I'm really not responsible for what happens the next time someone says "Maybe you're suffering from buffering!" without noticing that the code prints to standard output and includes a newline character.

If you don't understand the problem, please refrain from giving a misleading and unhelpful answer -- you aren't helping the person with the problem and you're spreading misinformation that makes it more difficult to give people the right answers.

It's not difficult to understand. I even wrote Unnecessary Unbuffering to help you understand.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I see some of merlyn's cgi code containing "$| = 1;" but I never understood what it was for.

    At least, that is where I think I saw it...
    • Yep, it's part of the standard header in all of his programs, not just his CGI ones. (If you read more than one of his columns, he copies and pastes that explanation.)

      I think it's an unnecessary pessimization in terms of clarity and performance. Most of the time, buffering isn't a problem. Only change the default when it is.

      • "Most of the time, buffering isn't a problem. Only change the default when it is."

        This seems like an excellent rule of thumb even for a more general context. Maybe I'll leave "use strict; use warnings;" out of my templates and only put them in code while its tests aren't passing.

        (I'm only about 20% serious.)

        • Ah, but my default rule of thumb has an implicit "Assuming the default is good and useful..." preface. I can see now that my buffering rule of thumb is one of the 20% of cases where that clause should be explicit.

      • It's probably partly legacy, partly defensive. In the "old days", if you printed trace messages, you never saw them unless you unbuffered output. And I frequently print trace messages while I'm "debugging" (as I describe in my debugging web apps [stonehenge.com] column).

        Nowadays, I tend to use only "warn" for trace messages, so perhaps I should change my default style for non-CGI things.

        --
        • Randal L. Schwartz
        • Stonehenge
  • If you don't understand the problem, please refrain from giving a misleading and unhelpful answer

    The problem with this advice is that people have to know that the don't understand the problem...

  • Maybe you need to turn off buffering :-)
  • Reading from STDIN flushes STDOUT, whether or not there was a newline. Though I'm told it behaved slightly differently in past versions of ActiveState perl (5.6.something?) on Win32 before it was compiled with USE_PERLIO.