One of the things that I’ve been criticized for (for lack of a better term, I suppose) is that I push object-oriented techniques over procedural programming  in WordPress.

To some degree this is true: I do prefer object-oriented programming, but I don’t think it’s the end-all-be-all of programming paradigms. After all, when building, say, a theme, there’s actually little room for writing object-oriented code.

On top of that, because of the minimum requirements of WordPress, there are a lot of advanced features in PHP that I avoid because I can’t be guaranteed that the end user will have them available on his or her system when they install the plugin.

So, sure, I prefer object-oriented programming, but I certainly don’t aim to make it the utopian programming practice.

That said, there is one aspect of procedural programming that requires some type of convention: private functions.

Private Functions in Procedural Programming

When it comes to writing private functions in procedural programming, it’s really a convulsion of terms because the very nature of procedural programming doesn’t have the idea of function scope; therefore, you can’t really have public or private functions, right?

Helper Functions

Sometimes I also refer to these functions as helpers. You know what I mean: They are functions written to help to run an algorithm on a data, perhaps retrieve some information in a certain format, or make it easier to read (and write) conditional code.

The thing is, they’re really only known by the people working on the codebase – that is, they aren’t, say, covered in any API documentation.

A Tangent on JavaScript

At one point in my career, I was spending a lot of time in JavaScript and I needed some way to indicate what functions were my private helper functions versus those that were meant to be used elsewhere in the codebase.

This is not meant to spark a discussion on creating private functions within the scope of a custom prototype, so I digress on that point.

So to differentiate between the functions that were to be used throughout the code versus those that were not, I’d write something like this:

  • Normal functions: `insertAfter( elemBefore, elemAfter )`
  • Helper functions: `_verifyIsSafe( sEmailAddress )`

Easy, right? Prefix an underscore and go on about it.

Now Back To PHP

With that in mind, that’s how I’ve historically been writing functions intended for internal use or as helpers within PHP so that they are easily identified as such.

That is to say, I prefix the functions that are normally helpers with an underscore to show they are meant for internal use only.

It works well for me, but is it the accepted convention?

Am I Missing Something?

I’ll be the first to admit that procedural programming is not the primary way in which I write code (of course, I think that’s evident ;), so I can’t be certain that the above technique is what’s actually used.

As such, I’m asking you guys if I’m missing something or if there is a more common way that developers indicate what are considered helper functions (and aren’t meant to be made, say, publicly aware)?