Advertisement

Any other suggestions for my code?

Started by January 14, 2003 08:41 PM
10 comments, last by SSJCORY 21 years, 10 months ago
Here's my suggestion:
- int main() look nicer than main(); but is the same
- don't put open braces at the end; align it with same column as close braces, it look nicer that way.
- data members better be private
- use struct if all else require publicity
- use switch instead of multiple if
- use initialization list as much as possible in constructor
- Capitalize class name; small name are for variables.
- Capitalize function name; as your other function begin with capitals. (hint: create())
- If you have explicit 'creation' (the calling of create()), then you need explicit 'destruction'.
- Do have some prefixes/sufixes to indicate it as a member variables, globals... or a pointer.
- Add const to the back of the function if your function just simply return something.
- Don't immediately instantiate objects after definition of class. Looks better if they are created seperately.
- Do seperate your class in another .h/.cpp
- Don't create any function that looks like main (Main)
- Publics in the front looks better, so is having privates at the end.
- Don't use old include (as many have suggested)
- and finally... be consistent.

.... phew...


[EDIT]
and....
- Bad@mount0fspacing<readability.
- dontputyourvariablewithnamelikethis.
- capitalizeYourVariableThisWayLooksBetter.
- CapitalizeYourClassThisWayLooksBetter.



[edited by - DerekSaw on January 15, 2003 8:51:35 PM]
"after many years of singularity, i'm still searching on the event horizon"
don''t be afraid of the spacebar. personally, I think cout << "blah" << var << "blah"; is easier on the eyes than cout<<"blah"<<var<<"blah";

comments. comment stuff that you do- what variables are for, why you use certain processes before. it will make your life easier if 5 years from now you come back to the code and have to figure out what everything does. or if you''re like me, you can use them to try and convince your teacher that what you''re doing makes sense. well, you could do that if you''re a student

This topic is closed to new replies.

Advertisement