AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [DEBATE] Hawk552 vs SnoW (https://forums.alliedmods.net/showthread.php?t=106358)

SnoW 10-13-2009 15:58

[DEBATE] Hawk552 vs SnoW
 
You should never assign a variable for zero when creating it:
PHP Code:

for( new 0sizeofszBuyCommands ); i++ ) 

But leave it as:
PHP Code:

for( new isizeofszBuyCommands ); i++ ) 

Don't blame me, it was Hawk who started the Bad practice- day.

Hawk552 10-13-2009 16:01

Re: Blocking Buy Commands (Basic)
 
Quote:

Originally Posted by SnoW (Post 961089)
You should never assign a variable for zero when creating it:
PHP Code:

for( new 0sizeofszBuyCommands ); i++ ) 

But leave it as:
PHP Code:

for( new isizeofszBuyCommands ); i++ ) 

Don't blame me, it was Hawk who started the Bad practice- day.

Edit:

Nothing.

I don't recall starting this or ever specifically saying anywhere that you have to do that, but it's completely fine. You could even consider it good practice because it clearly states what i will evaluate to instead of implying it.

SnoW 10-13-2009 16:11

Re: Blocking Buy Commands (Basic)
 
Quote:

Originally Posted by Hawk552 (Post 961095)
I don't recall starting this or ever specifically saying anywhere that you have to do that, but it's completely fine. You could even consider it good practice because it clearly states what i will evaluate to instead of implying it.

The way of assigning the variable comes from other langs such as Java where it has to be done. There's no point doing such thing in loops ( because you have some kind of habit for that ) and then not doing it in other cases. Imagine someone doing something smiliar as this:
PHP Code:

new origin] = { 00};
new 
boolbvar false

The starting values have to be known and reminding them for readability is just silly. This is really bad practice for my opinion.

Exolent[jNr] 10-13-2009 16:21

Re: Blocking Buy Commands (Basic)
 
When do you ever use a vector when you first create it?
There is always some assignment that is done before it is used.

Also, the boolean variable can be declared as false for the same reason as an integer can be declared as 0.

SnoW 10-13-2009 16:34

Re: Blocking Buy Commands (Basic)
 
There isn't always an assigment, even the origin was a bad example. It could be in a hud game my worm's origin which I'd generate in a smiliar loop in what you used the size. What ever it doesn't matter.
Obviously there's no difference between false and zero, just that assigning a var to false seems in a code even worse practice.

Hawk552 10-13-2009 16:40

Re: Blocking Buy Commands (Basic)
 
Quote:

Originally Posted by SnoW (Post 961101)
The way of assigning the variable comes from other langs such as Java where it has to be done.

... I know, I use C++ way more than I use Pawn nowadays. The reality is that no language that I know of actually demands that you assign a value; it will just be garbage until you do. For this reason, I disagree with your analogy. In C, C++, Java, etc. we avoid assigning a value whenever possible because it's significantly faster. In this case, both options cost the same amount of resources but assigning a zero value is explicit as opposed to implicit.

Quote:

Originally Posted by SnoW (Post 961101)
There's no point doing such thing in loops ( because you have some kind of habit for that ) and then not doing it in other cases.

This is true. If you're referring to my code, however, I have moved away from that recently and it was previously never a conscious decision.

Quote:

Originally Posted by SnoW (Post 961101)
Imagine someone doing something smiliar as this:
PHP Code:

new origin] = { 00};
new 
boolbvar false

The starting values have to be known and reminding them for readability is just silly. This is really bad practice for my opinion.

Why do you use semicolons, then? According to your logic, it's a "relic" from Java and isn't necessary in Pawn, so why do you bear the double-standard? To respond to your statement, though, I don't really see the problem and don't think it's "really bad practice" since it doesn't cost any extra resources, is more explicit, and doesn't create any backwards compatibility issues.

SnoW 10-13-2009 17:09

Re: Blocking Buy Commands (Basic)
 
If you assign the var, other people don't get any readability, but they can actually get confused that the assigning isn't only possible but must be done.
There's no real problem here or either a solution to this, it's all about opinions.
When using semicolons the code isn't only much more clear and readable, but also the horrible thing that you are somehow limited to invisible lines is gone. When you see in chars where the statements end and the code can be even in one line I can't do anything but use semicolons.

Hawk552 10-13-2009 17:24

Re: Blocking Buy Commands (Basic)
 
Quote:

Originally Posted by SnoW (Post 961146)
If you assign the var, other people don't get any readability, but they can actually get confused that the assigning isn't only possible but must be done.

What? Either I don't understand your point, or I thought I already explained why it doesn't matter.

Quote:

Originally Posted by SnoW (Post 961146)
There's no real problem here or either a solution to this, it's all about opinions.

Well, no. Inefficiency is real and is not a matter of opinions.

Quote:

Originally Posted by SnoW (Post 961146)
When using semicolons the code isn't only much more clear and readable,

