digitalmars.D - Extend with to take multiple arguments
- Amex (9/9) Jun 04 2019 with(A){with(B){with(C){
- ag0aep6g (6/8) Jun 04 2019 You don't need the braces.
- Andrei Alexandrescu (2/12) Jun 05 2019 Wow this must be the shortest and most satisfying thread ever.
- 12345swordy (7/19) Jun 05 2019 tbh I found the with keyword to be unnecessarily verbiage. In C#
- Adam D. Ruppe (2/5) Jun 05 2019 What does that have to do with the `with` keyword?
- Laurent =?UTF-8?B?VHLDqWd1aWVy?= (8/13) Jun 06 2019 I think that what 12345swordy means is that in C#, you can
- Adam D. Ruppe (5/7) Jun 06 2019 Oh yeah, I see,
- Amex (16/30) Jun 06 2019 I don't use with just to initalize but many things... it cuts
- Bastiaan Veelo (5/9) Jun 05 2019 I don’t understand your point. How is that different from D?
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (22/33) Jun 06 2019 First, new Class has different capitalization, so it's not an
- 12345swordy (3/26) Jun 06 2019 Exactly, what I meant, thank you Simen.
- Bastiaan Veelo (10/35) Jun 06 2019 I see. I played with this a bit. Just for fun, there is an
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.
Jun 04 2019
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) { ... }
Jun 04 2019
On 6/5/19 1:15 AM, ag0aep6g wrote:On 05.06.19 02:57, Amex wrote:Wow this must be the shortest and most satisfying thread ever.with(A){with(B){with(C){ is quite annoying...You don't need the braces. with (A) with (B) with (C) { ... }
Jun 05 2019
On Wednesday, 5 June 2019 at 20:10:40 UTC, Andrei Alexandrescu wrote:On 6/5/19 1:15 AM, ag0aep6g wrote:you can initialize a class like this: var exp = new Class { }; That is just my opinion though. AlexOn 05.06.19 02:57, Amex wrote:Wow this must be the shortest and most satisfying thread ever.with(A){with(B){with(C){ is quite annoying...You don't need the braces. with (A) with (B) with (C) { ... }
Jun 05 2019
On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote:tbh I found the with keyword to be unnecessarily verbiage. In var exp = new Class { };What does that have to do with the `with` keyword?
Jun 05 2019
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: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.tbh I found the with keyword to be unnecessarily verbiage. In var exp = new Class { };What does that have to do with the `with` keyword?
Jun 06 2019
On Thursday, 6 June 2019 at 07:19:15 UTC, Laurent Tréguier wrote: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.
Jun 06 2019
On Thursday, 6 June 2019 at 07:19:15 UTC, Laurent Tréguier wrote:On Thursday, 6 June 2019 at 00:29:33 UTC, Adam D. Ruppe wrote:I don't use with just to initalize but many things... it cuts down having to specify a reference. with(XX) with(YY) { swith(q} { case a } if (b) foo(y) } } where q,a,b,y all come from XX and YY. Having to specify all the withs gets redundant(since it has to be done for each scope, I usually use it at the function level).On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote: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.tbh I found the with keyword to be unnecessarily verbiage. In var exp = new Class { };What does that have to do with the `with` keyword?
Jun 06 2019
On Wednesday, 5 June 2019 at 21:02:39 UTC, 12345swordy wrote:var exp = new Class { }; That is just my opinion though. AlexI don’t understand your point. How is that different from D? auto exp = new class {}; https://run.dlang.io/is/mupnDT Bastiaan.
Jun 05 2019
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: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"; } -- Simenvar exp = new Class { }; That is just my opinion though. AlexI don’t understand your point. How is that different from D? auto exp = new class {}; https://run.dlang.io/is/mupnDT Bastiaan.
Jun 06 2019
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:Exactly, what I meant, thank you Simen. Alex[...]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
Jun 06 2019
On Thursday, 6 June 2019 at 14:36:57 UTC, 12345swordy wrote:On Thursday, 6 June 2019 at 07:22:38 UTC, Simen Kjærås wrote:I see. I played with this a bit. Just for fun, there is an alternative without “with” and without repeating the object name. It’s not shorter nor prettier, and it’s not quite the same :-) Anyway: auto exp = new class Class { this() { n = 4; s = "foo"; } }; https://run.dlang.io/is/EcC8KK Bastiaan.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"; } -- SimenExactly, what I meant, thank you Simen. Alex
Jun 06 2019