Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 02-11-2010, 07:07 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by cbk1994
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.
There's no reason to capitalise them because you can't capitalise them. When you do, the capitals get decapitalised.

Click image for larger version

Name:	proof.jpg
Views:	115
Size:	58.1 KB
ID:	50395

Notice the window title compared to the RC output and class window?

Note: Sorry, I have nothing to do
Reply With Quote
  #17  
Old 02-11-2010, 07:41 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
Requesting unstick. This contains suggestions such as "avoid falling through", "variables should be declared", and other statements that are pretty blatantly wrong.
I don't mind if this gets unstuck, but I still believe everything I wrote in here is more or less proper.

Could you elaborate perhaps?

Regarding the class capitalizing, I would change that but I can't edit this anymore.

Quote:
Personally, I don't think this is much of a clean-coding guide or whatever the Hell it's supposed to be so much as your personal preference in guide form. A lot of this stuff is very arguable, and what gives you the right to make your personal preference a standard, as this has been stickied?
It isn't a standard. I'm trying to appeal to people's intuitions about rules that have a logical backing.

If there a rule that work better for you, by all means use them. I'm also open to arguing any of the suggestions I provided.
Reply With Quote
  #18  
Old 02-11-2010, 08:26 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
I guess you could do worse than declaring variables especially considering Graal's crazy variable scopes, and while I do not do it in javascript either I can see the point considering var in a nested scope does not do what you would think it does.

And I guess falling through on switch cases is okay as long as you put // FALL THROUGH or something.
Reply With Quote
  #19  
Old 02-11-2010, 08:52 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Even though most of the languages I use these days don't require it, I tend to declare all the variables I'm going to use at the beginning of a function, thanks to spending a lot of time with C.

That has it's uses, though, other than just being used to it.
Reply With Quote
  #20  
Old 02-12-2010, 12:09 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
I don't mind if this gets unstuck, but I still believe everything I wrote in here is more or less proper.

Could you elaborate perhaps?

Regarding the class capitalizing, I would change that but I can't edit this anymore.


It isn't a standard. I'm trying to appeal to people's intuitions about rules that have a logical backing.

