Re: shorter foreach syntax - C++0x range-based for

2010-11-25 Thread Kagamin
Emil Madsen Wrote:

> Why is reference semantics for classes the right thing to do? - Just curious
> about it, because to me it seems counter intuitive to have to semantics.

What is the alternative? Value semantics?


Re: shorter foreach syntax - C++0x range-based for

2010-11-24 Thread Emil Madsen
On 1 November 2010 16:14, Andrei Alexandrescu  wrote:

> On 11/1/10 9:09 AM, Gary Whatmore wrote:
>
>> Nick Treleaven Wrote:
>>
>>  There's a C++0x proposal for a range-based 'for' statement:
>>> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2930.html
>>>
>>> The upcoming GCC 4.6 C++ compiler changes list support for this:
>>> http://gcc.gnu.org/gcc-4.6/changes.html
>>>
>>> I think the syntax could be useful for D to shorten and improve on the
>>> status quo a little. Here's the C++ example:
>>>
>>> int array[5] = { 1, 2, 3, 4, 5 };
>>> for (int&  x : array)
>>>   x *= 2;
>>>
>>> Currently D has:
>>>
>>> int array[5] = [1, 2, 3, 4, 5];
>>> foreach (ref x; array)
>>>   x *= 2;
>>>
>>> I think this is better:
>>>
>>> for (ref x : array)
>>>   x *= 2;
>>>
>>> Apart from being 4 chars shorter, I think it looks more natural using the
>>> ':' instead of ';'. A lesser benefit is it allows reuse of the 'for'
>>> keyword, making the 'foreach' keyword unnecessary.
>>>
>>> Maybe this would be acceptable for D?
>>>
>>
>> No, 1) it's too late to change it. 2) the syntax comes from Java. It would
>> be embarrasing to admit that Java did something right.
>>
>>  - G.W.
>>
>
> Java did a lot of things right (be they novel or not) that are present in
> D, such as reference semantics for classes, inner classes with outer object
> access etc.
>
> Andrei
>

Why is reference semantics for classes the right thing to do? - Just curious
about it, because to me it seems counter intuitive to have to semantics.

-- 
// Yours sincerely
// Emil 'Skeen' Madsen


Re: shorter foreach syntax - C++0x range-based for

2010-11-24 Thread so
Annotations: a very flexible and extensible system to add metadata to  
any kind of definition. Meta-data can be runtime, compile-time or both.  
D could take a lot of inspiration from Java's annotations.


Integrated support for multi-threading: threads, monitors,  
mutexes/locks, synchronization, etc., are part of the language,  
including more advanced synchronization constructs such as condition  
variables. And also a well defined memory model! In fact D took direct  
inspiration from Java on this, did it not?
Also, very good, very well thought concurrency utils (the stuff done by  
Doug Lea).


Wildcards in generics: a very interesting mechanism for increasing type  
safety. Java wildcards were not done right in every aspect, but still  
they are very nice, and I don't know of any mainstream languages that  
have anything quite like that, or even close.


I don't think that is the case, most of those features are "must" for a  
modern language, especially a language like D.
You don't need a language inspiration for these features you listed at  
this age PL.


--
Using Opera's revolutionary email client: http://www.opera.com/mail/


Re: shorter foreach syntax - C++0x range-based for

2010-11-24 Thread Bruno Medeiros

On 01/11/2010 15:14, Andrei Alexandrescu wrote:

On 11/1/10 9:09 AM, Gary Whatmore wrote:

2) the syntax comes from Java. It
would be embarrasing to admit that Java did something right.

- G.W.


Only if one is an idiot.



Java did a lot of things right (be they novel or not) that are present
in D, such as reference semantics for classes, inner classes with outer
object access etc.

Andrei


A few more things:

Annotations: a very flexible and extensible system to add metadata to 
any kind of definition. Meta-data can be runtime, compile-time or both. 
D could take a lot of inspiration from Java's annotations.


