views:

60

answers:

4

I'm going to be starting a fairly large PHP application this summer, on which I'll be the sole developer (so I don't have any coding conventions to conform to aside from my own).

PHP 5.3 is a decent language IMO, despite the stupid namespace token. But one thing that has always bothered me about it is the standard library and its lack of a naming convention.

So I'm curious, would it be seriously bad practice to wrap some of the most common standard library functions in my own functions/classes to make the names a little better? I suppose it could also add or modify some functionality in some cases, although at the moment I don't have any examples (I figure I will find ways to make them OO or make them work a little differently while I am working).

If you saw a PHP developer do this, would you think "Man, this is one shoddy developer?"

Additionally, I don't know much (or anything) about if/how PHP is optimized, and I know that usually PHP performace doesn't matter. But would doing something like this have a noticeable impact on the performance of my application?

+2  A: 

Simple wrappers wont hit your performance, but this might confuse any future developers on the project. As a PHP programmer you slowly come to expect the weird naming conventions.

If you are adding any functionality its great to have consistent conventions. I have worked with a PHP static class that did wrap the native array functions (and add new ones). It was quite convenient to always have the same argument placements.

leChuck
+5  A: 

You might be the only developer now but will someone else ever pick up this code? If so you really should stick mainly to the standard library names if you're doing nothing more than simply wrapping the call.

I've worked with code where the author has wrapped calls like this and it really does harm the ability to quickly understand the code

If you saw a PHP developer do this, would you think "Man, this is one shoddy developer?"

Well no...but I'd think "Damn...I've got to learn this guys new naming standard which although well-intentioned will take me time"

Dolbz
+3  A: 

I assume you are referring not only to naming conventions, but also to the merry mixture of function (needle, haystack) and function(haystack, needle) parameter orders.

I can totally understand the desire to build sane wrappers around these in self-defense. I still rather wouldn't do it, though, simply because it adds a proprietary layer to your project that will make it harder to understand for others. Everybody knows what array_push does, but MyArrayFunctions::push one may have to look up, or even look into to find out what it does.

I tend to stick with the standards, even though they're admittedly crappy in this case. Plus, with a decent IDE that can look up functions and parameters as you type, the problem is already much reduced.

On the other hand, I can't really see any harm in, say, a static class Array that brings all the push(), pop(), array_this() and array_that() into one standard form. I'd say it's up to you, really.

Pekka
Your wish is PHP commands: http://de3.php.net/manual/en/class.arrayobject.php ;)
Gordon
@Gordon, you keep surprising me with this new > 5 stuff. I really need to take half a day off and just explore what's there. Thanks!
Pekka
@Pekka you're welcome, though it should be noted that ArrayObject does not provide all the regular array methods, but it's a good start.
Gordon
A: 

In my opinion OOP implementations of for example an array are okay, you will wrap them and partially modify functionality, however just renaming functions and shuffling arguments I don't like.

If you really need to do it make sure you comment it with phpdoc so people can see the correct syntax in the autocomplete of their IDE.

Xeross