• (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)

    I was going to point out the log only has minute resolution... ...but I guess the site must be so slow they only need minute resolution on logs anyway

  • 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

    And this is why we need proper qualifications for doing anything that is building things within the information infrastructure.

    Architects of physical buildings need to prove that their building design will not fall down. The bricklayers, carpenters and electricians who build those structures have to prove that they are competent to do so.

    So why on Earth can any school-age person fire up a wordpress site that looks legit and asks you to enter your personal details be totally free from any regulation or oversight whatsoever? It's madness.

  • (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

    Remy, Leroy: This sequence of comments is making me chuckle. Yeah, people write crap in any language. Many a time I've looked at something I wrote and had to ask "was I drunk when I wrote this?" (Depending on what and when, that's a "maybe.") But there are languages that either by design or promotion lend themselves to writing bad code. When I found that PHP had three distinct methods for database access, I popped a cork. I see how it evolved... badly. But the promotion or culture of the language can be a big, non-technical part of its badness. In my experience, every language or system billing itself as "anyone can learn this" is actually correct: anyone DOES show up to use it and then we get all the cringeworthy code that makes this site so much "fun."

  • Wintermute (unregistered) in reply to Argle

    PHP hasn't stood for Personal Home Pages in 30 years or more. These days it's PHP Hypertext Preprocessor.

  • 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.

Leave a comment on “A Big Ol' Log”

Log In or post as a guest

Replying to comment #:

« Return to Article