Page 2 of 2
Re: Pass by reference
Posted: Thu Apr 16, 2009 8:33 pm
by USCode
Demivec wrote:In looking at the examples you provided nothing you did made the code any easier to read. The ways that you suggested to make it easier to write seemed to only involve exchanging the "@" character for an "&" character. That hardly seems helpful or worthwhile.
Looking at Mistral's first 2 examples in his original post, utilizing the pass by reference character "&" seems much easier IMHO than using @ and pointers in the second example.
Clearly this:
Code: Select all
Procedure That(&This)
This=2
EndProcedure
That(This)
Debug This
Is simpler than this:
Code: Select all
Procedure That(*This.Integer)
*This\i=2
EndProcedure
That(@This)
Debug This
Posted: Thu Apr 16, 2009 8:40 pm
by Kaeru Gaman
USCode wrote:Clearly this:
...
Is simpler than this:
...
Kaeru Gaman wrote:working with structured pointers make it ALWAYS clearly visible that you are handling a byRef Value and no local Variable....
in your second example, wich is only nanometers shorter, it not self evident in Line 2 wich kind of Variable it is.
there is no way to tell by this line only that it is not access byVal.
... in the example that shows how it is now, you
can clearly see that it is a Reference.
Re: Pass by reference
Posted: Fri Apr 17, 2009 10:18 am
by Psychophanta
Demivec is very right here, as usual.
USCode wrote:
Clearly this:
Code: Select all
Procedure That(&This)
This=2
EndProcedure
That(This)
Debug This
Is simpler than this:
Code: Select all
Procedure That(*This.Integer)
*This\i=2
EndProcedure
That(@This)
Debug This
Very obscure clairvoyance, indeed.
Kaeru and Demivec explains quite well, don't need for me to say samethings.
Posted: Fri Apr 17, 2009 7:29 pm
by USCode
In my personal past experiences coding with Delphi and VB I've found a by-reference operator to be very useful and not confusing at all but I guess it's all academic as it's ultimately up to Fred and as he hasn't added that feature to the language yet expresses his opinion on the subject...

Posted: Wed Apr 22, 2009 7:13 pm
by Lewis
I believe
this conversation is quite similar to the one in hand:
HTH.
Re: Pass by reference
Posted: Thu Oct 07, 2010 8:40 am
by buddymatkona
The option to pass variables ByRef would make PureBasic much friendlier and probably increase the user base. I know people would hate it if
X = Pow(X, 3.0)
would not work unless X was part of a structure. I feel the same way about Procedure ModifyABCD(A,B,C,D).
Re: Pass by reference
Posted: Wed Jun 03, 2020 4:06 pm
by Naampie2000
I came across this topic searching this,
Wouldn't it be much simpler to pass by reference by default and yust move the value into a named varaible like so?
Code: Select all
DeclareModule featurerequest
Declare Ar
EndDeclareModule
Module featurerequest (a,b,c) ;<-byreference
Ar = a ;<- byvalue
EndModule
Re: Pass by reference
Posted: Thu Jun 04, 2020 9:56 am
by Naampie2000
Hi,
I want to strengthen my case a little bit, my code always uses the ByRef keyword on 99.999% of the code.
And most of my modules are fire and forget. Even in cases where it matters to have a discrete variable, it's hardly inside the module body
for where it should require a discrete instance of the module.
Code: Select all
Module counter (ByRef register, ByRef increment)
register = register + increment
EndModule
Define CountA
counter (CountA, somevar)
;CountA = updated
Code: Select all
DeclareModule counter
Define register
EndDeclareModule
Module counter (byref increment)
register = register + increment
EndModule
counterN (somevar) ; <- needs a unique instance of counter
Being used to this, it would be hard to look back,
And would be like having a dinner at a fancy restaurant getting every meal prewrapped to go, for the rarest case people just up and leave the well suited establishment.. in order to "return".
I would really like a feature like this, maybe in order to have it backwards compatible in the form of a derivative?
Kind regards,
Re: Pass by reference
Posted: Thu Jun 04, 2020 10:37 am
by NicTheQuick
This is not Purebasic code you are talking about.
Also I don't understand what your point should be.

Re: Pass by reference
Posted: Thu Jun 04, 2020 11:44 am
by Naampie2000
The code is written as a feature request,
Why things could be passed by reference "by default" in my oppinion, is my code simply looks like that.
Else there's the way of using the module header for discrete variable declaration.
In order to do the module as it stands, every pointer passed to it is converted to a move instruction into a discrete register.
Which you can resolve by proceding to undo it by butchering your syntax by putting * and \ everywhere.
Which has the drawback of producing semi legible "slow by default" code and some extra work to make it.
The other way around, "with the header passing pointers by default" or having byref syntax like &.
None of these syntax issues exist. And the rare case of a move instruction being needed, you can declare and move a variable.
The pro's of doing this are writing fast code fast and legible.
The only con I can think of is backwards compatability, but even that may not be so much of an issue.
So if it was a left side opperand it was bound to change anyway.