Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-16-2011, 01:16 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Code Styling Debate: DOs and DON'Ts

So, browsing the scripting forums, this post got me thinking:
Quote:
Originally Posted by cbk1994 View Post
It's only necessary to use temp the first time, but I'd highly recommend using it throughout.
When are things acceptable, and when are they not? I know that many code styling related topics are completely based on preference. Nevertheless, I'd like to talk about your general preferences, what is acceptable to you and what is not.

Let's start off with the temp prefix Chris was talking about. I mostly agree with always using it, but I sometimes don't do it in generally long lines/function calls because I believe it destroys readability.

What are your thoughts on this?
__________________
Reply With Quote
  #2  
Old 12-16-2011, 01:42 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
I used to only use it the first time, and eventually transitioned to always using it since it gets rid of a lot of ambiguity (is it a global variable or a temp variable?). I don't really see how it kills readability at all.
__________________
Reply With Quote
  #3  
Old 12-16-2011, 04:06 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
As I said, I almost always do it that way as well. But when I'm doing some math in a function call, lines tend to get long, so I leave it out there.
__________________
Reply With Quote
  #4  
Old 12-16-2011, 04:15 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I do it in fear of the variable getting hijacked by a global version, that same fear is also why I would using avoid player attributes/keywords when naming variables.
__________________
Quote:
Reply With Quote
  #5  
Old 12-16-2011, 04:39 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
i like to use as many colors as possible so my coding is fun and easy to look at!! xoxo
__________________
Reply With Quote
  #6  
Old 12-16-2011, 04:50 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by fowlplay4 View Post
I do it in fear of the variable getting hijacked by a global version, that same fear is also why I would using avoid player attributes/keywords when naming variables.
I always use different variable names, no matter the scope. If a name is being used globally, I won't be using it in any other scope, and so on.
__________________
Reply With Quote
  #7  
Old 12-16-2011, 04:50 PM
TSAdmin TSAdmin is offline
Forum Moderator
TSAdmin's Avatar
Join Date: Aug 2006
Location: Australia
Posts: 1,980
TSAdmin is a splendid one to beholdTSAdmin is a splendid one to beholdTSAdmin is a splendid one to beholdTSAdmin is a splendid one to beholdTSAdmin is a splendid one to behold
I tend to be consistent throughout the entire script. If I create something with a prefix, the prefix will appear every single time unless it explicitly requires dropping, but that's never been something I was forced into doing, if there's an existing reason to force the dropping of a prefix at all.
__________________
TSAdmin (Forum Moderator)
Welcome to the Official GraalOnline Forums! Where sharing an opinion may be seen as a declaration of war!
------------------------
· User Agreement · Code of Conduct · Forum Rules ·
· Graal Support · Administrative Contacts ·
Reply With Quote
  #8  
Old 12-16-2011, 05:14 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
I always include the relevant prefix (i.e. temp or player prefix; even player.clientr.foo) etc, because that way there is no ambiguity. It is good practice to do that, not least because people do not have to guess as much when reading your code, but it prevents confusion between scopes (i.e. is your temp variable actually a global variable in some unusual circumstances?). It forces you to think about the scope you are dealing with, leaving less chance of conflicts occurring.
__________________
Skyld
Reply With Quote
  #9  
Old 12-16-2011, 06:55 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Skyld View Post
I always include the relevant prefix (i.e. temp or player prefix; even player.clientr.foo) etc
Same for me aswell as the this. prefix for functions.

It would however be interesting to know if this has any bearing on script time, albeit the difference would probably be negligible.
On a similar note I compared script time between the use of the this. or player. prefix in classes joined to the player, if my results were accurate then it was always faster using this. as opposed to player. with variables and functions Serverside, however Clientside only with variables was the use of the this. prefix faster. And yes the difference was tiny.
Reply With Quote
  #10  
Old 12-16-2011, 07:21 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Crow View Post
Let's start off with the temp prefix Chris was talking about. I mostly agree with always using it, but I sometimes don't do it in generally long lines/function calls because I believe it destroys readability.

What are your thoughts on this?
As long as functions cannot be closed over, I would always use the temp prefix because it clearly defines the lookup chain.

This is especially true of code that uses a with block or GUI controls just because a lot of people like to drop the this prefix in those cases, so it actually becomes something of a burden for the reader.

However, removing the temp prefix has no ramifications as far as efficiency is concerned (save for 5 keystrokes).

e:

Quote:
Originally Posted by ffcmike View Post
On a similar note I compared script time between the use of the this. or player. prefix in classes joined to the player, if my results were accurate then it was always faster using this. as opposed to player. with variables and functions Serverside, however Clientside only with variables was the use of the this. prefix faster. And yes the difference was tiny.
Could you post the code you used to test? This really seems unbelievable to me.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
Reply


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 09:02 AM.


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