owen

Apparently I’m not the only one with brace issues, but now they’ve come back to bite me.

A while ago I was showing Berta some code I had written. I forget what it was. Anyway, she commented as she had int he past that she didn’t like my style of indentation and brace use. Some will be surprised/enlightened to find out that this is one of the few things that Berta and I ever argue about. Anyway, she was convinced that her way was good, and I liked my way and that was that. Well, in a sudden urge to get myself in line with what seemed like the rest of the world (for no particular reason… ahem), I decided to switch everything over to the way that Berta did it, and now I’m thinking to regret it.

For the record, my original style of coding is called K&R, after book authors Kernighan & Ritchie who publish in this style. It looks like this:

if (test) {
  do_something();
}

Berta’s style is called Allman, and is named for similar reasons. It also looks identical to the code produced by my C++ teacher at WCU:
if (test)
{
  do_something();
}

Now, if you’re not a programmer, you don’t see the difference other than where a brace (not a curly bracket, a brace) is positioned. But the difference in readability in more complex code is profound, I assure you.

Anyhow, I switched over to Allman, and now I find myself writing code in PHP for WordPress. It turns out that there is a published standard for code written in PHP (like there is in many languages, just not the ones with the most controversy) and it is… K&R.

K&R is used throughout the PHP world. It is used by the PEAR authors, whose code is routinely folded into the core of php as libraries. It is used by the WordPress authors. Everybody uses it, even I used to - but now I’m not.

So I’ve written about 50k of code in Allman, and just learned that K&R is the standard. Not to mention that I submitted a bunch of stuff for inclusion in CVS that now may be rejected because I listened to Berta’s crazy-talk. I told you this method was good. <sigh>

If anyone has a tool that’ll convert my non-standard code from Allman to K&R so I can fall back into my good habits, please let me know.