Code styles - prefered, readability & performance
I've seen here many different coding styles. And I asked myself - and now I ask you - which of these two examples do you prefer in consideration of the readability, maintain & performance.
Or is there even a performance deviation at all? PHP Code:
PHP Code:
PHP Code:
PHP Code:
Comments?and why? or do you just feel like "f?#k readability! what is style? most important is the functionality!"? :bee: Maybe you got some other code style examples with their dis-/advantages. |
Re: Code styles - prefered, readability & performance
example #2 spacing and neatness/straightness
|
Re: Code styles - prefered, readability & performance
PHP Code:
|
Re: Code styles - prefered, readability & performance
This is all user preference. You can't be asking an answer to an opinion.
Also if you use spaces and not tabs. End yourself. I personally use this style: PHP Code:
|
Re: Code styles - prefered, readability & performance
My List would be:
Performance first because, i would rather drive a ugly car thats working correctly than driving a pretty car that can't even start. Also along the way you can use the commenting style to define your functions and their use for yourself & others to know: 1: PHP Code:
PHP Code:
Q. How to name variables/function? A. Simple as short as you possible can without breaking the readability. Example: using function "OnGameFrame" ticks about 66 times a secound tho it depends on the Servers FPS rate, so there is a big difference here in having variables named with 50 bytes than with 10 bytes. Q. Use 'many' space lines / shrink the size? A. Just stick to use TABS which equals to 4 spaces. Spoiler for why to use tabs (Stolen from some random site):
Spoiler
Q. old/new syntax? A. NEW SYNTAX Why even question this. |
Re: Code styles - prefered, readability & performance
Group related functionality when possible and don't repeat things if you don't have to. If the control flow is weird, put failure states in early.
Maintainability's important. You'll want to know what you're looking at when you come back to it after a few months. If you asked me to implement Some_Command with all the same functions, I would've done it like this: Code:
public Action Some_Command(int client, int argc) { |
Re: Code styles - prefered, readability & performance
Code:
public Action Some_Command(int client, int args) { if (!IsClientConnected(client)) { return Plugin_Handled; } if (!CVAR.BoolValue) { PrintToChat(client, "nope"); return Plugin_Handled; } if (GetClientTeam(client) != 1) { PrintToChat(client, "nope"); return Plugin_Handled; } return Plugin_Handled; } |
Re: Code styles - prefered, readability & performance
Quote:
|
Re: Code styles - prefered, readability & performance
Quote:
|
Re: Code styles - prefered, readability & performance
Quote:
When I was learning SourceMod ThatOneGuy taught me how to stay completely organized by prefixing all variables with their type and if they're global or not so it's simple to tell, for example... This really helped me when I was starting PHP Code:
Spoiler
In the end - assuming everything's working okay - it's all about readability and if my padded, spacey (and in my opinion) clean style makes it easier for someone to understand then that's all that matters to me. I don't write for just myself However recently I've been doing camel notation on SM 1.7 things that have a class |
| All times are GMT -4. The time now is 13:00. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.