What are the best practices?
Hey,
I bet you all have your ways of coding things; I surely have learned a lot from my mistakes. So what are your best practices in terms of coding? First of all, let me start: - use classes, and sub classes to override behaviour - use one convention for all your variables, don't do i1, i2, i3, etc. - do not do this: Code:
int i =0; // set i to 0 So, what do you suggest? |
Re: What are the best practices?
Why not initialise variable to zero ?
|
Re: What are the best practices?
I think that is about the useless comment "set i to 0"...
for my experience, now I feel by not stuff all parameters in function declarations in one line can sometimes offer better readability, like this: PHP Code:
PHP Code:
|
Re: What are the best practices?
Yeah it was about the comment ;-) I mean, the comment is more characters then the actual line of code; which brings me to:
- the code should be readable as it is, any comment needed to explain code, means your code is not simple/good enough. Comments however can explain WHY certain things are done Since i work with Java for some time now, I have been into classes big time; when i see the RB code, all those FUNC_ methods give me the creeps. Keep things where they belong (ie, a bot can See things, not a util method with a bot pointer... ) Also, i am all with you Whistler about huge params functions, but then again, you might wonder why they need so many params :) |
Re: What are the best practices?
Nice idea Whistler but I really don't like this kind of syntax. :)
Maybe is better when there is many arguments to put them in a struct or class and to pass one object or pointer as argument instead of many arguments. ;] |
Re: What are the best practices?
I don't know if that is better The Storm; because you hide the functionality from the method signature.
I mean, if you do something a a bot for instance, hence a bot pointer is needed. But, then again you may wonder if the method you are creating would not be better to be part of the bot class itself. Methods with an awful lot of variables often indicate too much is done within the same method. Which is a 'bad smell' imo ;) |
Re: What are the best practices?
Still I don't like the kind of new line syntax, but here whats looks better for me:
Code:
int MyFunc(int iParameter1, float flParameter2, char szParameter3[], P.S. I can't get it to display well in the forum board but you get the idea. :P |
Re: What are the best practices?
Ah yes, thats how i like it as well. I was more referring like putting everything in one class for the sake of reducing arguments ;)
|
Re: What are the best practices?
Sometimes is good the classes to have static public methods. :P
|
Re: What are the best practices?
Quote:
|
All times are GMT +2. The time now is 15:05. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.