![]() |
Code Styling Debate: DOs and DON'Ts
So, browsing the scripting forums, this post got me thinking:
Quote:
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? |
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.
|
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.
|
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 like to use as many colors as possible so my coding is fun and easy to look at!! xoxo
|
Quote:
|
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.
|
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.
|
Quote:
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. |
Quote:
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:
|
All times are GMT +2. The time now is 01:51 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.