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

Haluk Karamete halukkaramete at gmail.com
Wed Feb 22 20:58:35 UTC 2012


Thank you for catching that. I did not know about buddypress's bp_.

but, I was asking in general, not particularly in wp. The library and
the functionality I'm trying to build should work also in drupal,
joomla etc.

In general, what are the advantages of prefixing the function names as
opposed to postfixing them?

Or we can make the question more wordpressy... why did wordpress opt
in for prefix as oppsed to postfix? was it the result of a thinking
process or was it just hey , it don't matter.. wp_ looks good type
thing?

On Wed, Feb 22, 2012 at 12: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