• (cs) in reply to mol1111
    mol1111:
    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.
    Yes. The former is merely ignorant. The latter is just stupid.

    Note that this does not apply for e.g. Perl, where you can use actual names instead of the line noise, and refuse to use the line noise.

  • Sylver (unregistered) in reply to Marvin the Martian
    Marvin the Martian:
    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.

    No, it's obviously a small shop, they don't have someone on call. What do you expect them to do? Call the guy back from his vacation? Good luck with that. Hire a consultant from a 3 letters firm and a 4 figure hourly rate? Or ask the server guy who knows enough PHP to have a look in the code and see if he can fix it?

    Their policy makes sense, as far as I can see.

  • jay (unregistered) in reply to Jens Fiederer
    Jens Fiederer:
    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.

    Ditto. I'm sure there have been plenty of times that I've rewritten a library function because I didn't know it existed. This case is a little strained as one would think that a date formatting function is so obviously generally useful that you would take the time to check if it isn't already there. But as long as the code is well-written, I wouldn't fault somebody much for that.

  • inhibeo (unregistered)
    Michael H:
    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.

    So, since you think you are a better programmer than he is, you must also be a better sysadmin than he is? Brillant!

  • (cs)

    Ok, we don't see too often code written for people actually working. Did your coworker know about this website? It will be nice to read some sort of justification to this piece of 5h1t.

  • (cs)

    Always suspicious when you see something like this. It would be a good idea to ask the original programmer why they didn't use "date()" - there might be a reason.

  • AshG (unregistered)

    The PHP itself is a WTF. I can see how the programmer was forced to code in it and being disgusted by it.

    So he doesn't know some date formatting function, big deal! It worked for years! Did the sysadmin reveal where the broken functionality was? Most likely not even in the code. Remember, the programmer was absent. Would he leave if something wasn't working? No, he tested his stuff and then left.

    Most likely this was some misconfiguration on the sysadmin's part. I've seen it so many times. I submit my working code, everything works flawlessly (so what if I reimplement a function or two?) Then they fuck it all up by messing with the system and passing the blame on me.

  • YogiBear (unregistered) in reply to anonymous coward
    anonymous coward:
    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

    If you're trying to roll your own phrase for "raises the question" here, you should keep in mind the people who came up with the English language have better developers and testing processes than you.

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

    Thank you.

  • (cs) in reply to YogiBear
    YogiBear:
    anonymous coward:
    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

    If you're trying to roll your own phrase for "raises the question" here, you should keep in mind the people who came up with the English language have better developers and testing processes than you.

    And thank you too. I couldn't've said it better myself.

  • Anonymous Coward (unregistered)

    I'm surprised that more people aren't opposed to the huge volume of global variables that were left around to just print the date.

  • (cs) in reply to YogiBear
    YogiBear:
    anonymous coward:
    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

    If you're trying to roll your own phrase for "raises the question" here, you should keep in mind the people who came up with the English language have better developers and testing processes than you.

    Do you expect people using English to read a dictionary or thesaurus and figure out the right words to use?

  • Fedaykin (unregistered) in reply to Diogo Baeder
    Diogo Baeder:
    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.

    Sorry, this is just plain wrong. It's the programmers job to keep the system working. Now while improving code that present a real problem to correctness, maintainability or other important quality is part of their job, this does not include the blanket statement of "refactor everything you think is not good".

    The best way to limit the introduction of software defects in an existing system is to employ strict change management practices. In simpler terms:

    If it ain't broke, don't fix it (TM).

  • Henry Troup (unregistered) in reply to RHuckster
    RHuckster:
    Do you expect people using English to read a dictionary or thesaurus and figure out the right words to use?

    Do we expect people writing code to use a reference manual to figure out the right functions to use? or do we let them complain that

    String.IndexOf("dd/mm/yyyy")

    dosn't format the date correctly?

  • Scott (unregistered) in reply to mol1111
    You completely missed my point: I'm just saying that date() function is ugly so I understand that somebody is not using it.

    Wow. I could have sworn you were being sarcastic the first time.

  • Mogri (unregistered)

    ITT: 75% troll by volume.

  • Mogri (unregistered)

    Here's the exact same code in a fraction of the lines, for those interested:

       #BUILD STRINGS FOR WEBPAGES
       $now = time(); // make sure we're using the same timestamp for everything
       $htmlserverdate = date('Y-m-d', $now);
       $htmlservertime = date('H:i:s', $now);
       $htmltime = date('H:i', $now);
    

    Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?

  • Typo Terry (unregistered)

    unavaiable. noun.

    1. Unable to transform self into an applicable avian form. Usage: Our programmer was unavaiable, so I had to fly into the meeting and sit in for him.
  • (cs) in reply to Henry Troup
    Henry Troup:
    RHuckster:
    Do you expect people using English to read a dictionary or thesaurus and figure out the right words to use?

    Do we expect people writing code to use a reference manual to figure out the right functions to use? or do we let them complain that

    String.IndexOf("dd/mm/yyyy")

    dosn't format the date correctly?

    Which was exactly my point. I'm sick of people complaining that these kinds of TDWTFs are stupid because nobody is expected to memorize the manual. News flash: People aren't expected to memorize the manual, but they are expected to at least search the documentation for innate functionality, especially if it's something as common as dates or collections or whatever.

    It's one thing if the guy made an implementation of something that's addressed in PEAR, or something that's somewhat obscure, like archiving to a zip format. But, this is a date() function.

    That being said, if I saw this in the code I work with now, I'd likely not make such a huge deal about it like this guy did... it's a curiosity, and I'd most certainly ask the original author about it, but I wouldn't consider it quite TDWTF-worthy. That's reserved for code that seriously makes one blurt it out in the middle of the office uncontrollably, and this just didn't do it for me.

  • Anon.Coward (unregistered) in reply to Gler

    Actually, those functions you mentioned are aliases to methods of (newly introduced) DateTime object, and they're new as well. E.g. date_timestamp_get <=> DateTime::getTimestamp

    Other (older) date/time functions have more-less sane syntax.

    It's just that php's architecture became serious about OO around version 5, and it's still being introduced... Therefore, they made aliases for most object methods, in case some doesn't want to use objects (not really a bright idea if you ask me, but that explains those cryptic function names).

    captcha: luctus. Hope you feel enlightened by now.

  • glenstarchman (unregistered) in reply to Mikuso

    I think that "magic" functions like extract that just pop variables into existence are EVIL. But maybe that's because I once worked with a guy who used them for $_GET and $_POST on URLS with dozens of params. Same guy liked nothing more than to define some global variable three layers deep in includes so one never knew the origin of a variable. Fucking atrocious.

  • Anonymous Coward (unregistered) in reply to jspenguin
    jspenguin:
    Poorly reimplementing functions built-into PHP is a long standing tradition.
    Even in the PHP standard library.
  • (cs) in reply to RHuckster
    RHuckster:
    YogiBear:
    anonymous coward:
    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

    If you're trying to roll your own phrase for "raises the question" here, you should keep in mind the people who came up with the English language have better developers and testing processes than you.

    Do you expect people using English to read a dictionary or thesaurus and figure out the right words to use?

    I expect people using English to know how to use it. If not, then don't use it. :-)

  • Gene Wirchenko (unregistered)

    The code has a race condition. What if in between calls to $now(), the date-time changes?

    Sincerely,

    Gene Wirchenko

  • Mogri (unregistered) in reply to Gene Wirchenko
    Gene Wirchenko:
    The code has a race condition. What if in between calls to $now(), the date-time changes?

    Sincerely,

    Gene Wirchenko

    $now is a variable, not a function. No race condition.

  • nemo (unregistered) in reply to Ian Tester
    Ian Tester:
    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.
    Sadly, this is true. As it's a simple language to do simple things in, it attracts a lot of morons at the low end. That's a shame as despite it's inconsitancies, it's one of the nicer languages for doing large scale web-application development in (assuming you know anything about software engineering, because if not, you're doomed whatever language you opt for).

    Of course when you do, you must remove code like todays WTF whenever you find it. Such code doesn't maintain well over the 2+ year range. I would instruct the programmer involved in the proper use of the date function ("date('Y-m-d H:m:s')") and the search function in the online PHP manual...

    We now return you to your regularly scheduled program of code-monkeys beating their chests and flinging dung at each other.

    (Captcha: appellatio. Sounds like a good time.)

  • Iago (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.
    A very bad Perl programmer, who was totally unaware of the standard POSIX::strftime function, and had no idea that CPAN is full of other libraries that handle every sort of date/time formatting imaginable.

    Sorry, but there is no excuse for reinventing the wheel in any language. Not even languages as poorly designed as PHP -- if you don't even have the brains to figure out that someone has probably had to format dates before you, then you should be flipping burgers, not writing WTFs.

  • Steve P (unregistered)

    There are a lot of defensive comments here supporting the notion that not being aware of all the functions available within a specific language are acceptable, and that - even if you do know that it exists, "date()" and its "printf" format is too obscure anyway.

    Date uses a standard printf structure, which - whilst it does have ties with the history of the C programming language - is all part of the IT lexicon. To admit that you don't know and understand printf (and - from that - how date format strings work) is to admit that you are unaware of the industry for which you work.

    If you admit to being unaware of any such thing, you are unaware of how and why your industry works, where it comes from, and how the whole system hangs together. I would not want anybody in a technical position: programmer, sysadm, DBA - maybe storage and networks would get away with it - who couldn't explain some of the %d %M %%etc stuff, and know where to find the rest of it within 20 keystrokes.

  • Here's a nickel, kid... (unregistered) in reply to Emperor Obvious
    Emperor Obvious:
    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.

    Ditto. IIABDFI.

    A further definition of "bad code"...

    • It fails its function
    • Causes a noticeable bottleneck
    • Is too hard to maintain (and needs to be changed often enough to be a problem...in this wtf, it probably worked fine & would rarely need to be changed, if ever)

    Years ago I broke myself of "fixing" all the bad code I ran across...and stopped working so much overtime.

  • AshG (unregistered)
    "For years, we’ve never needed to put on each other's hats. Recently, however, the programmer was away on vacation and something big happened in one of our PHP applications. I had a good idea of how to fix it, so I dove into the appropriate .php file. And that's when I saw this date formatting code."
    TRWTF is, the storyteller does not share how he fixed this date formatting code and whether this "something big" was resolved by the fix.
  • (cs) in reply to RHuckster
    RHuckster:
    Henry Troup:
    Do we expect people writing code to use a reference manual to figure out the right functions to use? or do we let them complain that
    String.IndexOf("dd/mm/yyyy")
    dosn't format the date correctly?

    Which was exactly my point. I'm sick of people complaining that these kinds of TDWTFs are stupid because nobody is expected to memorize the manual. News flash: People aren't expected to memorize the manual, but they are expected to at least search the documentation for innate functionality, especially if it's something as common as dates or collections or whatever.

    Fully agreed. When I was learning to program, I had one editor window open, two windows for man pages, and one for compiling, testing, and looking up man pages - but mostly looking up man pages.

    Years ago, when I had a brief stint as a PHP programmer, another PHP programmer asked how I managed to learn so much of the language so fast (for example, that funny strftime function). I pointed out that I developed with a couple of browser windows (this was before tabs) open to the PHP docs. He dismissed that as too much effort.

    These days, I use screen(1), so my number of man page sessions is a bit more dynamic.

  • (cs) in reply to Ian Tester
    Ian Tester:
    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.

    Specifically, it's representative of a lot of noob perl programmers who then switched to writing PHP code.

    I've worked with a few. I'm of the opinion that neither language is to blame for those few. Nor, for that matter, is awk, despite the fact that at least two of that set had been awk programmers before they were perl programmers.

  • (cs) in reply to Anonymous Coward
    Anonymous Coward:
    I'm surprised that more people aren't opposed to the huge volume of global variables that were left around to just print the date.

    The part that bothers me about it is the possibility that somewhere in all that mess of code, there's something that depends on those global variables being periodically set to the current time...

  • EmperorOfCanada (unregistered)

    For something like formatting a date I would generally have assumed that a language like PHP would allow you to format the crap out of the date in a single like and thus hunted down the function if I didn't know it.

    But I have written code like the above because I switch between boring C++, QT enhanced C++, Objective-C, PHP, Javascript, Actionscript, and SQL. Oddly enough I don't know all the functions in the above languages. So sometimes I end up stupidly reinventing the wheel. A monolingual language guru would probably laugh at much of my code. "You could have packed those 800 lines into a 40 character recursive regular expression, dumb ass!"

    Also sometimes you roll your own to create some functionality that the base function didn't have and then you remove the cool functionality leaving you with stupid looking code.

    Or you ported code from a language that required you to roll your own and you blindly ported functionality that existed in house.

    So from my own experience I have created variations of the theme underlying the above code many times and didn't feel bad afterward. So I prefer WTFs that involve people writing no excuse code like 1000 slightly varying lines of code when a simple for loop with 3 lines would have worked as well.

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

    Actually, there is one case where I wish we had done this. We have to apply a rather complex fit to some data, and whoever wrote the code originally took advantage of a powerful fitting function in a library to do this. This turned what would have been developing our own complex fitting function into a simple library call.

    This is all good. However, this means we don't have control over the fitting of the data. While I have a general idea how the fitting function works, I don't know the exact algorithm so I don't know how it gets the exact answer it spits out. The library is closed source, so I can't just look and see what it does. The one time we tried to switch to something else the users had a fit when they got a slightly different answer when they reran some of their old data, even after I tried to explain that the difference between a result of 1.65234667 and 1.65234702 is statistically insignificant. They wouldn't let up until we went back, which means that we are now tied to using this library (and the baggage that comes with it) for the foreseeable future. Ugh.

  • (cs)

    I'm going to have to go ahead and state that we don't need a whole new article every time somebody goes and reinvents the wheel. Oh no, somebody wrote something that there was a standard lib function for. How terrible. Yes. Woo. Okay. We've seen it a thousand times already, enough is enough.

  • ysth (unregistered) in reply to Mogri
    Mogri:
    Here's the exact same code in a fraction of the lines, for those interested:
       #BUILD STRINGS FOR WEBPAGES
       $now = time(); // make sure we're using the same timestamp for everything
       $htmlserverdate = date('Y-m-d', $now);
       $htmlservertime = date('H:i:s', $now);
       $htmltime = date('H:i', $now);
    

    Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?

    And you verified that the other 8 variables (9 counting $now, which you have arbitrarily changed) weren't used anywhere?

  • (cs) in reply to ysth
    ysth:
    Mogri:
    Here's the exact same code in a fraction of the lines, for those interested:
       #BUILD STRINGS FOR WEBPAGES
       $now = time(); // make sure we're using the same timestamp for everything
       $htmlserverdate = date('Y-m-d', $now);
       $htmlservertime = date('H:i:s', $now);
       $htmltime = date('H:i', $now);
    

    Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?

    And you verified that the other 8 variables (9 counting $now, which you have arbitrarily changed) weren't used anywhere?

    This is by far the biggest WTF that seemingly nobody else has mentioned. Not only is he re-implementing a standard PHP function, he's making the pretentious assumption that it isn't going to get overwritten later. Reminds me of an old co-worker of mine who always overwrote the superglobals, causing so many annoying bugs...

  • (cs)

    It's easy to spot bad coders. They always complain how the language they write in is not good enough for their needs.

  • JJ (unregistered) in reply to Gumpy Guss

    The PHP date function (or gmdate in times of timezone troubles) allows to specify the string format you want to receive, i.e. date('Y-m-d H:i:s') will return a date value like "2009-12-31 23:45".

  • (cs) in reply to Sir Twist
    Sir Twist:
    mol1111:
    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.
    Yes. The former is merely ignorant. The latter is just stupid.
    QFT.

    Pick the right tool for the right job. You may think what you want of the date function and its format but it is the right tool for the job. It will be faster and shorter than any user defined function and easier to read for a coworker/successor. Not using it "because it is ugly" is a lame excuse that will not get you far with most other programmers.

    ASP 3.0 is ugly too in my opinion. It's ugly, slow, lame and outdated. Yet I've still had to use it to maintain websites. Should I have gone ahead and rewritten it in PHP instead because I found it ugly?

  • (cs) in reply to AshG
    AshG:
    Most likely this was some misconfiguration on the sysadmin's part. I've seen it so many times. I submit my working code, everything works flawlessly (so what if I reimplement a function or two?) Then they fuck it all up by messing with the system and passing the blame on me.
    Finally a decent troll!

    Did you ever stop to realize that built-in framework function usually are independent from system settings. e.g. built-in date functions correctly take into account language and culture for parsing dates. If you roll your own functions you can only claim "Works on my machine!" and that's it.

  • Lee K-T (unregistered) in reply to Kiss me I'm Polish
    Kiss me I'm Polish:
    It's easy to spot bad coders. They always complain how the language they write in is not good enough for their needs.

    That's not true. I never complain!

  • Anonymous (unregistered)

    PHP coder != software developer

  • oliver (unregistered)

    Given http://www.osnews.com/story/19266/WTFs_m , this single excerpt is still one of the left-side WTFs; and it's not what I'd expect to read on TDWTF. Either the author gives a different code piece or it didn't happen.

  • Elvis (unregistered)

    As a WTF, this one is pretty pedestrian. PHP coder does not use standard library function but creates a working date formatter in about ten lines of well commented code

    To make this a real WTF you would probably need to implement XML.....

  • JayC (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'll agree that there are cases where you may not want to use a language's microfeature, especially considering your coworkers' tastes and knowledge. But whining about having to look something up.. God Forbid! You are extremely limiting your skillset if you don't occasionially look things up. Furthermore, there was likely much more time and resources available that framework library module you want to avoid than you have to fix your current issue NOW (and it's much more flexible, to boot!). The only other reason I can think for not using the library would be there's some specific optimization requirements you can't very easily implement (or avoid) with the module. (for instance, to write you own function to avoid JavaScript includes hell)
  • Patrick (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.
    This is called perpetuating ignorance. PHP has the most advanced date formatting/parsing system of any language. The fact is, if you use the date() function you can use the same format string to convert back. You can also allow users to customise their own date/time display. You try doing that from scratch, you're going to end up making a mistake or being unable to do everything the pre-existing functions do, and that's not worth a quick glance at the manual and one line of code.
  • Patrick (unregistered) in reply to Anonymous
    Anonymous:
    PHP coder != software developer
    Google runs on incantations?
  • (cs) in reply to Mogri
    Mogri:
    Here's the exact same code in a fraction of the lines, for those interested:
       #BUILD STRINGS FOR WEBPAGES
       $now = time(); // make sure we're using the same timestamp for everything
       $htmlserverdate = date('Y-m-d', $now);
       $htmlservertime = date('H:i:s', $now);
       $htmltime = date('H:i', $now);
    

    Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?

    Why do so many people here assume that getdate() returns the time on the webserver that executes the code? It might very well return the time on another server or the time in the users local timezone.

    Secondly the original code wasn't affected by the year 2038 problem unlike any php code that uses the time() or date() functions. So instead of fixing the code you just created a new bug.

Leave a comment on “A First Date”

Log In or post as a guest

Replying to comment #:

« Return to Article