.:: Bots United ::.  
filebase forums irc server wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps waypoints yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
What are the best practices?
Old
  (#1)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,083
Join Date: Nov 2003
Location: Netherlands
Default What are the best practices? - 01-07-2008

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
- use assertions wherever possible, to assure your assumptions are correct

So, what do you suggest?


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: What are the best practices?
Old
  (#2)
The Storm
Council Member / E[POD]bot developer
 
The Storm's Avatar
 
Status: Offline
Posts: 1,605
Join Date: Jul 2004
Location: Bulgaria
Default Re: What are the best practices? - 01-07-2008

Why not initialise variable to zero ?
  
Reply With Quote
Re: What are the best practices?
Old
  (#3)
Whistler
Whistler
 
Whistler's Avatar
 
Status: Offline
Posts: 1,490
Join Date: Feb 2004
Location: P. R. China
Default Re: What are the best practices? - 02-07-2008

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:
int
MyFunc
(
   
int      iParameter1,
   
float    flParameter2

looks better than:

PHP Code:
int MyFunc(int iParameter1float flParameter2
... especially when there are too many parameters

Last edited by Whistler; 02-07-2008 at 08:50..
  
Reply With Quote
Re: What are the best practices?
Old
  (#4)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,083
Join Date: Nov 2003
Location: Netherlands
Default Re: What are the best practices? - 02-07-2008

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


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: What are the best practices?
Old
  (#5)
The Storm
Council Member / E[POD]bot developer
 
The Storm's Avatar
 
Status: Offline
Posts: 1,605
Join Date: Jul 2004
Location: Bulgaria
Default Re: What are the best practices? - 02-07-2008

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. ;]
  
Reply With Quote
Re: What are the best practices?
Old
  (#6)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,083
Join Date: Nov 2003
Location: Netherlands
Default Re: What are the best practices? - 02-07-2008

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


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: What are the best practices?
Old
  (#7)
The Storm
Council Member / E[POD]bot developer
 
The Storm's Avatar
 
Status: Offline
Posts: 1,605
Join Date: Jul 2004
Location: Bulgaria
Default Re: What are the best practices? - 02-07-2008

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[],
                    string strParameter4, bool bParameter5)
{
       // The stuff...
}
i.e. when the arguments can't fit good on the screen we put the new line with one tab space after the first bracket.

P.S. I can't get it to display well in the forum board but you get the idea.
  
Reply With Quote
Re: What are the best practices?
Old
  (#8)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,083
Join Date: Nov 2003
Location: Netherlands
Default Re: What are the best practices? - 02-07-2008

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


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: What are the best practices?
Old
  (#9)
The Storm
Council Member / E[POD]bot developer
 
The Storm's Avatar
 
Status: Offline
Posts: 1,605
Join Date: Jul 2004
Location: Bulgaria
Default Re: What are the best practices? - 02-07-2008

Sometimes is good the classes to have static public methods.
  
Reply With Quote
Re: What are the best practices?
Old
  (#10)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: What are the best practices? - 03-07-2008

Quote:
Originally Posted by Whistler View Post
...
PHP Code:
int
MyFunc
(
   
int      iParameter1,
   
float    flParameter2

looks better than:
...
I think that can be useful if you want to include comments to each parameter. but nonetheless, a header-text for each function describing what it does is nice. there are also some programs around to automatically create documentation from those texts in a bunch of html files


  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com