Integrated support for multi-threading: threads, monitors, 
mutexes/locks, synchronization, etc., are part of the language, 
including more advanced synchronization constructs such as condition 
variables. And also a well defined memory model! In fact D took direct 
inspiration from Java on this, did it not?
Also, very good, very well thought concurrency utils (the stuff done by 
Doug Lea).


Wildcards in generics: a very interesting mechanism for increasing type 
safety. Java wildcards were not done right in every aspect, but still 
they are very nice, and I don't know of any mainstream languages that 
have anything quite like that, or even close.



--
Bruno Medeiros - Software Engineer


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Kagamin
Andrei Alexandrescu Wrote:

> Java did a lot of things right (be they novel or not) that are present 
> in D, such as reference semantics for classes, inner classes with outer 
> object access etc.

Implicitly making inner class inner is not right.


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Nick Treleaven
On Mon, 01 Nov 2010 09:07:29 -0700, Jonathan M Davis wrote:

>> for (ref x : array)
>>   x *= 2;
>> 
>> Apart from being 4 chars shorter, I think it looks more natural using
>> the ':' instead of ';'. A lesser benefit is it allows reuse of the
>> 'for' keyword, making the 'foreach' keyword unnecessary.
>> 
>> Maybe this would be acceptable for D?
> 
> The current syntax has been around for quite a while, it's in TDPL, and
> making the change gives no significant improvement. Generally speaking,
> we're not really supposed to be making any major changes from what TDPL
> says without a really good reason. Saving a few characters is not a
> really good reason. foreach works just fine and is arguably clearer,
> since you know right away that you're dealing with a foreach loop rather
> than a for loop - and while similar, they _are_ semantically different.

OK.

> And I don't see why : would be better than ;. IIRC, Java uses one and C#
> uses the other and you have to remember which uses which when moving
> between the two.

Actually C# uses:

foreach (int x in array)

So D has its own unique syntax.

> And if you're looking to save typing, ; has the
> advantage that you don't have to use the shift key.

True, but still takes longer to type 'each' than press shift IMO. But 
readibility is perhaps more important than writing code.

> If D had chosen to just reuse for, that would have been fine, but it
> didn't, and I think that it's fine as it is. Changing foreach to for
> would not be a productive change in the least.

Fair enough.


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Jonathan M Davis
On Monday, November 01, 2010 06:16:47 Nick Treleaven wrote:
> There's a C++0x proposal for a range-based 'for' statement:
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2930.html
> 
> The upcoming GCC 4.6 C++ compiler changes list support for this:
> http://gcc.gnu.org/gcc-4.6/changes.html
> 
> I think the syntax could be useful for D to shorten and improve on the
> status quo a little. Here's the C++ example:
> 
> int array[5] = { 1, 2, 3, 4, 5 };
> for (int& x : array)
>   x *= 2;
> 
> Currently D has:
> 
> int array[5] = [1, 2, 3, 4, 5];
> foreach (ref x; array)
>   x *= 2;
> 
> I think this is better:
> 
> for (ref x : array)
>   x *= 2;
> 
> Apart from being 4 chars shorter, I think it looks more natural using the
> ':' instead of ';'. A lesser benefit is it allows reuse of the 'for'
> keyword, making the 'foreach' keyword unnecessary.
> 
> Maybe this would be acceptable for D?

The current syntax has been around for quite a while, it's in TDPL, and making 
the change gives no significant improvement. Generally speaking, we're not 
really 
supposed to be making any major changes from what TDPL says without a really 
good reason. Saving a few characters is not a really good reason. foreach works 
just fine and is arguably clearer, since you know right away that you're 
dealing 
with a foreach loop rather than a for loop - and while similar, they _are_ 
semantically different. And I don't see why : would be better than ;. IIRC, 
Java 
uses one and C# uses the other and you have to remember which uses which when 
moving between the two. And if you're looking to save typing, ; has the 
advantage that you don't have to use the shift key.

If D had chosen to just reuse for, that would have been fine, but it didn't, 
and 
I think that it's fine as it is. Changing foreach to for would not be a 
productive change in the least.

