Raised This Month: $ Target: $400
 0% 

charmax & sizeof


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-29-2013 , 04:00   Re: charmax & sizeof
Reply With Quote #1

Quote:
Originally Posted by Leon M. View Post
A smart coder thinks earlier about it, changed once a variable and that was a quick edit. Well, only if you know what are you doing, so I guess its better to use charsmax

But that sounds conceited ;)

As I said such code is more readable for me, that's why I prefer it :p
Smart coders use charsmax EVERY TIME [, in this context].
__________________

Last edited by fysiks; 04-29-2013 at 04:01.
fysiks is offline
Strick3n
Member
Join Date: Apr 2013
Old 04-29-2013 , 09:43   Re: charmax & sizeof
Reply With Quote #2

Quote:
Originally Posted by GhostMan View Post
In one 'Glow' plugin i found these lines:
PHP Code:
new name[64]
get_user_name(Player[iPlayer], namesizeof(name) -1
And i'm wondering if this would be the same?
PHP Code:
new name[33]
get_user_name(Player[iPlayer], namecharmax(name)) 
Maby using charmax is even better?

By the way would he creat name[64]? Aren't [33] is enought?
same same new name .
Strick3n is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-30-2013 , 04:17   Re: charmax & sizeof
Reply With Quote #3

What a dumb reason. Bad practice. Less readable. Loss of maintainability. There is no valid reason to hardcode.
__________________

Last edited by Arkshine; 04-30-2013 at 04:18.
Arkshine is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 04-30-2013 , 19:17   Re: charmax & sizeof
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
What a dumb reason. Bad practice. Less readable. Loss of maintainability. There is no valid reason to hardcode.
global variables what is needed to change some reason, those i still do with charsmax
but there are not that many things you need to changes.
.Dare Devil. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-30-2013 , 23:40   Re: charmax & sizeof
Reply With Quote #5

Quote:
Originally Posted by .Dare Devil. View Post
but there are not that many things you need to changes.
lol. Based on this statement, I can only assume that you don't make large scripts.
__________________
fysiks is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 05-03-2013 , 08:37   Re: charmax & sizeof
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
lol. Based on this statement, I can only assume that you don't make large scripts.
Why not?
.Dare Devil. is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-30-2013 , 10:24   Re: charmax & sizeof
Reply With Quote #7

When I had just started scripting, I used direct numbers instead of sizeof/charsmax() macros. I felt like it's faster that way and using macros just wastes time and makes the code somewhat bigger. I guess people here who are against macros are still going through this "early" period?

After quite a few years of experience I can now tell that it's definitely best to define/use constants/macros for nearly any direct value, unless it's a reaaaally short and unimportant script which you need to be done ASAP.
Code:
new PlayerNames[33][32];

Code:
#define MAX_PLAYERS 32 #define MAX_NAME_LEN 32 new PlayerNames[MAX_PLAYERS + 1][MAX_NAME_LEN];
Basically, the direct values (numbers, strings, etc.) should only be seen in the header of the script file (where you define constants/macros for them), while very scripts should only contain "words" (scripts/macros).
__________________
hleV is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-30-2013 , 10:27   Re: charmax & sizeof
Reply With Quote #8

Quote:
should only be seen in the header of the script file
Just an unimportant note, I usually prefer to define the constants/macros used in only one function directly inside of it, unless it's meant for editing.
Backstabnoob is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-30-2013 , 11:02   Re: charmax & sizeof
Reply With Quote #9

@hleV
I do it like you for globals

@backstabnoob
Trolls will be ignored! Well from now on.
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015
Leon M. is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-30-2013 , 11:37   Re: charmax & sizeof
Reply With Quote #10

Quote:
Originally Posted by Backstabnoob View Post
Just an unimportant note, I usually prefer to define the constants/macros used in only one function directly inside of it, unless it's meant for editing.
Well, if a value is completely function-exclusive, is irrelevant in any other context and is not supposed to ever be altered in the future, then it's perfectly acceptable to put it inside a function, I guess. Like making a static const (rather than a global const) string to not recreate it every time. For macros specifically, I tend to put them in the header of the file, though.
__________________

Last edited by hleV; 04-30-2013 at 11:41.
hleV is offline
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 -4. The time now is 10:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode