Coding style
#2

https://en.wikipedia.org/wiki/Hungarian_notation

The main point of Hungarian Notation is that you know what the variable's scope, type and purpose is from its name. For example, the variable you mentioned would be something like g_iPlayerTickSinceLastShot[MAX_PLAYERS];

the g_ shows it's a global variable, the 'i' prefix shows it's an integer, and then you have a CLEAR name. The thing you missed out was the 'Player' word. I always stress this to anyone. Take this example:

pawn Код:
new Float:health;
What's wrong here? Well, we know it's going to store a health value, but the health of what? I always use lower camel case for local variables (as per H. notation) and make sure to include the reference in the variable name, so:

pawn Код:
new Float:fVehicleHealth;
The 'f' denotes that it is a float, and you can clearly tell from the variable name that it stores the vehicle's health. You could even go a step further and be more specific and call it 'fCurrentVehicleHealth'.

I would steer clear of over-using abbreviations like 'TC' for tick count, just use 'Tick(s)'. You don't want to be looking at a script and think 'wtf is TC' and have to Ctrl+F all over the place. Abbreviations should only be used if they can't be misunderstood, for example I use 'Cur' instead of Current, 'IDX' for index (as many do) and so on.

Also, on a related note, try and keep variable names short. It's not fun typing 'PlayerTimeSinceLastConnectionToServer' 50 times.

Regarding the Allman indentation style: I don't see why you wouldn't use it. I hate K&R (bracket on the same line). It looks messy.
Reply


Messages In This Thread
Coding style - by Su37Erich - 09.10.2015, 21:04
Re: Coding style - by MP2 - 10.10.2015, 11:19
Re: Coding style - by Vince - 10.10.2015, 12:10
Re: Coding style - by Su37Erich - 24.10.2015, 00:52
Re: Coding style - by Kaperstone - 24.10.2015, 03:43
Re: Coding style - by Crayder - 24.10.2015, 08:45

Forum Jump:


Users browsing this thread: 1 Guest(s)