I am pretty much the only person I know who codes in the Allman style. I really, really like the idea of braces on their own lines. To me it's just logical and normal. 99% of the code I see, whether it be online or at work is in K&R style, or some variant.
I know I am in a very, very, small minority. I am the only person at my workplace that codes in this style. Because of this, it is sometimes difficult to read others' code and vice versa. It can also be difficult to read code online, in code snippets, etc. because it's just so different from what I see on a day to day basis.
But it's not just brace placement. Variable and method naming conventions are different, too. I prefer to name my things (variables and methods) in lower_snake_case. In my opinion it is the easiest to read, especially if you get into a situation (albeit sometimes rare) where you have no choice but to use a longer-than-usual name. In my opinion this_awesome_variable_that_is_long is much easier to read than thisAwesomeVariableThatIsLong. I believe it also best reflects "everyday" reading (at least in English) as most everyday text is lowercase and separated by spaces. There is also the debate of when you use an abbreviation or shortform. thisUrl or thisURL? I avoid the debate by making everything lowercase.
On the front-end I make sure my CSS properties are listed in alphabetical order. It takes a couple extra seconds to do it, and when it comes time later to make a change you know exactly where to find the property. Otherwise "display: block;" could be the first property, the last, or somewhere in between. I don't want to waste my time hunting through properties just to make a change (also Firebug lists them in alphabetical order, so making changes is easier since I know the second property is actually the second property). I understand the other side of that argument in that you don't want to have to hunt through properties to know where to add the next one. My counterargument is this allows anyone to jump in immediately, and inevitably when the time comes to go back and make changes you are already equipped with where to make the change. Essentially you can get down to business right away. I always feel it's better to "take the hit now" vs later, because you can plan for it now. There is a plugin for PhpStorm that allows you to automatically sort the properties, though it is a little buggy. In the end though I believe the time saved later more than makes up for the extra time now.
I also like to align assignment operators, colons, etc. Making my code readable (and therefore in my opinion, easy to modify and maintain) is usually my #1 priority.
So why the question? Well we have recently secured quite a large project. Other than it's a social media site, I can't say much more (under an NDA plus I simply haven't been filled in on the details yet ). Due to its size there will definitely be multiple developers working on it, sometimes at the same time but also sometimes "switching off". If everyone just "did their thing", than that means there will be a mix of coding conventions/style in the project, which is obviously a poor practice.
I am the senior developer (please stop laughing) so technically I could "set the standard" but I'd rather not be "that guy", directly or indirectly (meaning I bring the issue to management, they side with me, and make everyone do it). It is possible we could set a custom coding standard for the project, but that may be detrimental in the long run when developers (including myself) have to switch onto something else that is another style.
So what would you do? Should I take the plunge and try to code in an alternative style, or just say screw it and everyone does their own thing? Or make everyone do something completely different for this project? I included an "illustration" below of what I mean.
What I would do:
public function has_invoice_requires_sourcer()
{
if(!count($this->invoices))
{
throw new Invalid_Invoice_Exception('The request should have at least one invoice!');
}
foreach($this->invoices as $invoice)
{
if($invoice->usd >= SOURCING_MANAGER_THRESHOLD)
{
return true;
}
}
return false;
}
What I usually see:
public function hasInvoiceRequiresSourcer() {
if(!count($this->invoices)) {
throw new Invalid_Invoice_Exception('The request should have at least one invoice!');
}
foreach($this->invoices as $invoice) {
if($invoice->usd >= SOURCING_MANAGER_THRESHOLD) {
return true;
}
}
return false;
}
The lack of white space between lines, which to me are distinct, also throws me off.
Would love to hear comments, suggestions, concerns, even stories. Thanks for reading!