www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - The Language I Wish Go Was

reply Walter Bright <newshound2 digitalmars.com> writes:
http://news.ycombinator.com/item?id=1814887

Some commentary on D there.
Oct 21 2010
parent reply Juanjo Alvarez <fake fakeemail.com> writes:
On Thu, 21 Oct 2010 10:51:14 -0700, Walter Bright 
<newshound2 digitalmars.com> wrote:
 http://news.ycombinator.com/item?id=1814887
 Some commentary on D there.
I always enjoy a good rant about some language. When I'm intrigued by some language rants are the first things I google. I wish Go, sorry, D had named arguments too. Its a simple feature that nuke a trunkload of function overloading.
Oct 21 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Juanjo Alvarez:

 I wish Go, sorry, D had named arguments too. Its a simple feature 
 that nuke a trunkload of function overloading.
I use named arguments every day in Python, they make the code more readable and safer at the calling point, because there's less risk of passing wrong data. And recently I have seen that named arguments are widely used in SPARL Ada too, to make code less bug-prone. If a feature is seen as good in both Python and SPARK (that are two very different language), then it's good. This is the syntax in Ada (and SPARK): http://en.wikibooks.org/wiki/Ada_Programming/Subprograms#Named_parameters http://msdn.microsoft.com/en-us/library/dd264739.aspx On the other hand, currently there are many D2 features that are unfinished and buggy, so adding even more stuff is not a good idea. And I think named arguments are a purely additive change. So Walter may add them later when the current features are implemented well enough. Currently it's much more important to focus on eventually needed non-additive changes instead. Bye, bearophile
Oct 21 2010
parent reply Juanjo Alvarez <fake fakeemail.com> writes:
On Thu, 21 Oct 2010 15:45:55 -0400, bearophile 
<bearophileHUGS lycos.com> wrote:
 On the other hand, currently there are many D2 features that are 
unfinished and buggy, so adding even more stuff is not a good idea. And I think named arguments are a purely additive change. So Walter may add them later when the current features are implemented well enough. Currently it's much more important to focus on eventually needed non-additive changes instead. Very true. I also use named arguments constantly in Python. Since I'm not the only one that would like to have it in D 2.1 I'll go into gredy mode and add that expanding a dictionary as named arguments to a function is pretty useful too, but since in D's hashes the values must be of the same type for a declared hash it would be less useful, except for Variant[string] hashes maybe, which is a little convoluted.
Oct 21 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Juanjo Alvarez:

 expanding a dictionary as named 
 arguments to a function is pretty useful too, but since in D's hashes 
 the values must be of the same type for a declared hash it would be 
 less useful, except for Variant[string] hashes maybe, which is a 
 little convoluted.
In D2 there are even typesafe Variadic Functions for dynamic arrays and class objects: http://www.digitalmars.com/d/2.0/function.html An example: class Foo { int x; string s; this(int x_, string s_) { this.x = x_; this.s = s_; } } void test1(int[] array ...) {} void test2(int x, Foo f ...) {} void main() { test1(4, 5, 6); test2(1, 4, "text"); } So far typesafe variadic functions for class objects is an useless feature for me. Once named arguments are present, typesafe variadic functions for associative arrays may look like: void test3a(int[string] aa ...) {} void test3b(Variant[string] aa ...) {} You may call them like this: test3a(x: 1, y: 2, good: 3); test3b(x: 1, y: 2, good: "right"); Bye, bearophile
Oct 21 2010