Comment On A First Date

"I don't consider myself to be a programmer," Michael H writes, "but I have written my share of Perl and PHP. It's not that I dislike coding, it's just that I've moved to the sys admin side of things, and it's probably better for everyone that my kind doesn't write code. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: A First Date

2009-09-28 09:04 • by laoreet (unregistered)
null

Re: A First Date

2009-09-28 09:07 • by jspenguin
Poorly reimplementing functions built-into PHP is a long standing tradition. You should see some of the horrors I've come across.

Re: A First Date

2009-09-28 09:11 • by poo (unregistered)
That's a shame. Why isn't he familiar with the extensive, lightweight and incredibly well thought out PHP standard library?

Re: A First Date

2009-09-28 09:11 • by suscipit (unregistered)
I thought date fails were verboten due to sheer quantity. also, thr1ps 4 thr1d.

Re: A First Date

2009-09-28 09:15 • by 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?

Re: A First Date

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


YMMD

Re: A First Date

2009-09-28 09:15 • by 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.

Re: A First Date

2009-09-28 09:22 • by powerlord
286300 in reply to 286298
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?

Re: A First Date

2009-09-28 09:31 • by Gler (unregistered)
286302 in reply to 286294
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.

Re: A First Date

2009-09-28 09:32 • by 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.

Re: A First Date

2009-09-28 09:33 • by nah (unregistered)
286304 in reply to 286303
Topcoder?

Re: A First Date

2009-09-28 09:36 • by Diogo Baeder (unregistered)
286305 in reply to 286300
Yes, it is. It's still a TDWTF-worthy story. :-P

Re: A First Date

2009-09-28 09:41 • by anonymous coward (unregistered)
286306 in reply to 286303
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

Re: A First Date

2009-09-28 09:41 • by 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.

Re: A First Date

2009-09-28 09:42 • by akatherder
286308 in reply to 286303
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.

Re: A First Date

2009-09-28 09:46 • by Diogo Baeder (unregistered)
286309 in reply to 286296
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.

Re: A First Date

2009-09-28 09:49 • by 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.

Re: A First Date

2009-09-28 09:50 • by Diogo Baeder (unregistered)
286311 in reply to 286302
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.

Re: A First Date

2009-09-28 09:53 • by Ben (unregistered)
Rule 1 of programming in any language:

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

Re: A First Date

2009-09-28 09:55 • by Indrora (unregistered)
286313 in reply to 286293
There have been some horrible cases where its neccesary, like implementing PHP5 functions in PHP4. Eugh...

Re: A First Date

2009-09-28 09:59 • by Diogo Baeder (unregistered)
286315 in reply to 286303
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.

Re: A First Date

2009-09-28 09:59 • by 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.

Re: A First Date

2009-09-28 09:59 • by Evo
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...

Re: A First Date

2009-09-28 10:01 • by Ian Tester (unregistered)
286318 in reply to 286310
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.

Re: A First Date

2009-09-28 10:01 • by Evo
286319 in reply to 286311
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...

Re: A First Date

2009-09-28 10:03 • by Diogo Baeder (unregistered)
286320 in reply to 286312
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.

Re: A First Date

2009-09-28 10:04 • by Monday (unregistered)
At least he commented his code...

Re: A First Date

2009-09-28 10:08 • by 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.

Re: A First Date

2009-09-28 10:18 • by nico (unregistered)
286323 in reply to 286322
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.

Re: A First Date

2009-09-28 10:19 • by NMe
286324 in reply to 286322
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.

Re: A First Date

2009-09-28 10:21 • by 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.

Re: A First Date

2009-09-28 10:24 • by Carl (unregistered)
286326 in reply to 286315
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?

Re: A First Date

2009-09-28 10:33 • by 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.

Re: A First Date

2009-09-28 10:35 • by mol1111
286328 in reply to 286324
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.

Re: A First Date

2009-09-28 10:36 • by 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 ;)

Re: A First Date

2009-09-28 10:38 • by mol1111
286330 in reply to 286323
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.

Re: A First Date

2009-09-28 10:42 • by 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

Re: A First Date

2009-09-28 10:46 • by 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);

Re: A First Date

2009-09-28 10:49 • by 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);

Re: A First Date

2009-09-28 10:58 • by cod3_complete
Does it really need saying? TRWTF is PHP. I could slap Rasmus Lerdorf in the face for days and still not be satisfied. *Sigh*

Re: A First Date

2009-09-28 11:08 • by Bim Job (unregistered)
286337 in reply to 286308
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...

Re: A First Date

2009-09-28 11:14 • by 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.

Re: A First Date

2009-09-28 11:17 • by Bim Job (unregistered)
286339 in reply to 286303
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.

Re: A First Date

2009-09-28 11:20 • by Bim Job (unregistered)
286340 in reply to 286338
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?

Re: A First Date

2009-09-28 11:28 • by 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.

Re: A First Date

2009-09-28 11:41 • by Emperor Obvious (unregistered)
286345 in reply to 286309
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.

Re: A First Date

2009-09-28 11:50 • by 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.

Re: A First Date

2009-09-28 11:51 • by foxyshadis (unregistered)
286347 in reply to 286322
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)

Re: A First Date

2009-09-28 11:57 • by 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.

Re: A First Date

2009-09-28 11:57 • by Sylver (unregistered)
286350 in reply to 286322
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."
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment