www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - function parameters: is it possible to pass byref ... while being

reply someone <someone somewhere.com> writes:
The following gives me a compiler error when I add the second 
parameter:
is not an lvalue and cannot be modified

```d
public bool add(
    ref classTickerID robjTickerID,
    ref classExchanges robjExchanges = null /// needing this 
optional
    ) {

}
```

If I take out the null then the parameter is assumed mandatory of 
course.
Jul 17
next sibling parent reply Adam Ruppe <destructionator gmail.com> writes:
On Saturday, 17 July 2021 at 20:49:58 UTC, someone wrote:
    ref classTickerID robjTickerID
Why are you using ref here at all? You probably shouldn't be using it. But if it is legitimately needed you can do a pointer instead of ref.
Jul 17
parent someone <someone somewhere.com> writes:
On Saturday, 17 July 2021 at 21:02:38 UTC, Adam Ruppe wrote:

 Why are you using ref here at all?
Muscle memory I suppose; objects need to be passed by reference, these are the things I'll need to be re-wired to in D.
 You probably shouldn't be using it. But if it is legitimately 
 needed you can do a pointer instead of ref.
No. Nothing special at all here.
Jul 17
prev sibling parent reply Jack Applegame <japplegame gmail.com> writes:
On Saturday, 17 July 2021 at 20:49:58 UTC, someone wrote:
 The following gives me a compiler error when I add the second 
 parameter:
 is not an lvalue and cannot be modified

 ```d
 public bool add(
    ref classTickerID robjTickerID,
    ref classExchanges robjExchanges = null /// needing this 
 optional
    ) {

 }
 ```

 If I take out the null then the parameter is assumed mandatory 
 of course.
Just remove `ref`, because in D clasess themselves are references.
Jul 17
parent reply someone <someone somewhere.com> writes:
On Saturday, 17 July 2021 at 21:46:38 UTC, Jack Applegame wrote:

 Just remove `ref`, because in D clasess themselves are 
 references.
All refs are goners now; thanks :) !
Jul 17
parent reply zjh <fqbqrr 163.com> writes:
On Saturday, 17 July 2021 at 22:40:35 UTC, someone wrote:
 On Saturday, 17 July 2021 at 21:46:38 UTC, Jack Applegame wrote:
This must be `Forum Oriented Programming`.
Jul 17
parent reply Brian Tiffin <btiffin gnu.org> writes:
On Sunday, 18 July 2021 at 00:00:01 UTC, zjh wrote:
 On Saturday, 17 July 2021 at 22:40:35 UTC, someone wrote:
 On Saturday, 17 July 2021 at 21:46:38 UTC, Jack Applegame 
 wrote:
This must be `Forum Oriented Programming`.
It's our best hope. Self taught programming is scary. School taught programming is scary. Corporate taught programming is scary. *Practice makes perfect? No, practice makes permanent.* The sanest path forward for the profession is Peer taught programming, in public.
Jul 17
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 7/17/21 6:49 PM, Brian Tiffin wrote:

 *Practice makes perfect?  No, practice makes permanent.*
One reference for that quote is "Classical Guitar Pedagogy" by Anthony Glise, Chapter Nine--Practicing. ;) Ali
Jul 17
prev sibling parent reply someone <someone somewhere.com> writes:
On Sunday, 18 July 2021 at 01:49:11 UTC, Brian Tiffin wrote:

 It's our best hope. Self taught programming is scary.  School 
 taught programming is scary.  Corporate taught programming is 
 scary.  *Practice makes perfect?  No, practice makes permanent.*

 The sanest path forward for the profession is Peer taught 
 programming, in public.
I am a self-taught programmer well before college, furthermore, I am *almost* a self-taught guy in everything that interests me (albeit the fact that I have a degree in electronics engineering), but I am *not*, in *any way*, ashamed to ask anything no matter the issue, I have no pride when I am asking questions, I am not ashamed to answer no when I don't have the answer, I want to learn, and to teach whenever I feel I have and edge on something. That being said, one of the things that I felt in love with when I was first exposed to was OOP; with all its pros and cons. OOP made me a far better programmer than I was before. And it was not in college nor anywhere near to, it was on one of my first jobs as a developer at a financial institution which by the time back in the early 90s was using a database manager called FoxPro wich evolved to Visual FoxPro by the time Microsoft bought it and it was fully OOP from top to bottom and was far ahead of similar tools of the era, so far ahead in the language and flexibility and speed that a few years after it was released Microsoft killed it because a lot of companies were doing serious business with it while *not buying* Microsoft's star-database, SQL Server, which obviously was far far expensive. It was with this tool that I learned primarily to encapsulate everything -and it payed off; code quality using OOP was far superior. These were my humble origins to OOP far away from things like LISP and what-not that I didn't know they even existed. C++ came afterward with all its complexity and 50% of the guys loving it and the other 50% hating it with passion. I don't know of any other language so divisive than C++. And no, I don't love it nor hate it, I respect it, it is powerful, the problem with C++ is that anyone writing code with it feels the need to show you how big has his ... and you came across constructions that seem complex puzzles; so, in practice, unless you have some guidelines cast in stone at company level, you end fighting the language, or more precisely, the ones coding with the language.
Jul 17
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 7/17/21 8:52 PM, someone wrote:

 I am a self-taught programmer
