• (cs) in reply to Mogri
    Mogri:
    Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?

    Could be three. date()'s second argument defaults to time() if not explicited.

  • SCB (unregistered) in reply to pyro789x
    pyro789x:
    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.
    So what you're saying is that instead of creating a whole new article every time we need something like this, we should have a standard library article that everyone can refer to?
  • Central Harlem Anonymous (unregistered)

    I agree with other commenters that there may be a reasonable explanation for this. The code may antedate the existence of the standard library functions, for example, or may be faster for common cases. Mathematica has extremely flexible date functions, but when speed matters, I roll my own. Since I know the input format that will be passed to the function, I can leave out the standard function's efforts to figure this out (is "11-01-1999" equal to 'November 1' or 'January 11'?), with the result being code that runs about 10x as quickly.

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

    Wow, just wow... Be thankful he isn't a brain surgeon. No matter what the profession: pilot, doctor, engineer, accountant, lawyer, etc... you are expected to do research and some rereading of directions or instruction to stay good at what you do.

    How one says RTFM requires more effort than coding your own implementation is beyond my comprehension, though.

  • Manny (unregistered)

    Does no one here know about the DateTime class in PHP? Seriously? Its like this entire comment thread is 100% trolls :P

    http://us2.php.net/manual/en/class.datetime.php

  • Bim Job (unregistered) in reply to tgape
    tgape:
    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.

    That's fair enough.

    I blame Perl for being Perl. I blame PHP for being PHP. I blame awk for being awk.

    I don't bother blaming idiots for using </insert language here>. I don't even bother blaming them for being idiots. That's cruel and unusual punishment.

    I just laugh at their puny efforts and fire them.

  • Mogri (unregistered) in reply to Adriano
    Adriano:
    Mogri:
    Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?

    Could be three. date()'s second argument defaults to time() if not explicited.

    And if you can guarantee that they'll all be called in the same second, that's a good idea. But you can't, so it's not.

  • Zenithy (unregistered) in reply to Kermos

    Well after few years of praxis i can proudly say that for reimplementing such a common thing like date format function i surely dont have time..

    But when i was little bit younger i nearly tried reimplement basic ops such as + - * / :)

  • AshG (unregistered) in reply to bjolling
    bjolling:
    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.

    No sir, you are a troll.

    Did you ever stop to realize that nowhere in the article it mentioned that the code in question was the root of all evil? No, the programmer was on vacation for some time, and then something broke. The sysadmin opened the code and found some reimplementation of a library function. Did that reimplemented piece stop working all of a sudden? Did the sysadmin change the code to a library function call, and everything was fixed right that instant?

    Did you ever stop to realize that when I said "I submit the working code" I meant "After all documented processed have been followed, the code has been rolled out to production and has been working there for quite some time"?

  • Ferd n@ (unregistered)

    The crap is that companies who insist on PHP as the progam "language" are sh*t. They don't want to or can't afford the money to pay for anything extensible. The same goes for MySQL.

    So there. Hmph.

    capptcha Syphilis::PHP

  • Ferd n@ (unregistered) in reply to Ferd n@

    double Hmph.

    How much can you "earn" coding in PHP and MySQL?

    Moreover, how many crag replies will PHP/MySQL crappers respond to this? Har-de-har-har. Arses. Name any real companies use PHP. Name any real companies use MySQL. I Double-dare you. None. Because you'll be sticking your tongue on that nice, frosty, pole in the school yard.

  • Ferd n@ (unregistered) in reply to Ferd n@

    And, yes, before you respond, a troll.

    Only because I'm tired of hearing about WTFs that have to do with PHP or MySQL.

    But I bet there will be people who can't resist saying how good PHP and/or MySQL is!!!

  • (cs) in reply to EmperorOfCanada
    EmperorOfCanada:
    But I have written code like the above because I switch between boring C++ (which has strftime), QT enhanced C++ (which has strftime), Objective-C (which has strftime)[/b], PHP (which has strftime), Javascript (http://hacks.bluesmoon.info/strftime/), Actionscript (http://www.java2s.com/Tutorial/C/0460__time.h/strftime.htm), and SQL (which may have DATE_FORMAT, depending on version). Oddly enough I don't know all the functions in the above languages.

    I've used bold to add my comments above, rather than enter and leave quote half a dozen times. (Yeah, I realize that the Javascript strftime library wasn't available for some time after the language was written - but it was fun to point out.)

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

    I've fought attempts to do this every time I did a port with someone else. On at least one of those occasions, the person assisting me was supposedly an expert in the target language, there was a significant effort to do the literal port, and the other guy managed to fail in the effort - he introduced a slight semantic difference. Yet the single builtin routine that performed that function in the target language could handle either what the other guy implemented, or what he tried to implement. He claimed he was doing the literal port because he didn't want to risk introducing any change in behavior...

  • SomeRandomA (unregistered) in reply to Mogri
       $now = time(); // make sure we're using the same timestamp for everything
    

    Mind reader eh? How could you know that getdate() returns current date/time?

    Also seeing people giving date() as answer, we don't know what he did in getdate() so could he have gotten timestamp for date() easily or not.

    This definetly isn't a WTF.

  • (cs) in reply to Mogri
    Mogri:
    And if you can guarantee that they'll all be called in the same second, that's a good idea. But you can't, so it's not.
    If you have a difference significative enough between one call for a date ('dd-mm-yyyy' or your format of choice) and the following for a time in hh:mm:ss, , and then for for a time as 'hh:mm:ss' and another of 'hh:mm', you have way more problems than PHP and date().

    Since in only one of those variables one actually cared about seconds, I'd say I could, and it is.

    Granted, it's three calls to the time function, instead of one in your example, but that's another thing altogether.

  • read the refactoring article on wikipedia (unregistered) in reply to Emperor Obvious

    That statement is completely wrong in every sense of the word "refactor."

    That defeats the entire point of "refactoring" because code that doesn't work is a bug. You don't refactor broken functionality, you fix it. Refactoring code implies that the code works but could be done better.

    If code is written well, is easy to maintain, performs to expectations, then yes, don't refactor it. Just because it "works" doesn't mean it shouldn't be refactored.

  • (cs) in reply to Adriano
    Adriano:
    Mogri:
    And if you can guarantee that they'll all be called in the same second, that's a good idea. But you can't, so it's not.
    If you have a difference significative enough between one call for a date ('dd-mm-yyyy' or your format of choice) and the following for a time in hh:mm:ss, , and then for for a time as 'hh:mm:ss' and another of 'hh:mm', you have way more problems than PHP and date().
    Or the code could just be being run very close to midnight; it happens. Look, it's dead simple. If you want to measure the time and report it out in a few places in different ways, get the timestamp once and use that since then you have consistency. It's not difficult, and every (non-toy) language supports this mode of operation.

    (Of course, if you are doing significant processing between the two formattings then it's even more important, but that's less common with webpage processing than other programming tasks.)

  • (cs) in reply to Patrick
    Patrick:
    PHP has the most advanced date formatting/parsing system of any language.
    No. It merely has the most advanced ignorance of any group of users.
  • Barf4Eva (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.

    See, that is the problem. You have to spend the time to determine whether it truly is working and truly is serving its intended purpose.

    That's why I just decide to spend the time where I'm told to, like a good little boy, assuming the best in the middle of a massacre. "It's all OK. That code was strewn about for good reason." I move on, assume it works, and then assess what is my ASSIGNED task at hand, and remove all assumptions from THAT.

    So many a dev falls in to the pit of despair, numbing one's brain across thousands of lines, only to be spit out of the corporate machine like a little pellet of bric-o-brac.

    Whereas the dev who can maintain focus, will only have to deal with the reality before him... The ASSIGNED ticket. :P

  • zeno (unregistered) in reply to Kermos

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

    You are kidding, right? :|

  • Mark (unregistered)

    I wouldn't criticize this code until I've run it through performance metrics and consulted with the programmer on the intent (or consulted the design docs if any). Maybe two calls to date() are slower... maybe this function contains a work around for some obscure time/date localization issue... maybe it is a debug function accidentally left in...

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

    Yes. I would also expect YogiBear to, as well: http://www.merriam-webster.com/dictionary/beg

    If help's required, you're looking at number two under "beg the question."

  • http://www.happytiffany.com (unregistered)

    A specialized and reliable jewelery manufacturer and wholesaler localed at China. We guarantee our company's Links of London jewelry, links london, links london jewelry, brace...

  • http://www.pretty-tiffany.com (unregistered)

    With high quality, good price, more than 3000 items, Charmtide is a leading suppliers of international luxury items. Located in Shenzhen, China, We are specialized in designing, ma...

  • anonymous (unregistered)

    He should have written:

       #BUILD STRINGS FOR WEBPAGES
       $htmlserverdate=htmlspecialchars($serverdate);
       $htmlservertime=htmlspecialchars($servertime);
       $htmltime=htmlspecialchars($hour . ":" . $minute);

Leave a comment on “A First Date”

Log In or post as a guest

Replying to comment #:

« Return to Article