View Single Post
  #3  
Old 07-07-2009, 11:58 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by WhiteDragon View Post
Variable Declarations

Variables should be declared before used. GS2 does not require this, but doing so makes the program easier to read.

The variable declarations should be the first statements in the function body.

It is preferred that each variable be given its own line and comment.
PHP Code:
temp.currentEntry// currently selected table entry
temp.level// current level
temp.size// size of table 
There was a debate somewhere in the forums a while back about this. I don't understand why you'd do something like that when you can instead do this:

PHP Code:
/*
    Variables:
    
    temp.level - current level
    temp.size - size of table
*/ 
Why make the engine do more work by even parsing the text to see if it should do anything with it? Comments work just as well.
Quote:
Always use the prefix even after originally declaring the variable for clarity.
This is personal preference, though generally leads to cleaner coding. I don't do it myself, but I name my variables in a way that it is easy to know where they are coming from.
Quote:
  • Classes should start with an upper case letter
It is general Graal style to have classes in all lowercase letters. I don't know of a single server that has classes with uppercase letters. Classes are not objects (like this rule was meant for). There's no reason to capitalize them.
Quote:
  • The { should be at the end of the line that begins the compound statement.
This is personal preference.
Quote:
return is a function, not a statement, therefore it should use ( ) around the value, otherwise we are using GS1 syntax.
I'm like 99percent certain this is incorrect. Someone please let me know if I'm wrong. return is not a function in any language (with similar syntax to GS2) that I know of (such as Java).
Quote:
Each case is aligned with the switch. This avoids over-indentation.
I disagree completely. It ruins the general indentation style for different blocks of code. Over-indentation is not a problem. Not indenting only hurts readability.
Quote:
Each group of statements (except the default) should end with break or return. Do not fall through.
Why? There are times when it is perfectly okay to fall through.

PHP Code:
switch (player.chat) {
  case 
"/clear":
  case 
"clear":
    
// clear messages
  
break;


I appreciate the effort you put into this, but it's focused way too much on what personal preference should be rather than clean coding standards.
__________________
Reply With Quote