Not even remotely. I can't see any difference in readability and I think many people would agree with me. Semicolons are a crappy cop-out for the compiler to know when the line ends.

Quote:

Originally Posted by SnoW (Post 961146)
[...] but also the horrible thing that you are somehow limited to invisible lines is gone. When you see in chars where the statements end and the code can be even in one line I can't do anything but use semicolons.

In my over four years now using Pawn, I have never once that I can recall needed multiple lines for a single expression. The use of semicolons doesn't even "fix" it, anyway; you can use multiple lines for single expressions without them.

The fact that you can't deny is that using semicolons creates extra work for you. I'm arguing that the work you do is pointless and is a result of the "archaic" Java/C style that you're, ironically, advocating staying away from.

SnoW 10-14-2009 05:16

Re: Blocking Buy Commands (Basic)
 
Quote:

Originally Posted by Hawk552 (Post 961170)
Well, no. Inefficiency is real and is not a matter of opinions.

Umm... Maybe I understood wrong, but where was the inefficiency? The both ways should equal and one shouldn't be more efficient than one.
Quote:

Originally Posted by Hawk552 (Post 961170)
Not even remotely. I can't see any difference in readability and I think many people would agree with me. Semicolons are a crappy cop-out for the compiler to know when the line ends.

Many will agree with you, but I guess many will agree with me as well, maybe the ones who use semicolons? It's maybe more readable for me as I've got used to it, but I don't see why I need there a reason. It's just how it is. Somehow I don't see a reason how using start assigment would be any readable to the people who use it.

Quote:

Originally Posted by Hawk552 (Post 961170)
In my over four years now using Pawn, I have never once that I can recall needed multiple lines for a single expression. The use of semicolons doesn't even "fix" it, anyway; you can use multiple lines for single expressions without them.

But you can't many in a single line. Which I think in following situation when using "everyone know statement", looks even better than in two lines.
PHP Code:

new Floathealthpevindexpev_heathhealth );
//... 

Quote:

Originally Posted by Hawk552 (Post 961170)
The fact that you can't deny is that using semicolons creates extra work for you. I'm arguing that the work you do is pointless and is a result of the "archaic" Java/C style that you're, ironically, advocating staying away from.

It can actually be that the first lang in I used semicolons was pawn. You could compare the extra work to adding a "g" before global variables or even naming variables with long names just to make the code readable. This is still what you do as well I believe.

Hawk552 10-14-2009 09:24

Re: Blocking Buy Commands (Basic)
 
Quote:

Originally Posted by SnoW (Post 961455)
Umm... Maybe I understood wrong, but where was the inefficiency? The both ways should equal and one shouldn't be more efficient than one.

Okay... let me put this very simply. Which one of these takes longer to type?

PHP Code:



PHP Code:

 

Clearly, the first one does. Thus, if you cannot justify the extra work, using semicolons is inefficient. Multiply this by a few hundred times for any reasonable plugin, or a few thousand times for any big one, and you have a massive inefficiency problem here which is significantly bigger than the arguably inefficient explicit initialization of looping variables and iterators.

Quote:

Originally Posted by SnoW (Post 961455)
Many will agree with you, but I guess many will agree with me as well, maybe the ones who use semicolons? It's maybe more readable for me as I've got used to it, but I don't see why I need there a reason. It's just how it is. Somehow I don't see a reason how using start assigment would be any readable to the people who use it.

All action requires a reason or it is irrational. The readability was not my point in the first place; I was just stating that it's not as readable as you think in response to your claim that it looks nicer.

As for the initialization, I already explained that it can be more readable (although I don't do it) since it's clearly stating what a variable will contain without implying it and without costing any extra resources or introducing backwards compatibility problems.

Quote:

Originally Posted by SnoW (Post 961455)
But you can't many in a single line. Which I think in following situation when using "everyone know statement", looks even better than in two lines.
PHP Code:

new Floathealthpevindexpev_heathhealth );
//... 


That is terrible programming and is one of the first things that they teach you not to do in computer science/programming/electrical/whatever 101.

I mean, we can detag floats like this to use them as integers:

PHP Code:

new Float:temp
temp 
Float:get_user_fragsid )
client_printidprint_chat"Your frags are %d"temp 

But is this really a good idea? Would you really come to the conclusion, based on the code I have given above, that detagging incorrectly tagged variables is good/useful just because we can do it? Of course you wouldn't.

Quote:

Originally Posted by SnoW (Post 961455)
It can actually be that the first lang in I used semicolons was pawn. You could compare the extra work to adding a "g" before global variables or even naming variables with long names just to make the code readable. This is still what you do as well I believe.

This is a terrible comparison. Tagging variables with "g" is actually useful as it provides information that you can't see on first glance without it. I automatically know where the end of a line is without a semicolon, but if I'm looking through a block of code that is unfamiliar, I won't know what is global and what isn't. Giving variables long names is also nothing like using semicolons; it again provides useful information that you won't find on first glance without it. So no, what you're saying is not what I believe.


All times are GMT -4. The time now is 13:20.

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