Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 05, 2019 Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
with(A){with(B){with(C){ is quite annoying... Rather, allow with(A,B,C){ Also, B is checked to come from A so one does not have to do with(A, A.B, A.B.C) also have an opWith which is similar to opDispatch for With overriding. |
June 05, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Amex | On 05.06.19 02:57, Amex wrote:
> with(A){with(B){with(C){
> is quite annoying...
You don't need the braces.
with (A) with (B) with (C)
{
...
}
|
June 05, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On 6/5/19 1:15 AM, ag0aep6g wrote:
> On 05.06.19 02:57, Amex wrote:
>> with(A){with(B){with(C){
>> is quite annoying...
>
> You don't need the braces.
>
> with (A) with (B) with (C)
> {
> ...
> }
Wow this must be the shortest and most satisfying thread ever.
|
June 05, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 5 June 2019 at 20:10:40 UTC, Andrei Alexandrescu wrote:
> On 6/5/19 1:15 AM, ag0aep6g wrote:
>> On 05.06.19 02:57, Amex wrote:
>>> with(A){with(B){with(C){
>>> is quite annoying...
>>
>> You don't need the braces.
>>
>> with (A) with (B) with (C)
>> {
>> ...
>> }
>
> Wow this must be the shortest and most satisfying thread ever.
tbh I found the with keyword to be unnecessarily verbiage. In C# you can initialize a class like this:
var exp = new Class { };
That is just my opinion though.
Alex
|
June 06, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to 12345swordy | On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote:
> tbh I found the with keyword to be unnecessarily verbiage. In C# you can initialize a class like this:
> var exp = new Class { };
What does that have to do with the `with` keyword?
|
June 06, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to 12345swordy | On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote: > In C# you can initialize a class like this: > var exp = new Class { }; > > That is just my opinion though. > > Alex I don’t understand your point. How is that different from D? auto exp = new class {}; https://run.dlang.io/is/mupnDT Bastiaan. |
June 06, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Thursday, 6 June 2019 at 00:29:33 UTC, Adam D. Ruppe wrote:
> On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote:
>> tbh I found the with keyword to be unnecessarily verbiage. In C# you can initialize a class like this:
>> var exp = new Class { };
>
> What does that have to do with the `with` keyword?
I think that what 12345swordy means is that in C#, you can directly initialize class members in the curly brackets:
var exp = new Something() {
SomeMember = 42
}
So you get shorter syntax to init class members, without the need for a "with" keyword.
|
June 06, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bastiaan Veelo | On Thursday, 6 June 2019 at 06:53:00 UTC, Bastiaan Veelo wrote:
> On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote:
>> In C# you can initialize a class like this:
>> var exp = new Class { };
>>
>> That is just my opinion though.
>>
>> Alex
>
> I don’t understand your point. How is that different from D?
>
> auto exp = new class {};
>
> https://run.dlang.io/is/mupnDT
>
> Bastiaan.
First, new Class has different capitalization, so it's not an anonymous class like in your code. Second, I believe 12345swordy omitted some parts of his intended code, so a more correct example would be:
class Class {
int n;
string s;
}
var exp = new Class { n = 4, s = "foo" };
This, D doesn't do. The equivalent would be:
class Class {
int n;
string s;
}
auto exp = new Class();
with (exp) {
n = 4;
s = "foo";
}
--
Simen
|
June 06, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laurent Tréguier | On Thursday, 6 June 2019 at 07:19:15 UTC, Laurent Tréguier wrote:
> I think that what 12345swordy means is that in C#, you can directly initialize class members in the curly brackets:
Oh yeah, I see,
I usually use with for existing things, like
with(MyEnum) ...
so it didn't come to my mind.
|
June 06, 2019 Re: Extend with to take multiple arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Thursday, 6 June 2019 at 07:22:38 UTC, Simen Kjærås wrote:
> On Thursday, 6 June 2019 at 06:53:00 UTC, Bastiaan Veelo wrote:
>> [...]
>
> First, new Class has different capitalization, so it's not an anonymous class like in your code. Second, I believe 12345swordy omitted some parts of his intended code, so a more correct example would be:
>
> class Class {
> int n;
> string s;
> }
>
> var exp = new Class { n = 4, s = "foo" };
>
> This, D doesn't do. The equivalent would be:
>
> class Class {
> int n;
> string s;
> }
>
> auto exp = new Class();
> with (exp) {
> n = 4;
> s = "foo";
> }
>
> --
> Simen
Exactly, what I meant, thank you Simen.
Alex
|
Copyright © 1999-2021 by the D Language Foundation