Raised This Month: $12 Target: $400
 3% 

Dynamic Arrays in SourcePawn


Post New Thread Reply   
 
Thread Tools Display Modes
Steell
SourceMod Donor
Join Date: Mar 2009
Old 08-08-2012 , 14:14   Re: Dynamic Arrays in SourcePawn
Reply With Quote #31

Quote:
Originally Posted by BAILOPAN View Post
Note that arrays will always be passed by reference to functions no matter what, so you don't have to worry about that.
Right, but if we're using @ to denote array references when declaring new variables, then I feel that everywhere we're dealing with references we should also use @ to remain consistent; even though there's no functional point in including @ in function parameters, for example, new Sourcepawn 2 users will see function headers without @ for arrays and assume that they're passed by-value, since declaring new arrays without the @ means precisely that.

For proposal 4, if we include @ in function parameters for arrays, then although it's consistent and easier to read, it's extra work for the user writing the code. Since it's always pass-by-reference then we could always omit the @ in function parameters for arrays, but then it's syntactically inconsistent with array references everywhere else.

In summary: minor nitpicking about syntax.
__________________
Steell is offline
BAILOPAN
Join Date: Jan 2004
Old 08-08-2012 , 14:30   Re: Dynamic Arrays in SourcePawn
Reply With Quote #32

Quote:
Originally Posted by Steell View Post
Right, but if we're using @ to denote array references when declaring new variables, then I feel that everywhere we're dealing with references we should also use @ to remain consistent; even though there's no functional point in including @ in function parameters, for example, new Sourcepawn 2 users will see function headers without @ for arrays and assume that they're passed by-value, since declaring new arrays without the @ means precisely that.
I realize Proposal #4 was pretty light on details, so let me clarify. "@" would not a by-reference qualifier; it's a box that contains a value. Boxes would have no relation to arrays whatsoever. You could store boxes inside boxes, or scalars, etc.

Think of it like wrapping an array inside an object. You can re-point the box at another box, or you can change the value inside the box, but these are different from pass-by-reference. The box itself is a reference that contains a value or reference.

Whatever the case, I don't think it ever makes sense to pass arrays by value, and it would break almost every plugin in existence. The notion of "consistency" here doesn't factor in.
__________________
egg

Last edited by BAILOPAN; 08-08-2012 at 14:47.
BAILOPAN is offline
BAILOPAN
Join Date: Jan 2004
Old 08-08-2012 , 14:39   Re: Dynamic Arrays in SourcePawn
Reply With Quote #33

Some languages (like C#) distinguish "Value" types from "Reference" types, and they behave in that category under every condition. SourcePawn doesn't do that. Arrays are value types, (and structs will be too), but they are passed as references - in the former case because it makes the most sense, and in the latter case for performance. But scalar variables are value types and are passed as values. So the rule is basically "composite types are always passed as references."
__________________
egg

Last edited by BAILOPAN; 08-08-2012 at 14:40.
BAILOPAN is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-08-2012 , 15:02   Re: Dynamic Arrays in SourcePawn
Reply With Quote #34

Assuming this is for SourcePawn 2 or whatever it's going to be called, so existing SourceMod plugins will still keep its own language?

In that case I'd go for proposal 1 because it's simple and strict. Provide a helper function to get a copy of the array. Maybe something like this:

PHP Code:
new myArray[] = {123};
new 
secondArray[];

secondArray myArray.copyOf();

// copyOf creates a copy of the array and returns the reference to it. 
Maybe a better name than copyOf, but I suppose you get my point.

To me, the assignment operator only seems logical to use when you're assigning a single value (primitive or reference) to a variable. It doesn't seem right to assign a bunch of values at once, it's too magical.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 08-08-2012 at 15:06.
rhelgeby is offline
Send a message via MSN to rhelgeby
BAILOPAN
Join Date: Jan 2004
Old 08-08-2012 , 15:04   Re: Dynamic Arrays in SourcePawn
Reply With Quote #35

Quote:
Originally Posted by rhelgeby View Post
Assuming this is for SourcePawn 2 or whatever it's going to be called, so existing SourceMod plugins will still keep its own language?

In that case I'd go for proposal 1 because it's simple and strict. Provide a helper function to get a copy of the array.

To me, the assignment operator only seems logical to use when you're assigning a single value (primitive or reference) to a variable. It doesn't seem right to assign a bunch of values at once, it's too magical.
There is only one language: SourcePawn. These proposals are changes to the existing language, to be implemented in a new runtime.

(re: too magical, I agree - there are severe performance faults lurking there if someone isn't careful...)
__________________
egg

Last edited by BAILOPAN; 08-08-2012 at 15:05.
BAILOPAN is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-08-2012 , 15:07   Re: Dynamic Arrays in SourcePawn
Reply With Quote #36

See my post again with the new copyOf stuff. How about something like that?
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
BAILOPAN
Join Date: Jan 2004
Old 08-08-2012 , 15:24   Re: Dynamic Arrays in SourcePawn
Reply With Quote #37

For sure, in a proposal #1 scenario, I think it makes a lot of sense to have a clone mechanism on arrays.
__________________
egg
BAILOPAN is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 08-20-2012 , 18:13   Re: Dynamic Arrays in SourcePawn
Reply With Quote #38

Imho:
PHP Code:
new array[];
array.
push(); //add default initialized cell to array
array.push(5); //add cell containing 5 to array
array.pop();
array.
resize(10); //change the size of array to 10, if it's bigger than old size, default initialize new elements.
array.resize(105); //same but fill new elements with 5 
__________________
FaTony is offline
ShufflexDD
Senior Member
Join Date: Apr 2011
Location: :noitaɔo˩
Old 10-20-2012 , 08:19   Re: Dynamic Arrays in SourcePawn
Reply With Quote #39

hmm, why in every way I get a lot of errors?

omg, it's just a proposal
__________________

⇈⇈⇈⇈⇈⇈⇈⇈⇈⇈⇈⇈⇈⇈⇈
Check this website and find out how many functions
it has working with game server together.

Last edited by ShufflexDD; 10-20-2012 at 08:59.
ShufflexDD is offline
Send a message via ICQ to ShufflexDD Send a message via Skype™ to ShufflexDD
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 10-20-2012 , 14:25   Re: Dynamic Arrays in SourcePawn
Reply With Quote #40

Quote:
Originally Posted by ShufflexDD View Post
hmm, why in every way I get a lot of errors?
Because we're talking about things that don't exist yet.
__________________
11530 is offline
Reply


Thread Tools
Display Modes

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 14:16.


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