Jump to page: 1 2
Thread overview
What's the purpose of the 'in' keyword ?
May 27, 2018
loloof64
May 27, 2018
rikki cattermole
May 27, 2018
loloof64
May 27, 2018
Adam D. Ruppe
May 27, 2018
Russel Winder
May 27, 2018
Jonathan M Davis
May 28, 2018
eastanon
May 30, 2018
Q. Schroll
May 30, 2018
aberba
May 30, 2018
Ali Çehreli
May 31, 2018
Jonathan M Davis
May 31, 2018
Jonathan M Davis
May 27, 2018
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 28, 2018
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
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
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
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.

-- 
Russel.
=========================================
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
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 28, 2018
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 30, 2018
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
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
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
« First   ‹ Prev
1 2