tags:

views:

566

answers:

10

Why are so many people still writing crappy versions of things in standard libraries? Not to go after PHP developers, but guys go read the PHP SPL

+11  A: 

Peer review can help catch that kind of thing. If you have another developer looking at the code, and they continually find implementations of standard library methods, it should fail the review unless there's a good reason for reinventing the wheel.

Elie
You can use the peer reviews to produce checklists of common problems (like this one) and to identify training needs.
MarkJ
Precisely. As part of a normal peer review process, developers will learn to avoid past mistakes, which in this case, would mean they would start looking at the common libraries for reuse.
Elie
+6  A: 

Better search techniques. and Domain Specific Familiarity

How does a developer check for a function they dont know the name of? Or perhaps there isnt an EXACT built in function to do what they want, but something they can use to save a lot of code. You need to be able to find the right terminology for the problem at hand, and from there you know what to search for. This is best achived by reading topics specific to your problem domain. Get away from coding specific resources and spend sometime in the field which you are coding for... wether it be retail, medical, insurance, etc.

Neil N
Who, in this day and age, can't look things up, do a little research on Wikipedia or whatever, discover appropriate terminology, and run a google search? It takes less time than re-inventing the wheel.
Adam Jaskiewicz
The problem is knowing you dont have the proper terminology in the first place.
Neil N
agreed, my first thought when solving a problem is to google for anything else similar; unfortunately, googles not perfect, but i can usually find something if it exists (granted, if i didn't find it i have no idea if it does exists, but, well, yeah, paradox)
zaczap
I usually take not finding a solution as a clue that I'm looking the wrong way, and need to research my problem a bit more. The key point is that it does usually exist, you just aren't looking in the right place.
Adam Jaskiewicz
Adam is correct and there are many examples on StackOverflow. For instance computational geometry. There are questions where someone can't find any algorithms, because he doesn't know that the jargon for his "heatmap" display is a "raster map" or "buffering a polyline" is a "Minkowski sum"
MarkJ
MarkJ, thats just what I was getting at, and if I wasnt lazy, I'd have found examples right here on SO like the one you pointed out.
Neil N
+8  A: 

Young, ambitious programmers like to solve every problem on their own. They don't need no stinkin' libraries. Older, lazy programmers would rather search for existing solutions to the problem at hand.

So my advice: the next time you hire a programmer, choose the old guy who falls asleep in the reception area.

Just kidding, mostly. Peer review and education is the answer.

Boden
I like how you blame the young 'uns and I blame the old 'uns - clearly programmers are a fractious bunch :P
annakata
In my experience annakata is right. Older c++ programmers who have been writing software since before the c++ standard library existed will write everything themselves.
Wim Coenen
+3  A: 

A simple coding style document might help by reminding the devs that there are libraries available (maybe list some preferred) and that they should be familiar with them.

Sometimes, you just have to remind people.

A peer review would help.

royatl
+5  A: 

Summary: Assumption is the mother of all FUBARs

I see this a lot from colleagues who are unfamiliar with the concept of frameworks (god how they complain about "two languages in one"), to wit: old C++ guys suddenly confronted with C# diving in head first to recreate hashtables from scratch...

Clearly a big part of this phenomenon from that angle is not stepping out of old mindsets and habits. If you're in a new environment you need to learn the new rules. The only way to deal with that from the outside looking in is to provide training, whether that's pair-programming for a while or something more formal.

Lack of familiarity with your tools breeds the contempt of others.

annakata
Good point. Are there books out there that specifically address the problem of moving from one language to another? That would be interesting... "here's how you do most of the stuff you were probably doing in language X, in language Y".
Boden
IIRC, there were several "C# for C++ guys" type books published.
Neil N
And others: I've seen/heard of java for JS, JS for java, ruby for java, ruby for php, python for perl, etc, etc.. People need to learn that programming is supposed to be language independent.
annakata
I like the new title, Assumpion is the mother of all FUBAR's, my #2 rule up on my whiteboard here at work for coders to follow says "Dont assume anything". #1 is "If it aint broke dont fix it"
Neil N
@annakata: seems that the purpose of those books you cite is precisely that: weaning monoculture programmers from their habit. Or fleecing idiots out of their money, I don't know :)
Adriano Varoli Piazza
Is there a "C# for Java guys" I wonder?
finnw
+1  A: 

Very hard question to answer. Obviously peer review helps, but also proper documentation. Do your projects have technical specs, where you map out the classes and intefaces to be created?

If so, someone else on the team should review the specs and point out where existing code could be used...

+3  A: 

PHP is well documented if and only if, you know exactly what you're looking for. For example, you'd open Arrays and Array functions sections to see what you can do with arrays. And guess what, there is not even mention of SPL.

vartec
+3  A: 

Two reasons pop to mind quickly. First, the Standard PHP Library isn't WELL known, and suffers from poor documentation. The php.net website is widely considered the language's best asset, but a lot of the newer built in classes (such as the SPL, reflection API, DomDocument, etc.) are little more than a list of methods without a lot of context.

More importantly though, it looks like the full SPL never shipped by default with any version of PHP prior to the (unreleased) 5.3. This is a killer as far as adoption goes. Usually people writing PHP code don't have control over what gets complied into their PHP binary. That's handled by their web-host and/or operations team, and web hosts and/or operations teams have different goals than a developer and aren't going to install every optional extension that comes along. This also means projects like Drupal, Joomla, Wordpress, etc. can't rely on the SPL being installed everywhere, so they don't use it.

Part of the reason PHP "won out" over perl was a single install had everything you ever needed. Optional extensions have never become widely adopted until they became part of the base install.

Alan Storm
At least parts of SPL are in 5.2. I am using Iterators in several places. I know it isn't all available and it isn't remotely clear about what is available and how to use it all.
Zoredache
Excellent point. Before this post I wasn't really aware of the SPL, but I **was** aware Iterators, and didn't consider them part of the SPL.
Alan Storm
Problem with SPL is a lot of PHP installs are still 5.1.x or even 4.4.
jmucchiello
A: 

Agree with training and peer review, but also enforcing unit testing and code documentation should help with the NIH syndrome :)

Si
+3  A: 

You should also encourage research before actually setting out on writing code. I usually approach problems by thinking about a way to do it, then I try to find anything in the standard library or any other libraries that will help me out. I'd say that an hour of research in some cases can be worth days of coding.

If people aren't doing this, it may be a good idea to have someone ask them questions about their general approach to the problem and what library functions/classes they are thinking about using. If they're missing something obvious, suggest it to them.

Jason Baker