www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What's the purpose of the 'in' keyword ?

reply loloof64 <laurent.bernabe gmail.com> writes:
Hello everyone,

I've just completed the language tour, and I am starting a 
tutorial in order to use Gtk binding.

But somewhere, they use the 'in' keyword for the constructor : 
(https://sites.google.com/site/gtkdtutorial/#chapter2 : in 
section 3 for Buttons and Callbacks, main.d snippet).

What's the purpose of this 'in' keyword ? I could not process a 
good Google request to get an answer.

Regards
May 27 2018
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 28/05/2018 1:02 AM, loloof64 wrote:
 Hello everyone,
 
 I've just completed the language tour, and I am starting a tutorial in 
 order to use Gtk binding.
 
 But somewhere, they use the 'in' keyword for the constructor : 
 (https://sites.google.com/site/gtkdtutorial/#chapter2 : in section 3 for 
 Buttons and Callbacks, main.d snippet).
 
 What's the purpose of this 'in' keyword ? I could not process a good 
 Google request to get an answer.
 
 Regards
https://dlang.org/spec/function.html#parameters
May 27 2018
parent loloof64 <laurent.bernabe gmail.com> writes:
On Sunday, 27 May 2018 at 13:04:54 UTC, rikki cattermole wrote:
 On 28/05/2018 1:02 AM, loloof64 wrote:
 Hello everyone,
 
 I've just completed the language tour, and I am starting a 
 tutorial in order to use Gtk binding.
 
 But somewhere, they use the 'in' keyword for the constructor : 
 (https://sites.google.com/site/gtkdtutorial/#chapter2 : in 
 section 3 for Buttons and Callbacks, main.d snippet).
 
 What's the purpose of this 'in' keyword ? I could not process 
 a good Google request to get an answer.
 
 Regards
https://dlang.org/spec/function.html#parameters
Thank you very much : I'm going to look at it right now.
May 27 2018
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 27 May 2018 at 13:02:23 UTC, loloof64 wrote:
 What's the purpose of this 'in' keyword ? I could not process a 
 good Google request to get an answer.
It means you are taking the parameter in to look at, but not modify or store. Basically "const". (well, for now, literally "const" but that can change with other details)
May 27 2018
next sibling parent Russel Winder <russel winder.org.uk> writes:
On Sun, 2018-05-27 at 13:10 +0000, Adam D. Ruppe via Digitalmars-d-learn
wrote:
 On Sunday, 27 May 2018 at 13:02:23 UTC, loloof64 wrote:
 What's the purpose of this 'in' keyword ? I could not process a=20
 good Google request to get an answer.
=20 It means you are taking the parameter in to look at, but not=20 modify or store. =20 Basically "const". (well, for now, literally "const" but that can=20 change with other details)
Is there an easy set of "rules" as to when to use 'const' and when to use 'in'? In a situation where there are multiple ways of expressing the same concept there needs to be idioms to guide people to do the right thing in a given context. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t:+44 20 7585 2200 41 Buckmaster Road m:+44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 27 2018
prev sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn 
wrote:
 On Sun, 2018-05-27 at 13:10 +0000, Adam D. Ruppe via Digitalmars-d-learn

 wrote:
 On Sunday, 27 May 2018 at 13:02:23 UTC, loloof64 wrote:
 What's the purpose of this 'in' keyword ? I could not process a
 good Google request to get an answer.
It means you are taking the parameter in to look at, but not modify or store. Basically "const". (well, for now, literally "const" but that can change with other details)
Is there an easy set of "rules" as to when to use 'const' and when to use 'in'? In a situation where there are multiple ways of expressing the same concept there needs to be idioms to guide people to do the right thing in a given context.
Honestly, I'd suggest that folks never use in at this point. There's zero benefit to it. In principle, in was supposed to be const scope, but scope has never really done anything for anything other than delegates, so there has been no reason to use it over const. However, many folks seem to like it based on the idea that it was the opposite of out - and some folks used it based n what they expected scope to end up meaning whenever it finally got implemented for more than just delegates. Either way, it didn't actually buy them anything as long as scope has done nothing. Now with DIP 1000, scope is actually starting to mean something, but there's the concern that enabling scope for all of the places that in was used would break a lot of code. So, the spec now says that in means const rather than const scope, and as I undertand it, for the most part, the compiler doesn't treat it as scope anywhere aside from a a few buggy cases (even when -dip1000 is used). Some folks are not happy about that, and the situation may yet change (heck, we haven't even figured out how to switch to -dip1000 being the default without breaking everyone in the process yet - e.g. it's not ABI compatible with code that's not compiled with -dip1000, because it mangles differently). So, we can't really say what in is going to end up meaning when the dust settles. Ultimately, it may permanently just be const, or it may end up actually being const scope. But it's never actually bought you anything over using const (other than being shorted), and if it does end up becoming const scope, you're almost certainly going to have to fix a lot of the code that you wrote using in. So, I really don't think that it's a good idea to use in at all, but there are definitely folks who disagree with me, some of whom very much hope that it ends up meaning const scope and who want it to break their code if/when it does if there's any kind of escaping in their code - though given how confusing -dip1000 seems to be for many folks, I seriously question that much code using in would just work if it's changed to properly mean const scope or that all that many programmers using in understand scope well enough to use it correctly. - Jonathan M Davis
May 27 2018
next sibling parent eastanon <biorelated gmail.com> writes:
On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
 On Sunday, May 27, 2018 16:28:56 Russel Winder via 
 Digitalmars-d-learn wrote:
 [...]
