digitalmars.D - Damn C++ and damn D!
- so (18/18) Feb 05 2012 After some time with D, C++ is now a nightmare for me. (especially on
- Timon Gehr (13/31) Feb 05 2012 This should work:
- so (5/17) Feb 05 2012 It won't work.
- Timon Gehr (4/24) Feb 05 2012 It certainly has limits. I completely agree that C++s generic
- Jose Armando Garcia (17/46) Feb 05 2012 What I would really like to see in D is:
- so (14/34) Feb 05 2012 What am i missing?
- Jose Armando Garcia (18/50) Feb 05 2012 First, 'static if' is evaluated at compile time while 'if' is valuated
- Timon Gehr (6/58) Feb 05 2012 immutable variable = (boolean_condition) ? {
- Jose Armando Garcia (3/71) Feb 05 2012 Cool, now I want some syntactic sugar ;). I write this all the time!
- Andrei Alexandrescu (3/12) Feb 05 2012 Make it a function.
- Jose Armando Garcia (11/26) Feb 05 2012 I agree that in theory that you can do all this stuff in D but the
- Andrei Alexandrescu (7/35) Feb 05 2012 I agree with the general argument but I find it disconnected from the
- Michel Fortin (14/20) Feb 05 2012 Make it a function literal:
- so (10/12) Feb 05 2012 1. When actual part of the work lies in the macro.
- Kai Meyer (2/29) Feb 10 2012
- Timon Gehr (2/35) Feb 10 2012 Won't work. Or am I missing something?
- Jonathan M Davis (5/25) Feb 05 2012 So, basically, D does it way better than C++, but you're forced to conti...
- deadalnix (2/27) Feb 06 2012 Hopefully, we have compiler/phobos bugs to force us to get back to C++.
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.
Feb 05 2012
On 02/05/2012 02:49 PM, 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.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; } }
Feb 05 2012
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. And this grows exponentially for every new condition you have.
Feb 05 2012
On 02/05/2012 03:53 PM, so wrote:On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:You just maintain the macro.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.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.
Feb 05 2012
On Sun, Feb 5, 2012 at 12:57 PM, Timon Gehr <timon.gehr gmx.ch> wrote:On 02/05/2012 03:53 PM, so wrote:What I would really like to see in D is: immutable variable =3D if (boolean_condition) { // initialize based on boolean_condition being true } else { // initialize based on boolean_condition being false } Scala has this and find it indispensable for functional and/or immutable programming. Yes, I have been programming with Scala a lot lately. It has a lot of problem but it has some really cool constructs like the one above. Scala also has pattern matching and structural typing but that may be asking too much ;). I am not sure what it would take to implement this in D but I am thinking we need the concept of a void type (Unit in scala). Thoughts?On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:You just maintain the macro.This should work: #define DOTDOTDOT ... template<class T> void fun(T a){ if(cond<T>::value) { auto var =3D make(a); DOTDOTDOT; }else{ auto tmp =3D make(a); auto var =3D 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. =A0Now you have to maintain both of them.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.
Feb 05 2012
On Sunday, 5 February 2012 at 15:17:39 UTC, Jose Armando Garcia wrote:What I would really like to see in D is: immutable variable = if (boolean condition) { // initialize based on boolean condition being true } else { // initialize based on boolean condition being false } Scala has this and find it indispensable for functional and/or immutable programming. Yes, I have been programming with Scala a lot lately. It has a lot of problem but it has some really cool constructs like the one above. Scala also has pattern matching and structural typing but that may be asking too much ;). I am not sure what it would take to implement this in D but I am thinking we need the concept of a void type (Unit in scala). Thoughts?What am i missing? I can't see the difference between that and "static if". static if (boolean condition) { // initialize based on boolean condition being true immutable variable = ... } else { // initialize based on boolean condition being false immutable variable = ... }
Feb 05 2012
On Sun, Feb 5, 2012 at 1:24 PM, so <so so.so> wrote:On Sunday, 5 February 2012 at 15:17:39 UTC, Jose Armando Garcia wrote:First, 'static if' is evaluated at compile time while 'if' is valuated at runtime. Second 'if' in D is a statement while in Scala it is a expression think of it as a more powerful (more readable) version of the ternary operator ?:. In theory in Scala you need to write: auto variable =3D if (true) { 1 } else { 2 }; but Scala can implicitly derive the ';'. Thanks, -Jose PS. static if works in your case because "... static if is not only a statement but also a declaration." -The D Programming LanguageWhat I would really like to see in D is: immutable variable =3D if (boolean condition) { // initialize based on boolean condition being true } else { // initialize based on boolean condition being false } Scala has this and find it indispensable for functional and/or immutable programming. Yes, I have been programming with Scala a lot lately. It has a lot of problem but it has some really cool constructs like the one above. Scala also has pattern matching and structural typing but that may be asking too much ;). I am not sure what it would take to implement this in D but I am thinking we need the concept of a void type (Unit in scala). Thoughts?What am i missing? I can't see the difference between that and "static if". static if (boolean condition) { =A0// initialize based on boolean condition being true =A0immutable variable =3D ... } else { =A0// initialize based on boolean condition being false =A0immutable variable =3D ... }
Feb 05 2012
On 02/05/2012 04:17 PM, Jose Armando Garcia wrote:On Sun, Feb 5, 2012 at 12:57 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 }();On 02/05/2012 03:53 PM, so wrote:What I would really like to see in D is: immutable variable = if (boolean_condition) { // initialize based on boolean_condition being true } else { // initialize based on boolean_condition being false } Scala has this and find it indispensable for functional and/or immutable programming. Yes, I have been programming with Scala a lot lately. It has a lot of problem but it has some really cool constructs like the one above. Scala also has pattern matching and structural typing but that may be asking too much ;). I am not sure what it would take to implement this in D but I am thinking we need the concept of a void type (Unit in scala). Thoughts?On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:You just maintain the macro.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.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.
Feb 05 2012
On Sun, Feb 5, 2012 at 1:44 PM, Timon Gehr <timon.gehr gmx.ch> wrote:On 02/05/2012 04:17 PM, Jose Armando Garcia wrote:ngOn Sun, Feb 5, 2012 at 12:57 PM, Timon Gehr<timon.gehr gmx.ch> =A0wrote:On 02/05/2012 03:53 PM, so wrote:On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:You just maintain the macro.This should work: #define DOTDOTDOT ... template<class T> =A0void fun(T a){ if(cond<T>::value) { auto var =3D make(a); DOTDOTDOT; }else{ auto tmp =3D make(a); auto var =3D 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. =A0Now you have to maintain both of them.And this grows exponentially for every new condition you have.It certainly has limits. I completely agree that C++s generic programmi=Cool, now I want some syntactic sugar ;). I write this all the time!immutable variable =3D (boolean_condition) ? { =A0 =A0// initialize based on boolean_condition being true }():{ =A0 =A0// initialize based on boolean_condition being false }();facilities are severely underpowered.What I would really like to see in D is: immutable variable =3D if (boolean_condition) { =A0 // initialize based on boolean_condition being true } else { =A0 // initialize based on boolean_condition being false } Scala has this and find it indispensable for functional and/or immutable programming. Yes, I have been programming with Scala a lot lately. It has a lot of problem but it has some really cool constructs like the one above. Scala also has pattern matching and structural typing but that may be asking too much ;). I am not sure what it would take to implement this in D but I am thinking we need the concept of a void type (Unit in scala). Thoughts?
Feb 05 2012
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:Make it a function. Andreiimmutable 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!
Feb 05 2012
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: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=3D-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... -JoseOn Sun, Feb 5, 2012 at 1:44 PM, Timon Gehr<timon.gehr gmx.ch> =A0wrote:Make it a function.immutable variable =3D (boolean_condition) ? { =A0 =A0// initialize based on boolean_condition being true }():{ =A0 =A0// initialize based on boolean_condition being false }();Cool, now I want some syntactic sugar ;). I write this all the time!Andrei
Feb 05 2012
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: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.On 2/5/12 9:57 AM, Jose Armando Garcia wrote: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.On Sun, Feb 5, 2012 at 1:44 PM, Timon Gehr<timon.gehr gmx.ch> wrote:Make it a function.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!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
Feb 05 2012
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 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/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.
Feb 05 2012
On Sunday, 5 February 2012 at 14:57:58 UTC, Timon Gehr wrote:On 02/05/2012 03:53 PM, so wrote: You just maintain the macro.1. When actual part of the work lies in the macro. #define DETAIL \ ... \ ... \ ... You now have an enigma and compiler won't help you. 2. And if you need another condition. Another macro? Just imagine the situation! Maybe small but branching also creates overhead.
Feb 05 2012
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:You just maintain the macro.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.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.
Feb 10 2012
On 02/10/2012 06:49 PM, Kai Meyer wrote:On 02/05/2012 07:57 AM, Timon Gehr wrote:Won't work. Or am I missing something?On 02/05/2012 03:53 PM, so wrote:lambda instead of macro?On Sunday, 5 February 2012 at 14:24:20 UTC, Timon Gehr wrote:You just maintain the macro.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.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.
Feb 10 2012
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
Feb 05 2012
Le 06/02/2012 01:09, Jonathan M Davis a écrit :On Sunday, February 05, 2012 15:49:04 so wrote:Hopefully, we have compiler/phobos bugs to force us to get back to C++.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
Feb 06 2012