www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - From next C#

reply "bearophile" <bearophileHUGS lycos.com> writes:

like in the 0b0010\_1110; literal):

https://gist.github.com/anonymous/9997622

Declaring out arguments at the calling point is nice, but 
returning a tuple as in Python/Haskell is better:

GetCoordinates(out var x, out var y);


It's also nice the syntax to define struct/class members with the 
same name as class arguments as in Scala/TypeScript. But in D you 
can't use this syntax because those are template arguments:

class Customer(string first, string last) {

A solution is to use two groups, as for functions (but the 
default is the opposite for functions):

class Customer()(private const string first, private const string 
last) {

Bye,
bearophile
Apr 05 2014
parent "Idan Arye" <GenericNPC gmail.com> writes:
On Saturday, 5 April 2014 at 21:17:53 UTC, bearophile wrote:

 chars, like in the 0b0010\_1110; literal):

 https://gist.github.com/anonymous/9997622

 Declaring out arguments at the calling point is nice, but 
 returning a tuple as in Python/Haskell is better:

 GetCoordinates(out var x, out var y);
Returning a tuple is nice, but isn't the D way to return an "anonymous" struct(well, yes, it has a name, but that name is only defined inside the function that returns it...)? control structures. Imagine using `TryParse` in the condition expression of an `if` statement, declaring there an out parameter that'll only be accessible in the scope of the `if` statement.
 It's also nice the syntax to define struct/class members with 
 the same name as class arguments as in Scala/TypeScript. But in 
 D you can't use this syntax because those are template 
 arguments:

 class Customer(string first, string last) {

 A solution is to use two groups, as for functions (but the 
 default is the opposite for functions):

 class Customer()(private const string first, private const 
 string last) {
Instead of this confusing syntax, how about making them regular fields and marking them with a attribute that'll make the compiler add them to the default constructor: class Customer{ default string first; default string last; }
Apr 06 2014