开发者

Routine to keep names of methods, classes and functions organized?

开发者 https://www.devze.com 2023-01-19 08:49 出处:网络
I am working on a web application with a couple of colleagues for the mo开发者_StackOverflowment. It have turned out that we all have our own way of naming the classes, methods or whatever functions t

I am working on a web application with a couple of colleagues for the mo开发者_StackOverflowment. It have turned out that we all have our own way of naming the classes, methods or whatever functions that we currently are writing.

This is starting to get really annoying already so I know that we have a iceberg ahead if we continue like this.

Obviously the best way is to find one routine and stick to it - but how should that specific routine look? - What is common sense when naming pieces, objects, functions or whatever? Are there any standards out there?

Thanks a lot!


One standard you could adopt is the Zend Framework standards


You can take a look at the following: http://www.dagbladet.no/development/phpcodingstandard/

My work has implemented this, and while I don't always agree, at least it spawns consistency.


Take a look at the PEAR Coding Standards. It's pretty comprehensive and would make things easier if you ever use any pear packages.

It also might help to look up CRUD (Create Read Update Delete) on Wikipedia.

As for singulars vs plurals, I tend to try to stick with the conceptual style of my code. I find that with OOP, object names generally tend to be easier to wrap your mind around when you use singulars.

Even if your class is going to comprise information about multiple Dogs, instead of naming it Dogs, name it something else, like Pack, even if it's not technically a pack. It's easier to wrap your mind around multiple Packs than multiple Dogs's, and a "pack" is conceptually stronger than an amorphous group of "dogs". "Dogs" doesn't sound like a single object, whereas "pack" does.

I guess this is an obvious example, but if your class is only going to be used to define objects on an individual basis, don't make it plural. Or if your function is going to format only one string at a time, don't call it formatStrings().

Arrays are a little different. If you use an array for a list of all your dogs, you wouldn't name it $pack, because you'd expect that to contain information about a pack. Instead, you'd name it $dogs.


Use namespaces. Get together and come up with a logical namespace hierarchy policy, then use logical names within the namespaces for the elements.


Sit down with your colleagues, explain the problem you are watching develop, and then write down a standard that you all agree upon.

As you've identified, the only problem is consistency. Therefore, do not convince yourself that you also need a standard that is scientifically-proven to be optimal.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号