- 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
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.
Admin
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.
Admin
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.
Admin
So, since you think you are a better programmer than he is, you must also be a better sysadmin than he is? Brillant!
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
Admin
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.
Admin
Do you expect people using English to read a dictionary or thesaurus and figure out the right words to use?
Admin
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).
Admin
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
dosn't format the date correctly?
Admin
Wow. I could have sworn you were being sarcastic the first time.
Admin
ITT: 75% troll by volume.
Admin
Here's the exact same code in a fraction of the lines, for those interested:
Four lines of code. Is that so much harder to read? Is date() that much worse a function than getdate()?
Admin
unavaiable. noun.
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
I expect people using English to know how to use it. If not, then don't use it. :-)
Admin
The code has a race condition. What if in between calls to $now(), the date-time changes?
Sincerely,
Gene Wirchenko
Admin
$now is a variable, not a function. No race condition.
Admin
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.)
Admin
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.
Admin
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.
Admin
Ditto. IIABDFI.
A further definition of "bad code"...
Years ago I broke myself of "fixing" all the bad code I ran across...and stopped working so much overtime.
Admin
Admin
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.
Admin
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.
Admin
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...
Admin
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.
Admin
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.
Admin
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.
Admin
And you verified that the other 8 variables (9 counting $now, which you have arbitrarily changed) weren't used anywhere?
Admin
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...
Admin
It's easy to spot bad coders. They always complain how the language they write in is not good enough for their needs.
Admin
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".
Admin
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?
Admin
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.
Admin
That's not true. I never complain!
Admin
PHP coder != software developer
Admin
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.
Admin
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.....
Admin
Admin
Admin
Admin
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.