• laoreet (unregistered)

    null

  • (cs)

    Poorly reimplementing functions built-into PHP is a long standing tradition. You should see some of the horrors I've come across.

  • poo (unregistered)

    That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?

  • suscipit (unregistered)

    I thought date fails were verboten due to sheer quantity. also, thr1ps 4 thr1d.

  • Hazbert Crandell (unregistered)

    What version of PHP was this originally written in? You say that you have not needed to wear each others' hats for years. was this written in an early PHP version?

    Or are you just an arrogant asshole all the time?

  • grzlbrmft (unregistered) in reply to poo
    poo:
    That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?

    YMMD

  • Gumpy Guss (unregistered)

    I dunno PHP but there's a slight chance they were trying to subvert any date format customization or localization that the date() function might try to do.

    I recall one particularly shaky web server which broke if you changed the system-wide date format to anything other than the default.

  • (cs) in reply to Gumpy Guss
    Gumpy Guss:
    I dunno PHP but there's a slight chance they were trying to subvert any date format customization or localization that the date() function might try to do.

    I recall one particularly shaky web server which broke if you changed the system-wide date format to anything other than the default.

    Er, isn't the entire point of date (and its older sibling strftime) to get the time back in a custom format?

  • Gler (unregistered) in reply to poo
    poo:
    That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?

    This. (Assuming it was sarcasm).

    Just look at PHP's Date/Time functions

    eg:

    date_parse_from_format date_timestamp_get date_interval_create_from_date_string

    The real WTF is never any code written in PHP, it's the language itself.

  • (cs)

    Reimplementing standard library functions is actually pretty sensible. You don't know how well these library functions are implemented. They may have bugs, which you now cannot fix. If you implement your own, you can fix bugs as they arise. Also performance can be another issue. How can you be sure you're getting the maximum performance if you don't have exact control over the code? We actually have a very strict rule around here that forbids anyone from using standard library functions of any kind. It's just too risky.

  • nah (unregistered) in reply to Kermos

    Topcoder?

  • Diogo Baeder (unregistered) in reply to powerlord

    Yes, it is. It's still a TDWTF-worthy story. :-P

  • anonymous coward (unregistered) in reply to Kermos

    You're doubling your workload: building the framework and the business functionality.

    Also begs the question: do you really believe you've got better developers and testing processes than whomever has written your framework of choice?

    For me this is TRWTF

  • Matt (unregistered)

    Kermos is right. Why do you think everything has hardware abstraction layers and VMs lately? It is because you can't depend on other people's increasingly sloppy work. Its quality is fundamentally unknowable. Get yourself a generic base to run on, barely enough to execute code, and write the rest yourself. Short of nuking from orbit, it's the only way to be sure.

  • (cs) in reply to Kermos
    Kermos:
    Reimplementing standard library functions is actually pretty sensible. You don't know how well these library functions are implemented. They may have bugs, which you now cannot fix. If you implement your own, you can fix bugs as they arise. Also performance can be another issue. How can you be sure you're getting the maximum performance if you don't have exact control over the code? We actually have a very strict rule around here that forbids anyone from using standard library functions of any kind. It's just too risky.

    This is a great point. You should see my car. I named it Akatherder after its creator. I wanted to make sure I personally built the engine so I get the optimal mileage and performance.

  • Diogo Baeder (unregistered) in reply to Hazbert Crandell
    Hazbert Crandell:
    What version of PHP was this originally written in? You say that you have not needed to wear each others' hats for years. was this written in an early PHP version?

    Or are you just an arrogant asshole all the time?

    The date() function is available since PHP4, that is, since the year 2000. That's a lot of time.

    And he's not being arrogant. It's the programmer's responsability to keep good code, and to refactor everytime he/she finds bad code, like the one in this post. Since the function is available since 2000, I don't believe no one has ever touched the code in all these 9 years.

  • Chris Chubb (unregistered)

    That code has all of the fingerprints of an old Perl programmer on it. Get a date/time stamp pieces into an array, then reassemble them into the format you need.

  • Diogo Baeder (unregistered) in reply to Gler
    Gler:
    poo:
    That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?

    This. (Assuming it was sarcasm).

    Just look at PHP's Date/Time functions

    eg:

    date_parse_from_format date_timestamp_get date_interval_create_from_date_string

    The real WTF is never any code written in PHP, it's the language itself.

    A language can't be bad because of poorly written functions when good ones are available and solve the problem. It's just a matter of experience with the language, and of good practices. Java has many flaws, too, like inheritance uses at the core libraries when composition would be more adequate, and it's still a helluva language.

  • Ben (unregistered)

    Rule 1 of programming in any language:

    If the functionality is there, USE IT. Don't rewrite the whole language.

  • Indrora (unregistered) in reply to jspenguin

    There have been some horrible cases where its neccesary, like implementing PHP5 functions in PHP4. Eugh...

  • Diogo Baeder (unregistered) in reply to Kermos
    Kermos:
    Reimplementing standard library functions is actually pretty sensible. You don't know how well these library functions are implemented. They may have bugs, which you now cannot fix. If you implement your own, you can fix bugs as they arise. Also performance can be another issue. How can you be sure you're getting the maximum performance if you don't have exact control over the code? We actually have a very strict rule around here that forbids anyone from using standard library functions of any kind. It's just too risky.

    The date() function is pretty old. Are you considering a small company could make something better than a core function heavily tested by thousands of people in many years of development? If yes, then this company would be better if it contributed to the PHP source, because it's open, and because it's a bad practice to replace good core functions with new ones, simply because of code maintenance. Like this post story: the sysadmin had to fix some code, and what did he find? A function broken into tenths of lines of code; So, he had to stop working at real business-logic code to look at the badly written one, thus making the maintenance expensive.

  • Drew (unregistered)

    @Kermos: I disagree with most of your statement and would like to cancel my subscription to your newsletter.

    Captcha: ingenium. Any concrete substance that comes from someone's "ingenious" plot.

  • (cs)

    Wow, there's a str_pad function? Damn, I never knew that.

    My point is, php has so many functions, I don't think anybody knows them all. Or even their syntax, as they're always different. Well, yes, date() is quite common, but still...

  • Ian Tester (unregistered) in reply to Chris Chubb
    Chris Chubb:
    That code has all of the fingerprints of an old Perl programmer on it. Get a date/time stamp pieces into an array, then reassemble them into the format you need.
    Except the second thing the code does is pull data out of an array/object and into global variables for manipulation.

    The programmer clearly knows enough to get his job down properly, but not enough to be efficient. If that sounds like a Perl programmer to you, it's only a noob Perl programmer. Sadly, it's representative of an awful lot of PHP programmers.

  • (cs) in reply to Diogo Baeder
    Diogo Baeder:
    Gler:
    poo:
    That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?

    This. (Assuming it was sarcasm).

    Just look at PHP's Date/Time functions

    eg:

    date_parse_from_format date_timestamp_get date_interval_create_from_date_string

    The real WTF is never any code written in PHP, it's the language itself.

    A language can't be bad because of poorly written functions when good ones are available and solve the problem. It's just a matter of experience with the language, and of good practices. Java has many flaws, too, like inheritance uses at the core libraries when composition would be more adequate, and it's still a helluva language.

    Please be a troll...

  • Diogo Baeder (unregistered) in reply to Ben
    Ben:
    Rule 1 of programming in any language:

    If the functionality is there, USE IT. Don't rewrite the whole language.

    Very well said, Ben. That's one of the basis for maintainable code. If the functionality is badly implemented, then contribute to the source code of the language by optimizing it.

  • Monday (unregistered)

    At least he commented his code...

  • (cs)

    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.

  • nico (unregistered) in reply to mol1111
    mol1111:
    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.

    It still takes less time to go check the documentation then to reinvent the wheel.

  • (cs) in reply to mol1111
    mol1111:
    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.
    So I'm pretty sure you're writing everything without any libraries, frameworks or user defined functions and most of what you write is straightforward assembly?

    When you've got a tool available to do something easily for you, use it. Just writing something that does sort of the same but in the most verbose way ever does not show any knowledge of the framework you're working with. And while that doesn't necessarily make you a bad programmer it does make you an inexperienced one.

  • Death (unregistered)

    I think I can make an estimate how this code came to pass. His current job is your programmers first straight from school or having never worked with php before and the code is years old, dating back to the first things he did with PHP...

    I worked in a similar position a few years back. I wasnt even hired as a developer but thats what I became because I had an idea how to make everyones life easyer by just a bit of coding and a database. I screamed in horror when I had to fix something in my early code a few years later.

  • Carl (unregistered) in reply to Diogo Baeder
    Diogo Baeder:
    Are you considering a small company could make something better than a core function heavily tested by thousands of people in many years of development?
    Oh come on, it is just a date calculation. What could possibly go wrong?
  • Jens Fiederer (unregistered)

    OK, there's probably a gap in the programmer's knowledge of the library (and there MIGHT be many), or maybe that part of the code hasn't been touched for a decade.

    Far too pedestrian for a WTF, and what seems like an overly harsh reaction.

  • (cs) in reply to NMe
    NMe:
    mol1111:
    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.
    So I'm pretty sure you're writing everything without any libraries, frameworks or user defined functions and most of what you write is straightforward assembly?

    When you've got a tool available to do something easily for you, use it. Just writing something that does sort of the same but in the most verbose way ever does not show any knowledge of the framework you're working with. And while that doesn't necessarily make you a bad programmer it does make you an inexperienced one.

    You completely missed my point: I'm just saying that date() function is ugly so I understand that somebody is not using it.

    There is big difference if somebody is not using something because he does not know it exists and if he does not use it because he thinks it's ugly.

  • Frankyboy (unregistered)

    not a bad wtf as modern programming languages have such tons of functions. I'm sure I also do similar stuff in java once in a while simply because I don't know the class that implements the functionality (and sometimes because your programming teacher pushes you to ...;)). what good times there were once, back when I was programming C with only the handful of stdlib-functions to remember and not getting a "wtf" bacause you wrote your own functions ;)

  • (cs) in reply to nico
    nico:
    mol1111:
    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.

    It still takes less time to go check the documentation then to reinvent the wheel.

    In this case: no.

  • EatenByAGrue (unregistered)
    "If this is the work that he does when he wears the programmer hat, I'm going to make sure that I'm always available, so he never can put on the system administrator hat."

    Mission accomplished. Not only did we get a programmer for cheap, but we also have our administrator deciding to take on more responsibility for no extra cost.

    -Michael H's boss

  • Mikuso (unregistered)

    Ahhh, I see.

    Insead of:

    $hour=$now['hours'];
    $minute=$now['minutes'];
    $second=$now['seconds'];
    $month=$now['mon'];
    $day=$now['mday'];
    $year=$now['year'];

    He should have used:

    extract($now);
  • greg (unregistered)

    But still, it makes sense to pad year with zeros. It was ok not do so for last 1k years, and it`ll work properly for only next 8k!

    $year=str_pad($year, 4, "0", STR_PAD_LEFT);
    
  • (cs)

    Does it really need saying? TRWTF is PHP. I could slap Rasmus Lerdorf in the face for days and still not be satisfied. Sigh

  • Bim Job (unregistered) in reply to akatherder
    akatherder:
    Kermos:
    Reimplementing standard library functions is actually pretty sensible. You don't know how well these library functions are implemented. They may have bugs, which you now cannot fix. If you implement your own, you can fix bugs as they arise. Also performance can be another issue. How can you be sure you're getting the maximum performance if you don't have exact control over the code? We actually have a very strict rule around here that forbids anyone from using standard library functions of any kind. It's just too risky.

    This is a great point. You should see my car. I named it Akatherder after its creator. I wanted to make sure I personally built the engine so I get the optimal mileage and performance.

    Well, there's more to building the perfect car than just mechanical ability, you know. Without proper marketing, it'd just sit in the corner of the garage gathering rust.

    Similarly, date() is such a feeble name for a function; it's no wonder he felt the need to implement his own version. I mean, what is it? An XML interface to a relationship site? The invocation of a fruit? It's so hard to google these things, particularly if you're a PHP programmer.

    Now, if it had been called ThisFormatsYearMonthDayAndOtherStuffForTheBenefitOfMoronsLikeYou(), there's no way you'd be tempted to roll your own.

    Similarly, if you had any marketing nous at all, you'd have called your car Pussy Wagon...

  • Ajonos (unregistered)

    These WTFs always annoy me. They're not actually WTFs. Sure, he didn't use some standard library function that would have made his life a little easier. But the code is clean, well commented and works.

    Even if you could consider this sub-par code, it is not a result of bad coding skills. It is simply the result of not being aware of a certain standard library function. With the documentation most standard libraries have nowadays, I too, would find it to be faster 90% of the time just implement a quickie snippet of code like this than digging through documentation for a function that may or may not exist to do my work for me.

  • Bim Job (unregistered) in reply to Kermos
    Kermos:
    Reimplementing standard library functions is actually pretty sensible. You don't know how well these library functions are implemented. They may have bugs, which you now cannot fix. If you implement your own, you can fix bugs as they arise. Also performance can be another issue. How can you be sure you're getting the maximum performance if you don't have exact control over the code? We actually have a very strict rule around here that forbids anyone from using standard library functions of any kind. It's just too risky.
    Funny, but not funny enough. For proper sarcasm, try suggesting that all library functions should be implemented in C and swigged to a PHP interface.

    This of course is pretty damn close to performance heaven. It also offers the extra chewy goodness of portability across scripting languages. Yes! It's cross-platform, in much the same way that Java isn't.

    Obviously this would be a bit of a pain if you actually program in C. I haven't found a SWIG utility that converts C into a C API, but I'm sure I could write one in a day or two.

  • Bim Job (unregistered) in reply to Ajonos
    Ajonos:
    These WTFs always annoy me. They're not actually WTFs. Sure, he didn't use some standard library function that would have made his life a little easier. But the code is clean, well commented and works.

    Even if you could consider this sub-par code, it is not a result of bad coding skills. It is simply the result of not being aware of a certain standard library function. With the documentation most standard libraries have nowadays, I too, would find it to be faster 90% of the time just implement a quickie snippet of code like this than digging through documentation for a function that may or may not exist to do my work for me.

    Faster, and so well tested, of course.

    Is this Happy Fun Ball Day for Trolls, or has Alex signed up to some nefarious job site that filters mindless code hoodlums out on the basis of their IP address?

  • B00nbuster (unregistered)

    As long as this code is in its own function, it's not that bad. A programmer doesn't need to know his standard library inside out all of the time. Everyone writes such things as times. Hardly a WTF if the code is well-structured.

    There have been better WTFs.

  • Emperor Obvious (unregistered) in reply to Diogo Baeder
    Diogo Baeder:
    It's the programmer's responsability to keep good code, and to refactor everytime he/she finds bad code, like the one in this post. Since the function is available since 2000, I don't believe no one has ever touched the code in all these 9 years.

    It's not the programmer's job to refactor bad code. Code that works and is serving its intended purpose should always be left alone.

  • someguy (unregistered)

    I had enough trouble with PHP's date() that I never use it directly anymore. (almost) every date-function has now been put into a 1000+ line generic "date object" which wraps around date(), makes things (mostly timezone-related) sane. Yeah, I could extend the builtin Date object, but PHP's inheritance model and naming conventions make that annoying-to-impossible.

  • foxyshadis (unregistered) in reply to mol1111
    mol1111:
    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.
    I still prefer VB's date formatting than most languages; hate on VB for many the good reasons, but dates made a lot of sense. Instead of increasingly unrelated letters for more obscure needs, you just use as many letters as you want padding for each field. (eg, m/dd/yyyy vs date's G/d/Y)
  • Marvin the Martian (unregistered)

    So the hyper-critical stuff is done by the part-time codemonkey? That's like letting the brain surgery be done by the night nurse, instead of waiting for the morning or calling up the surgeon from his round of golf.

  • Sylver (unregistered) in reply to mol1111
    mol1111:
    I'm going to defend this code. I hate functions which use some form of "microlanguage" like date() function as I don't normally use them that often to remember all quirks of the microlanguage. Present code is clean and straightforward. On the other hand one ugly call to date() will always require you to look into the documentation what the stupid format-specifying-letters mean. So, I'm glad you are sysadmin and not programmer.

    I agree. This code is clean, easy to understand, properly commented, does not present significant performance issues and works... definitely not a WTF.

    Using date() would have been more elegant, and would have saved 10 lines or so. Better, but hardly critical.

    At most, the poster could have left a friendly note for the dev with a link to the date() function (www.php.net/date).

    Posting this to the daily WTF and making derogatory remarks on the competence of a colleague over such a minor issue reflects poorly on the character of the poster.

    Come on. This is the daily WTF. Not the daily "slightly unusual solutions that work and don't affect performance or usage."

Leave a comment on “A First Date”

Log In or post as a guest

Replying to comment #:

« Return to Article