[wp-hackers] prefix vs postfix - pros and cons

Haluk Karamete halukkaramete at gmail.com
Wed Feb 22 18:55:42 UTC 2012


when building a framework of library  functions, and you need to make
sure your function and variable/constant names will not get mixed up
by people's custom code, which way would you go? prefix your
functions?, or postfix them?

I'm building a library of php functions ( expected to be around 200
functions or so ) to ease my day to day operations and I need to adopt
a style.
I would like to pick your brains. My library will be called blueprint,
so the prefix/postfix would be either bp_ or _bp. Which one is better?

example leftof functiond, takes a string and returns the leftof what's
passed as substring.

so, ahuold this leftof functions be preifxed as

bp_leftof($string,$substring)

or postfixed as

leftof_bp($string,$substring)

it appears to me that the latter is more effective because of two reasons

one is intellisense... the moment you type in "ins" for insert, you
get your dropdown instantly. In the prefix approach, the first 3 chars
gets me no where.

secondly, when think of an action, you think of it directly, insert a
record, or list records, etc. So, you'd instinctively go for typing
that action such as insert_record,  rather than
something_insert_record.

The only advantage I see in prefixing is that in a functions list (
where your frameworks' functions mixed up with other frameworks), you
can see that your library of functions are all lumped together when
sorted alphabetically. But practically speaking, I don't see much
benefit to that.

When it comes to file naming convetions, I'd go for prefix though. But
it has its own dynamics, in file operations, alphabetical sorting is
practical.

My question is on specifically function and variable names which are
typed/thought a lot.

So,

bp_leftof($string,$substring)

or

leftof_bp($string,$substring)

Thanks


More information about the wp-hackers mailing list