- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
null
Admin
Poorly reimplementing functions built-into PHP is a long standing tradition. You should see some of the horrors I've come across.
Admin
That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?
Admin
I thought date fails were verboten due to sheer quantity. also, thr1ps 4 thr1d.
Admin
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?
Admin
YMMD
Admin
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.
Admin
Admin
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.
Admin
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.
Admin
Topcoder?
Admin
Yes, it is. It's still a TDWTF-worthy story. :-P
Admin
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
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
Rule 1 of programming in any language:
If the functionality is there, USE IT. Don't rewrite the whole language.
Admin
There have been some horrible cases where its neccesary, like implementing PHP5 functions in PHP4. Eugh...
Admin
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.
Admin
@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.
Admin
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...
Admin
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.
Admin
Please be a troll...
Admin
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.
Admin
At least he commented his code...
Admin
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.
Admin
It still takes less time to go check the documentation then to reinvent the wheel.
Admin
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.
Admin
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.
Admin
Admin
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.
Admin
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.
Admin
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 ;)
Admin
In this case: no.
Admin
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
Admin
Ahhh, I see.
Insead of:
He should have used:
Admin
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!
Admin
Does it really need saying? TRWTF is PHP. I could slap Rasmus Lerdorf in the face for days and still not be satisfied. Sigh
Admin
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...
Admin
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.
Admin
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.
Admin
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?
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
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.
Admin
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."