If there a rule that work better for you, by all means use them. I'm also open to arguing any of the suggestions I provided.
For the thread to be stuck pretty much says it is the "correct" way to do things. A few points:
  • Variable declarations serve absolutely no purpose to the engine, and can't possibly have any other effect except slowing it down, even if ever so slightly. Saying that all variables should be declared before being initialized is incorrect and personal preference. It is probably better to just use comments for listing variables.
  • The indentation of your switch statement is wacky. This is just my personal preference, but yours is being promoted as some kind of standard.
    PHP Code:
    switch (variable) {
      case 
    "value":
        
    // whatever
      
    break;
      
      case 
    "value2":
        
    // whatever2
      
    break;

    switch statements don't really have a universal format, though.
  • Falling through in switch statements isn't a problem unless you work on a server with really poor scripters.
  • 'default' needs to end with a break or return as well. Keep in mind it doesn't have to be at the end of the list.
  • Apparently classes can't even start with an uppercase letter, and even if they could/can, that would be different than what 99% of servers are doing now.

The thread is well-intentioned, but I don't like how it tries to set the "right" way to script based on someone's ideas. I wouldn't have a problem if the thread was reposted/edited with the controversial/incorrect stuff removed. There are also some things that need further explanation, such as the return statement. The way it's worded now it could be seen that something like:
PHP Code:
return (((2) + (2)) ^ .5); 
is wrong, when it's clearly not.
__________________
Reply With Quote
  #21  
Old 02-12-2010, 12:47 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
yea :0
Reply With Quote
  #22  
Old 02-12-2010, 01:01 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
For the thread to be stuck pretty much says it is the "correct" way to do things. A few points:
  • Variable declarations serve absolutely no purpose to the engine, and can't possibly have any other effect except slowing it down, even if ever so slightly. Saying that all variables should be declared before being initialized is incorrect and personal preference. It is probably better to just use comments for listing variables.
  • The indentation of your switch statement is wacky. This is just my personal preference, but yours is being promoted as some kind of standard.
    PHP Code:
    switch (variable) {
      case 
    "value":
        
    // whatever
      
    break;
      
      case 
    "value2":
        
    // whatever2
      
    break;

    switch statements don't really have a universal format, though.
  • Falling through in switch statements isn't a problem unless you work on a server with really poor scripters.
  • 'default' needs to end with a break or return as well. Keep in mind it doesn't have to be at the end of the list.
  • Apparently classes can't even start with an uppercase letter, and even if they could/can, that would be different than what 99% of servers are doing now.

The thread is well-intentioned, but I don't like how it tries to set the "right" way to script based on someone's ideas. I wouldn't have a problem if the thread was reposted/edited with the controversial/incorrect stuff removed. There are also some things that need further explanation, such as the return statement. The way it's worded now it could be seen that something like:
PHP Code:
return (((2) + (2)) ^ .5); 
is wrong, when it's clearly not.
Hi Chris,

For the thread to be stuck just means that people should look at it. Some guidance is better than none. (We have all seen some of the scripts out there.)

Regarding variable declarations, this is my rational behind the rule:
It makes it very clear how GS2 handles variables, and scope. As there is no block scope in GS2, this code code could be misleading:
PHP Code:
for (temp.0temp.2temp.i++) {
  echo(
temp.i);

With the above code, one (perhaps who has used C, C++, C#, Java, or the likes) may assume that temp.i would not be accessible outside of the for loop. However, this code makes it clear:
PHP Code:
temp.i;
for (
temp.0temp.2temp.i++) {
  echo(
temp.i);

Notating the script with comments would not have this same effect.
Also, naturally, when trying to make a standard for defining your variables, why not use the one that already exists within the syntax of the language? Speed is a non-reason against this point.


Regarding the switch indentation, the style 1) prevents over-indentation, and 2) matches the indentation style of all the other statements (that is, indent all compound statements within the outer statement; the cases being part of the switch statement).


Regarding falling through, sorry, but are you calling me and many of famous professional programmers & scripters "poor"? (This includes the language designers of C#, Go, Pascal, Ruby, Ada, Eiffel, and more.) Just because a construct exists in a language doesn't warrant over-usage of it. The switch statement can be really, really misleading to even mature scripters, and totally foreign to newbie scripters.


For a break;/return; in default:, that sounds extremely weird, as default is normally only evaluated when all the other cases are exhausted (apparently I don't know switches in GS2 that well either), but I'll confirm when I get home tonight.


I would have edited the class rule by now but can't.


The wording on the return statement section is a fair point and I would edit it if I could.


Thanks for commenting Chris, and I hope you agree that a thread including this information is better than no thread at all.
Reply With Quote
  #23  
Old 02-12-2010, 01:10 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Graal really needs some coding conventions. The finer points can be debated at other times. I want this thread stickied.
__________________
Reply With Quote
  #24  
Old 02-12-2010, 01:11 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
From what I remember reading, in GS2, the only proper time to use the switch statement is when you want to take advantage of falling through, as it's a less efficient than standard if-than-else.
Reply With Quote
  #25  
Old 02-12-2010, 01:15 AM
benpoke103 benpoke103 is offline
Zvarri!
benpoke103's Avatar
Join Date: Jun 2002
Posts: 332
benpoke103 will become famous soon enough
Quote:
Originally Posted by Inverness View Post
Graal really needs some coding conventions. The finer points can be debated at other times. I want this thread stickied.
Seconded.
__________________
Need support? Here's how to reach me.

Forum PM (Preferred)
#graaldt @ Freenode
Reply With Quote
  #26  
Old 02-12-2010, 01:39 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by 12171217 View Post
From what I remember reading, in GS2, the only proper time to use the switch statement is when you want to take advantage of falling through, as it's a less efficient than standard if-than-else.
Hey Downsider,
Although I don't claim to have any knowledge of the specific Bison language parser Stefan created nor any of its specific optimizations, in terms of switch statements in general:
A switch statement can always perform at least as well as a logically equivalent if statement.
A switch statement can perform better than an if statement when the range of values of the switch statement are sufficiently close enough to get compiled to a branch table.

I doubt that optimization has been made in GS2 though, so they are most likely equivalent in terms of performance.
Reply With Quote
  #27  
Old 02-12-2010, 06:31 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
I still remember reading that.

And lol @ gs2 being compared to a typical bytecode language. This is Graal. It's atypical in every way, especially the client.

dunno. you seem conceited, especially the "hi chris" "hi downsider" and the whole long-post-obviously-trying-to-intimidate deal. Bit upsetting.
Reply With Quote
  #28  
Old 02-12-2010, 06:56 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by 12171217 View Post
dunno. you seem conceited, especially the "hi chris" "hi downsider" and the whole long-post-obviously-trying-to-intimidate deal. Bit upsetting.
Alright, here is my point of view: my thread gets unsticked (I don't even know who did it) for a reason that I totally don't agree with (minor disagreements), with no alternative put up, and I try to back up my logic.

I'm sorry if I upset you but I'm honestly trying to do something good here.
Reply With Quote
  #29  
Old 02-12-2010, 07:11 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
I'm upset.
Reply With Quote
  #30  
Old 02-12-2010, 08:46 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
I don't know, I think he's made some very good points.
And by all means, GS2 is not a bad language, Downsider, for what it's trying to do. I doubt Switch statements would be any slower than if-else logic.

WhiteDragon is someone who obviously has considerable experience and knowledge in computer science and while finer points of style boil down mostly to aesthetics and popular convention, the points he's made here are completely legitimate and helpful even if you may disagree with them.

This should be stickied.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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


All times are GMT +2. The time now is 01:31 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.