[wp-hackers] coding standards and practicality of use
Haluk Karamete
halukkaramete at gmail.com
Sat Mar 10 17:27:01 UTC 2012
I am trying to build a new framework that would give me RAD power
easing my day to day operations, the way I like it to be. I'm new to
PHP ( coming from ASP background ) but I'm loving it though it is
tremendously different.
I am thinking that this library I'm working on, day in day out, may
prove useful at the end - not just for me bit also for some other
developers like me. So, i'm trying to do a good job at it, to make it
as professional as I can for a future release for all to enjoy as a
light weight alternative. And that's where the coding standards and
developer feedback come into play.
I expect the original library be around 200 functions. I'm around 50
now ( and I don't mind rewriting or improving them starting all over
). When the 1st version reaches a workable ( and deployable ) level
for me, I think it would be around 200 functions. But in the future,
it may grove even more. The library I'm working on is something that
could be inserted into a wordpress page or any other CMS without any
issues. ( be it drupal / joomla or for that matter any php project
that do not use any other tools ). And if you are using a known
framework, the framework I'm hoping to build will play nicely side by
side.
Out of these 200 functions, some 60 of them would be on string
functionality, another 30 or 40 on validations and another 20 on
sql/database stuff and so on.
I already named all these functions starting with blp_
At this point, they all are defined as functions.
I did not wrap this functionality into a class yet and that's one of
the questions I'm interested in your point of views.
Here, is a stripped down version of an example string function from my
library/framework.
function blp_leftof ( $str, $leftof_what ) {
// this function's job is to return the left portion of what was requested
//for example blp_leftof ( "0123456789", "5" ) would return 6789
}
of course this function could have been written as
blp_leftof ( "8", "0123456789" ) where the needle is before the haystack.
There must be pro's and con's to these 180 degree different approaches...
It looks like mentioning the needle first is a better idea.. my
argument in choosing this approach is most of the time, the needle is
more important in the mind then the haystack itself. That's the point
of interest and that's where the focus is, and therefore, it should be
done and over with as soon as possible. Also, when reading and
interpreting the code, both the mind and eyes will have an easier
processing time when read in that order, it's more English like too,
when you compare the sentence "give me the left of 5 in 0123456789. "
as opposed to talking like "in the 0123456789, give me the left of.5
". Mentioning the needle is just more natural. But again, you may be
introducing a new dimension that I may be missing... and that's one of
the 2 questions I'm trying to get an insight out of this email.
So, would you want such string functions to mention the needle or the
haystack first and if you think $haystack should be mentioned first,
could you tell me why would you prefer it that way?
And in a case where there are two needles ( as in the example right
below), would that standard of your choice still be developer
friendly?
example:
blp_getinbetween ( "5", "8", "0123456789" ) returns 67
as opposed to
blp_getinbetween ( "0123456789" , "5" , "8" ) returns 67
which one reads/thinks/looks better?
My second question is on using classes or not... should all these
200+ functions come as functions or class methods...
Which route would you take and why?
is it better that at the end of the day, when using this framework,
shoud be endup with
blp_leftof
or
blp->leftof ?
So to wrap up, question #1 is
the needle or the haystack first?
and the question #2 is
200 blp_ functions ( out in the open ) or 200 methods wrapped into a
blp object?
Thank you for your time...
P.S,
I could have asked this question in the PHP mailing list but due to
you guys, this list is my fav.
More information about the wp-hackers
mailing list