How should I order my parameters in a class?
I believe that I everything should be in alphabetical order, but what of grouping of different access modifiers.
- const
- public
- private
What order should they be arranged in?
How should I order my parameters in a class?
I believe that I everything should be in alphabetical order, but what of grouping of different access modifiers.
- const
- public
- private
What order should they be arranged in?
That's up to you or whoever reviews your code. If you write apps alone. Its whatever is easiest for you.
Personally I order code by relevance. I create some regions and put similar things together. I put the private variables and the public properties that expose them right next to each other in a vars and properties region. I put the load event toward the top, and the on closing event toward the bottom.
When the program compiles its all one big sheet of code anyway. There isn't a right way. (unless you work for a company that cares, in which case, do what they ask)
So there's no standard way of ordering things? I would like to adopt a good practice early. :)
Those guidelines were written by some cleaver programmers, There is no "official" standard. But there is always the Standard microsoft uses in its coding examples on MSDN.
I would argue to the OP that I don't think alphabetical is the best practice or even relevant. If you use Visual Studio (and everyone should because its amazing) you will notice that there is a combo box at the top of ever code view that lists all the members of the current document in alphabetical order. click on one and you are there.
Not saying that coding practice's aren't important, Because its very important that you are consistent. I Just don't feel that the order of your code should at all be based on access modifiers. Nor do I feel that all members with similar access modifiers even be kept together.
Best of luck. Learning to keep your code clean at the beginning can lead to a career of easy to review code.
Have a look at - Standards and Best Programming Practices
I couldn't find anything about ordering of variables in there?
There was lots of great information besides that!
I don't know if this would be how you want to do it, but my team in school ordered all variables by byte order, largest (long, double) to smallest (char, bool), followed by variable size (strings, containers, etc...). I'm not sure if it really made a difference in compile times, but it was organized nicely.
Does anyone recommend grouping by access type (private public, etc.)?
How they are grouped or ordered makes no difference to the app once it is compiled. The ordering/grouping is purely for your benefit whilst coding, and the benefit of those who may need to read your code in the future for review/maintenance/update.
If you aren't coding in an environment that has coding practices (as some employers/lecturers specify) then its your choice. Find a system that works for you. The key things to aim for are to make variables easy to locate and make your code easier to understand. I tend to group mine by use, so counters together, data access objects together, etc. But thats just me :p
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.