Same here.
 well before college
Not here because I had access to a Sinclair Spectrum only in 1985. :/
 I have a degree in electronics engineering
Same here.
 one of the things that I felt in love with when I was first exposed=20
to was OOP; with all its pros and cons I learned it with C++. Then I realized that it wasn't much used in D.=20 The following two presentations made me leave it completely behind=20 unless a simple class hierarchy is really necessary. 1) Our friend Lu=C3=ADs Marques presented the following at one of our loc= al=20 meetups. (He was distant. :) ) http://files.meetup.com/18234529/luis_marques_anemic_domain_models.pdf= That presentation concludes that anemic domain models are better than=20 rich design models. An interesting question from the presentation to all OOP people is "How=20 might you design a program that lets people play Monopoly with each=20 other over the internet?" Very eye opening! 2) Our "open methods" friend Jean-Louis Leroy concludes that OOP took a=20 wrong path in programming language history: https://dconf.org/2018/talks/leroy.html It starts with the "expression problem" (which is *not* about=20 "expressions").
 it was on one of my first jobs as a developer at a financial=20
institution which by the time back in the early 90s was
 using a database manager called FoxPro
Same here! :) I learned and programmed in FoxPro for my first job in the = US, in Sausalito, CA in 1994. I was maintaining and improving an order=20 entry, invoicing, inventory, etc. system. I had not even heard about OOP back then to know whether FoxPro was good = at it. :)
 It was with this tool that I learned primarily to encapsulate everythi=
ng
 -and it payed off; code quality using OOP was far superior.
Ah! OOP carries many meanings with it. Yes, encapsulation is important,=20 which I take less advantage of as I gain experience. :) (I am going=20 backward!) But I left "everything is an object" mantra way back in my=20 programming history. Pffft!
 C++ came afterward with all its complexity and 50% of the guys loving
 it
I've been one of those.
 I respect it, it is powerful, the
 problem with C++ is that anyone writing code with it feels the need to=
 show you how big has his ...
That. I've been there myself and I am pretty sure most of the brain power that = is attracted to C++ is there for the same reason. I asked a C++ speaker=20 why he was interested in C++ instead of one of the more modern languages = and he said "because it is hard".
 unless you have some guidelines cast in stone at company level
More than 400 rules in Core Guidelines alone... Add to that more=20 hundreds of MISRA, AUTOSAR, etc. standards. How can one expect=20 programmers to observe all of those rules? And only some of the=20 guidelines are machine-checkable. Anyway... Back to D... :) Ali
Jul 17
prev sibling parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 18 July 2021 at 03:52:30 UTC, someone wrote:
 That being said, one of the things that I felt in love with 
 when I was first exposed to was OOP; with all its pros and cons.
Yeah I like a lot about OOP and D's implementation is one of the nicest out there. Very competent implementation with a lot of nice bits. Totally underrated by most the D luminaries imo.
Jul 18
parent someone <someone somewhere.com> writes:
On Sunday, 18 July 2021 at 11:04:55 UTC, Adam D Ruppe wrote:
 On Sunday, 18 July 2021 at 03:52:30 UTC, someone wrote:
 That being said, one of the things that I felt in love with 
 when I was first exposed to was OOP; with all its pros and 
 cons.
Yeah I like a lot about OOP and D's implementation is one of the nicest out there. Very competent implementation with a lot of nice bits. Totally underrated by most the D luminaries imo.
I first touched D two months ago so it is probably too early for me to make the following assessment; but, all in all it didn't took too much time to grab the potential this language has, it is fucking powerful no matter how you look at it. I will not be elaborating further right now since this topic is not the place to, but, eventually I'll post my impressions so far; which translates more-or-less to the following: I'm here to stay :)
Jul 18