• (nodebb)

    It's surprising how often developers actually reinvent the wheel; in the worst way possible.

  • (nodebb)

    Isn't appending to a file literally the second lesson ever in computer science class in high school?

  • LZ79LRU (unregistered) in reply to MaxiTB

    Watch what you're calling worse. I'll have you know my four sided right angled wheel offers superior stability when parked on inclines. And the broad flat surfaces give it much better ground pressure as well. And it can't slip in mud either.

    About the only down side is that you can't turn it. But who wants to deal with rotation anyway?

  • my name (unregistered) in reply to LZ79LRU

    Ever seen Carry On Cleo?

  • (nodebb)

    Do we really need to pick on PHP? It seems kind of gratuitous.

  • Conradus (unregistered) in reply to my name

    "Infamy! Infamy! They've all got it infamy!"

  • Prime Mover (unregistered) in reply to LZ79LRU

    Square? Mine are triangular. Less corners so less bumpy.

  • Meir (unregistered) in reply to LZ79LRU

    Sure you can turn it - you just need an appropriately shaped surface. Look at Wikipedia under “square wheel.”

  • Foo AKA Fooo (unregistered) in reply to LZ79LRU

    I'll raise you my three-sided wheel. 25% fewer bumps!

  • (nodebb)

    Early in my career I managed to bring a bank's (14th largest in the nation) nightly processing to a halt for a few hours with a similar piece of bad code. Branch openings were delayed by 3 hours(really bad). The systems guys tried to crucify me and have me fired, but ultimately it way deemed their error for not putting in guard rails to kill a process cascading out of control. Lesson learned.

  • (nodebb) in reply to konnichimade

    Ultimately, this kind of thing could be written in almost any programming language that has strings constructed by dynamic allocation, like, for example, C++ or Java or Python or whatever.

    And it may well be worse than the article implies, since there are, in fact, four concatenations that involve a copy of the whole existing contents, unless PHP's string concatenator is right-associative. (i.e. unless a . b . c is equivalent to a . (b . c) as opposed to (a . b) .c)

  • Argle (unregistered) in reply to konnichimade

    konnichimade , we need to keep kicking it until it's dead. It'll take a while, but we need to. My daughter had a good idea for a website and I put together for her. She turned to a friend of hers to market the idea (I'm not much good at that) and we had some discussions of support websites. Her friend wanted to put it all together with WordPress. "What's wrong with WordPress and PHP? It's easy and fun! I've made web pages with it myself!" I about wanted to slap him. I'm the guy who's had to come in behind and clean up the messes after people who thought a toy could be used for serious business. I have to remind people that PHP actually stands for "Personal Home Page." It was a toy for a guy and his friends and it got out of hand.

  • (nodebb) in reply to konnichimade

    Seems to me it is not PHP that is being picked on. Other languages have similar APIs to read a whole file into memory at once. This could have been a WTF in any one of a number of languages.

  • Leroy (unregistered) in reply to Argle

    You want to kill the language because people can write crap in it? Time to kill all programming languages then.

  • (author) in reply to Leroy

    I am in favor of this. Every programming language is bad, and computers were a mistake.

  • Fordom Greenman (unregistered)
    Comment held for moderation.
  • Barry Margolin (github) in reply to jeremypnet

    Maybe if PHP didn't have the convenient file_get_contents and file_put_contents functions, so you have to do your own open/read/close, the programmer wouldn't have been lured into writing it this way.

    But it feels wrong to blame PHP for this, when those functions are especially nice in other contexts. Not to mention that they could have used file_put_contents with the FILE_APPEND flag.

  • dusoft (unregistered) in reply to Barry Margolin

    Right on! FILE_APPEND would do it.

  • Randal L. Schwartz (github)

    PHP is a poorly designed Perl wannabe. I'll just leave it at that, for fear of angering any of my Perl friends. :)

  • Erik (unregistered) in reply to Argle
    Comment held for moderation.
  • (nodebb)

    This is especially egregious because PHP makes it very very easy to append a line to a file, such as for logging. I believe there's even a special call that takes care of all the locking etc. etc.

  • (nodebb) in reply to Mr. TA

    What? No, show me teh codes to make a colourful explosion or write my name in super big letters. Learning how to open files is BORRRRRRING.

  • (nodebb)

    PHP programs do a lot of string concatenation; it's one of the things the implementation goes to a lot of effort to optimise. In this particular case it will recognise that the huge string in $content doesn't need to be kept intact for anything else after having the additional line added, so it will reuse the existing allocation (instead of copying the entire thing).

    Then again, in this particular case, you'd append to the file, of course.

  • (nodebb)

    That code was hilarious. Seriously. Can we all hope it was written as a joke for April Fool's Day?

    It's got to be a joke, right? Right?

  • LZ79LRU (unregistered)

    Hope is the first step on the road to disappointment.

  • (nodebb)

    The worst part of this approach (apart from the ghastly performance) is that this can lose log messages if you're in a multithreaded or multiprocess environment. Properly appending typically won't.

  • Argle (unregistered) in reply to Remy Porter
    Comment held for moderation.
  • Wintermute (unregistered) in reply to Argle
    Comment held for moderation.
  • Oliver Jones (github)

    Hey, with this most excellent aLOGorithm they can (but didn't) put the most recent log entry first in the file, instead of last. No extra cost, but I bet that could be an enterprise-level feature. Gotta bug like that, you gotta buy it a suit.

  • Ytmp4 (unregistered)
    Comment held for moderation.
  • SriOpenteq (unregistered)
    Comment held for moderation.
  • (nodebb)
    Comment held for moderation.

Leave a comment on “A Big Ol' Log”

Log In or post as a guest

Replying to comment #604754:

« Return to Article