January 10, 2013 Re: Enhancing foreach | ||||
---|---|---|---|---|
| ||||
Posted in reply to ixid | On Thursday, 10 January 2013 at 02:04:57 UTC, ixid wrote:
>
> Regardless of this particular suggestion's value, I think you're wrong to dismiss readable terseness and saving typing as mattering, it's one of D's advantages over C++ that it makes a lot of things far easier to do and understand because they're not a horrid mess.
The difference is that D allows doing in a single instruction what C++ would require several. It is actually less *code*, less duplication, less potential for bugs: New FUNCTIONALITY.
What you are proposing isn't much of that, it's just making you type less...
|
January 10, 2013 Re: Enhancing foreach | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Summerland | On Thursday, 10 January 2013 at 03:29:21 UTC, Peter Summerland wrote: > > I don't think Jonathan was (merely) dismissing readable terseness and saving typing. IMO he had more pertinent reasons why > > foreach(i; 0 .. 5) > {} > > is very nice, *as is*. The only thing I'd want to be able to do is: //---- foreach ( ; 0 .. 5) { writeln("hello"); } //---- If I don't need a named variable, why force me to define a symbol? http://d.puremagic.com/issues/show_bug.cgi?id=9009 I know I could just use "i" and move on, but when code starts getting complex, and you already have i, j, k, ii, dummy etc..., it can make a difference. |
January 10, 2013 Re: Enhancing foreach | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | Le 10/01/2013 10:23, monarch_dodra a écrit :
> On Thursday, 10 January 2013 at 03:29:21 UTC, Peter Summerland wrote:
>
> The only thing I'd want to be able to do is:
> //----
> foreach ( ; 0 .. 5)
> {
> writeln("hello");
> }
> //----
>
> If I don't need a named variable, why force me to define a symbol?
> http://d.puremagic.com/issues/show_bug.cgi?id=9009
>
> I know I could just use "i" and move on, but when code starts getting
> complex, and you already have i, j, k, ii, dummy etc..., it can make a
> difference.
What about :
foreach (0 .. 5)
{
writeln("hello");
}
?
|
January 15, 2013 Re: Enhancing foreach | ||||
---|---|---|---|---|
| ||||
Posted in reply to Raphaël Jakse | On Thursday, 10 January 2013 at 17:36:15 UTC, Raphaël Jakse wrote:
> Le 10/01/2013 10:23, monarch_dodra a écrit :
>> On Thursday, 10 January 2013 at 03:29:21 UTC, Peter Summerland wrote:
>>
>> The only thing I'd want to be able to do is:
>> //----
>> foreach ( ; 0 .. 5)
>> {
>> writeln("hello");
>> }
>> //----
>>
>> If I don't need a named variable, why force me to define a symbol?
>> http://d.puremagic.com/issues/show_bug.cgi?id=9009
>>
>> I know I could just use "i" and move on, but when code starts getting
>> complex, and you already have i, j, k, ii, dummy etc..., it can make a
>> difference.
>
>
> What about :
>
> foreach (0 .. 5)
> {
> writeln("hello");
> }
>
> ?
What about:
5 {
writeln("hello");
}
It could even work with floats!
1.5 {
writeln("nice");
}
prints:
nice
ni
|
January 15, 2013 Re: Enhancing foreach | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ary Borenszweig | Le 15/01/2013 19:41, Ary Borenszweig a écrit :
> On Thursday, 10 January 2013 at 17:36:15 UTC, Raphaël Jakse wrote:
>> Le 10/01/2013 10:23, monarch_dodra a écrit :
>>> On Thursday, 10 January 2013 at 03:29:21 UTC, Peter Summerland wrote:
>>>
>>> The only thing I'd want to be able to do is:
>>> //----
>>> foreach ( ; 0 .. 5)
>>> {
>>> writeln("hello");
>>> }
>>> //----
>>>
>>> If I don't need a named variable, why force me to define a symbol?
>>> http://d.puremagic.com/issues/show_bug.cgi?id=9009
>>>
>>> I know I could just use "i" and move on, but when code starts getting
>>> complex, and you already have i, j, k, ii, dummy etc..., it can make a
>>> difference.
>>
>>
>> What about :
>>
>> foreach (0 .. 5)
>> {
>> writeln("hello");
>> }
>>
>> ?
>
> What about:
>
> 5 {
> writeln("hello");
> }
>
> It could even work with floats!
>
> 1.5 {
> writeln("nice");
> }
>
> prints:
>
> nice
> ni
D should definitively implement the GWPM (Gess What the Programmer Meant) compile-time feature. That would be awesome.
|
Copyright © 1999-2021 by the D Language Foundation