Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-01-2009, 08:48 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Tigairius View Post
That's correct, Java's switch() statements only allow ints, but that doesn't mean I should model my code after the standards Java runs. You may notice that GScript2 utilizes strings much differently than most coding languages. Following that logic I should also declare all of my variables before using them even though they're automatically declared when they're not equal to NULL.
Not true, Java's switch() does not only allow ints (it also allows char, byte, and short types), and for that matter, switch() works the same in just about every other popular language (such as C++ which was used largely in making Graal).

I'm not saying you shouldn't use strings in switch() statements on Graal, I'm just pointing out that other languages wouldn't allow you to do that. Regardless, though, I still feel that it was quite unnecessary in this case.


Quote:
Originally Posted by Tigairius View Post
It really isn't necessary for this... if someone said filteron and it was currently on it would just switch it off. An extra line or two really isn't a big deal in my opinion.
I agree that it isn't so important for this example, but when you're dealing with large scripts (such as the code for Windows that is well past millions of lines), it is quite important to shorten the number of lines as much as possible. Just a general tip.
Reply With Quote
  #2  
Old 05-01-2009, 09:48 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
Quote:
Originally Posted by Gambet View Post
Not true, Java's switch() does not only allow ints (it also allows char, byte, and short types), and for that matter, switch() works the same in just about every other popular language (such as C++ which was used largely in making Graal).
All the languages that do switch statements and only allow you switch on integral types do that on account of having copied the syntax pretty much verbatim from C.

D lets you switch on strings, perl does not let you switch at all unless you write your own switchiness, ruby lets you switch on pretty much goddamn anything that defines an operator for matching a switch case. In Haskell and Nemerle, a switch-like structure is the basic low-level control structure and works for everything as well.

Quote:
Regardless, though, I still feel that it was quite unnecessary in this case.
I think it is purely a matter of style, here. Checking a variable against a sequence of values looks neater if you do not have to repeat the "variable ==" over and over, but all the break;s are pretty annoying too, I guess.

Quote:
I agree that it isn't so important for this example, but when you're dealing with large scripts (such as the code for Windows that is well past millions of lines), it is quite important to shorten the number of lines as much as possible. Just a general tip.
No, generally you want to make sure your code is as readable and maintainable as possible. The number of lines should only enter it a whole lot after that.
Reply With Quote
  #3  
Old 05-01-2009, 09:56 PM
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 Loriel View Post
No, generally you want to make sure your code is as readable and maintainable as possible. The number of lines should only enter it a whole lot after that.
I agree.
__________________
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 12:19 PM.


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