Honestly, I'd suggest that folks never use in at this point. There's zero benefit to it. In principle, in was supposed to be const scope, but scope has never really done anything for anything other than delegates, so there has been no reason to use it over const. However, many folks seem to like it based on the idea that it was the opposite of out - and some folks used it based n what they expected scope to end up meaning whenever it finally got implemented for more than just delegates. Either way, it didn't actually buy them anything as long as scope has done nothing. [...]
I really find these type of descriptions to be really useful and insightful. Going through the D textbooks can leave someone a little confused on when to use what and where? D has so many keywords and as a beginner it can be overwhelming. Thank you for your insights.
May 28 2018
prev sibling next sibling parent Q. Schroll <qs.il.paperinik gmail.com> writes:
On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
 [...]
 Honestly, I'd suggest that folks never use in at this point.
 There's zero benefit to it.
 [...]
Exactly. If you intend const, just write const. If you intend const scope, write const scope.
May 30 2018
prev sibling parent reply aberba <karabutaworld gmail.com> writes:
On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
 On Sunday, May 27, 2018 16:28:56 Russel Winder via 
 Digitalmars-d-learn wrote:
 On Sun, 2018-05-27 at 13:10 +0000, Adam D. Ruppe via 
 Digitalmars-d-learn
- Jonathan M Davis
Jonathan, which font were you using in your DConf powerpoint presentation for source code? It made the code look really nice...and also you have good naming skills.
May 30 2018
next sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 05/30/2018 03:16 PM, aberba wrote:
 On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
 On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn 
 wrote:
 On Sun, 2018-05-27 at 13:10 +0000, Adam D. Ruppe via Digitalmars-d-learn
- Jonathan M Davis
Jonathan, which font were you using in your DConf powerpoint presentation for source code? It made the code look really nice...and also you have good naming skills.
The pdf file has that information in it: http://www.identifont.com/similar?76H Ali
May 30 2018
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, May 30, 2018 15:28:53 Ali Çehreli via Digitalmars-d-learn 
wrote:
 On 05/30/2018 03:16 PM, aberba wrote:
 On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
 On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn

 wrote:
 On Sun, 2018-05-27 at 13:10 +0000, Adam D. Ruppe via
 Digitalmars-d-learn
- Jonathan M Davis
Jonathan, which font were you using in your DConf powerpoint presentation for source code? It made the code look really nice...and also you have good naming skills.
The pdf file has that information in it: http://www.identifont.com/similar?76H
Well, that's cool - especially since properly telling someone what the font was is kind of hard anyway, since I used latex to generate the slides, and you don't normally select a font directly with latex (rather, normally, you select a font family). I used the beamer package to generate the slides and the listings package for the code blocks. The code blocks were then configured to use \ttfamily for the font, so it's whatever gets selected for the ttfamily family of fonts. - Jonathan M Davis
May 30 2018
prev sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, May 30, 2018 22:16:28 aberba via Digitalmars-d-learn wrote:
 On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote:
 On Sunday, May 27, 2018 16:28:56 Russel Winder via

 Digitalmars-d-learn wrote:
 On Sun, 2018-05-27 at 13:10 +0000, Adam D. Ruppe via
 Digitalmars-d-learn
- Jonathan M Davis
Jonathan, which font were you using in your DConf powerpoint presentation for source code? It made the code look really nice...
I'd point you to my reply to Ali, since what he figured out will probably tell you better than I could.
 and also you have good naming skills.
Thanks. I'm glad that someone thinks so. Naming is pretty much the king of bikeshedding in programming, and I've been in far too many arguments on that topic before. Far too often, it seems like no matter what you name something, someone is going to think that the name is terrible. - Jonathan M Davis
May 30 2018