February 05, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jose Armando Garcia | On 2/5/12 9:57 AM, Jose Armando Garcia wrote:
> On Sun, Feb 5, 2012 at 1:44 PM, Timon Gehr<timon.gehr@gmx.ch> wrote:
>> immutable variable = (boolean_condition) ? {
>> // initialize based on boolean_condition being true
>> }():{
>> // initialize based on boolean_condition being false
>> }();
>>
>>
>
> Cool, now I want some syntactic sugar ;). I write this all the time!
Make it a function.
Andrei
|
February 05, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Sun, Feb 5, 2012 at 2:13 PM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote: > On 2/5/12 9:57 AM, Jose Armando Garcia wrote: >> >> On Sun, Feb 5, 2012 at 1:44 PM, Timon Gehr<timon.gehr@gmx.ch> wrote: >>> >>> immutable variable = (boolean_condition) ? { >>> // initialize based on boolean_condition being true >>> }():{ >>> // initialize based on boolean_condition being false >>> }(); >>> >>> >> >> Cool, now I want some syntactic sugar ;). I write this all the time! > > > Make it a function. > I agree that in theory that you can do all this stuff in D but the reality is that developers are lazy and end up fighting the language. It is probably true that in a well structure/abstracted program this is not a problem but the reality is that a lot programs don't start this way. I listen a very enlightening talk by Gilad Bracha the other day: https://www.youtube.com/watch?v=-IavVtOE_Fg. I still not ready to completely agree with him but I do see his point about a language getting out a programers way... -Jose > Andrei |
February 05, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jose Armando Garcia | On 2/5/12 10:25 AM, Jose Armando Garcia wrote: > On Sun, Feb 5, 2012 at 2:13 PM, Andrei Alexandrescu > <SeeWebsiteForEmail@erdani.org> wrote: >> On 2/5/12 9:57 AM, Jose Armando Garcia wrote: >>> >>> On Sun, Feb 5, 2012 at 1:44 PM, Timon Gehr<timon.gehr@gmx.ch> wrote: >>>> >>>> immutable variable = (boolean_condition) ? { >>>> // initialize based on boolean_condition being true >>>> }():{ >>>> // initialize based on boolean_condition being false >>>> }(); >>>> >>>> >>> >>> Cool, now I want some syntactic sugar ;). I write this all the time! >> >> >> Make it a function. >> > > I agree that in theory that you can do all this stuff in D but the > reality is that developers are lazy and end up fighting the language. > It is probably true that in a well structure/abstracted program this > is not a problem but the reality is that a lot programs don't start > this way. I agree with the general argument but I find it disconnected from the case in point. It's not "all this stuff", it's one little local thing, and I'd find it tenuous to claim that such a small difference in syntax actually matters for anything. > I listen a very enlightening talk by Gilad Bracha the other > day: https://www.youtube.com/watch?v=-IavVtOE_Fg. I still not ready to > completely agree with him but I do see his point about a language > getting out a programers way... I'll watch this, thanks. Andrei |
February 06, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to so | On Sunday, February 05, 2012 15:49:04 so wrote:
> After some time with D, C++ is now a nightmare for me. (especially on
> generic coding)
> Think about replicating this simple code in C++.
>
> void fun(T)(T a)
> {
> static if(cond(T))
> {
> auto var = make(a);
> }
> else
> {
> auto tmp = make(a);
> auto var = make_proxy(tmp);
> }
> ...
> }
>
> And this is just "one" condition.
> Damn D for introducing these and damn C++ committee for not adopting.
So, basically, D does it way better than C++, but you're forced to continue to use C++ after seeing how well D does it, and it's driving you crazy. Yeah, that happens to me a lot too.
- Jonathan M Davis
|
February 06, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jose Armando Garcia | On 2012-02-05 16:25:33 +0000, Jose Armando Garcia <jsancio@gmail.com> said: > On Sun, Feb 5, 2012 at 2:13 PM, Andrei Alexandrescu > <SeeWebsiteForEmail@erdani.org> wrote: >> Make it a function. > > I agree that in theory that you can do all this stuff in D but the > reality is that developers are lazy and end up fighting the language. Make it a function literal: immutable variable = { if (boolean_condition) return 1 else return 2; }(); The extra () at the end calls the literal immediately so that variable is assigned the result. -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ |
February 06, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | Le 06/02/2012 01:09, Jonathan M Davis a écrit :
> On Sunday, February 05, 2012 15:49:04 so wrote:
>> After some time with D, C++ is now a nightmare for me. (especially on
>> generic coding)
>> Think about replicating this simple code in C++.
>>
>> void fun(T)(T a)
>> {
>> static if(cond(T))
>> {
>> auto var = make(a);
>> }
>> else
>> {
>> auto tmp = make(a);
>> auto var = make_proxy(tmp);
>> }
>> ...
>> }
>>
>> And this is just "one" condition.
>> Damn D for introducing these and damn C++ committee for not adopting.
>
> So, basically, D does it way better than C++, but you're forced to continue to
> use C++ after seeing how well D does it, and it's driving you crazy. Yeah,
> that happens to me a lot too.
>
> - Jonathan M Davis
Hopefully, we have compiler/phobos bugs to force us to get back to C++.
|
February 10, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | lambda instead of macro?
On 02/05/2012 07:57 AM, Timon Gehr wrote:
> On 02/05/2012 03:53 PM, so wrote:
>> On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:
>>
>>> This should work:
>>>
>>> #define DOTDOTDOT ...
>>>
>>> template<class T> void fun(T a){
>>> if(cond<T>::value) {
>>> auto var = make(a);
>>> DOTDOTDOT;
>>> }else{
>>> auto tmp = make(a);
>>> auto var = make_proxy(tmp);
>>> DOTDOTDOT;
>>> }
>>> }
>>
>> It won't work.
>> You now have two scopes and you have to repeat every line after "var"
>> for both scopes. Now you have to maintain both of them.
>
> You just maintain the macro.
>
>> And this grows
>> exponentially for every new condition you have.
>>
>
> It certainly has limits. I completely agree that C++s generic
> programming facilities are severely underpowered.
>
|
February 10, 2012 Re: Damn C++ and damn D! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kai Meyer | On 02/10/2012 06:49 PM, Kai Meyer wrote:
> On 02/05/2012 07:57 AM, Timon Gehr wrote:
>> On 02/05/2012 03:53 PM, so wrote:
>>> On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:
>>>
>>>> This should work:
>>>>
>>>> #define DOTDOTDOT ...
>>>>
>>>> template<class T> void fun(T a){
>>>> if(cond<T>::value) {
>>>> auto var = make(a);
>>>> DOTDOTDOT;
>>>> }else{
>>>> auto tmp = make(a);
>>>> auto var = make_proxy(tmp);
>>>> DOTDOTDOT;
>>>> }
>>>> }
>>>
>>> It won't work.
>>> You now have two scopes and you have to repeat every line after "var"
>>> for both scopes. Now you have to maintain both of them.
>>
>> You just maintain the macro.
>>
>>> And this grows
>>> exponentially for every new condition you have.
>>>
>>
>> It certainly has limits. I completely agree that C++s generic
>> programming facilities are severely underpowered.
>>
>
> lambda instead of macro?
>
Won't work. Or am I missing something?
|
Copyright © 1999-2021 by the D Language Foundation