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

Chip Bennett chip at chipbennett.net
Wed Feb 22 20:51:26 UTC 2012


I would suggest that using *full slugs* rather than acronyms is better
still: i.e. blueprint_ vs bp_.

And it probably doesn't make a difference, but most things in the WordPress
ecosystem seem to tend to prefix rather than postfix.

Chip

On Wed, Feb 22, 2012 at 2:33 PM, Chris Taylor - stillbreathing.co.uk <
mrwiblog at gmail.com> wrote:

> I assume this is for use within a WordPress system, yes? In which case
> be aware that BuddyPress uses a bp_* convention for many of its
> internal methods. Therefore your *_bp convention would be better.
>
> Chris
>
> On Wed, Feb 22, 2012 at 6:55 PM, Haluk Karamete <halukkaramete at gmail.com>
> wrote:
> > 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
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list