- Jonathan M Davis


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Nick Treleaven
On Mon, 01 Nov 2010 10:09:17 -0400, Gary Whatmore wrote:

>> I think this is better:
>> 
>> for (ref x : array)
>>   x *= 2;
>> 
>> Apart from being 4 chars shorter, I think it looks more natural using
>> the ':' instead of ';'. A lesser benefit is it allows reuse of the
>> 'for' keyword, making the 'foreach' keyword unnecessary.
>> 
>> Maybe this would be acceptable for D?
> 
> No, 1) it's too late to change it.

I don't see a technical reason why foreach, the above for syntax and 'C' 
for syntax can't all be supported.

> 2) the syntax comes from Java.

Perhaps if C++0x does add this and Java already has it this makes more of 
an argument for D supporting it?


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Torarin
Pilsy:
> D is as much Java++ as it is C+=2.

Andrei:
> Java did a lot of things right (be they novel or not) that are present in D

Even if Java did only a single thing right, it would be silly to not
adopt it just to avoid "embarrassment".

Anyway, I think it's a nice syntax.


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Andrei Alexandrescu

On 11/1/10 9:09 AM, Gary Whatmore wrote:

Nick Treleaven Wrote:


There's a C++0x proposal for a range-based 'for' statement:
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2930.html

The upcoming GCC 4.6 C++ compiler changes list support for this:
http://gcc.gnu.org/gcc-4.6/changes.html

I think the syntax could be useful for D to shorten and improve on the
status quo a little. Here's the C++ example:

int array[5] = { 1, 2, 3, 4, 5 };
for (int&  x : array)
   x *= 2;

Currently D has:

int array[5] = [1, 2, 3, 4, 5];
foreach (ref x; array)
   x *= 2;

I think this is better:

for (ref x : array)
   x *= 2;

Apart from being 4 chars shorter, I think it looks more natural using the
':' instead of ';'. A lesser benefit is it allows reuse of the 'for'
keyword, making the 'foreach' keyword unnecessary.

Maybe this would be acceptable for D?


No, 1) it's too late to change it. 2) the syntax comes from Java. It would be 
embarrasing to admit that Java did something right.

  - G.W.


Java did a lot of things right (be they novel or not) that are present 
in D, such as reference semantics for classes, inner classes with outer 
object access etc.


Andrei


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Pillsy
Gary Whatmore Wrote:
[...]
> It would be embarrasing to admit that Java did something right.

Like class types being reference types, having "abstract" and "final" keywords, 
only alloowing single inheritance of implementation while allowing multiple 
implementation of interface, adding garbage collection, making strings 
immutable...?

D is as much Java++ as it is C+=2.

Cheers, 
Pillsy


Re: shorter foreach syntax - C++0x range-based for

2010-11-01 Thread Gary Whatmore
Nick Treleaven Wrote:

> There's a C++0x proposal for a range-based 'for' statement:
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2930.html
> 
> The upcoming GCC 4.6 C++ compiler changes list support for this:
> http://gcc.gnu.org/gcc-4.6/changes.html
> 
> I think the syntax could be useful for D to shorten and improve on the 
> status quo a little. Here's the C++ example:
> 
> int array[5] = { 1, 2, 3, 4, 5 };
> for (int& x : array)
>   x *= 2;
> 
> Currently D has:
> 
> int array[5] = [1, 2, 3, 4, 5];
> foreach (ref x; array)
>   x *= 2;
> 
> I think this is better:
> 
> for (ref x : array)
>   x *= 2;
> 
> Apart from being 4 chars shorter, I think it looks more natural using the 
> ':' instead of ';'. A lesser benefit is it allows reuse of the 'for' 
> keyword, making the 'foreach' keyword unnecessary.
> 
> Maybe this would be acceptable for D?

No, 1) it's too late to change it. 2) the syntax comes from Java. It would be 
embarrasing to admit that Java did something right.

 - G.W.