October 12, 2008
Jarrett Billingsley:
> It's not "error-prone", it's "you're not used to it."  You very commonly fall into the fallacy that if you think something's bad/confusing/not what you're used to, then _everyone_ must think that way and therefore it _must_ change.  Sorry, that's not the way it works.  I haven't mistyped a foreach loop, ever.  Deal with it.

I remember that when I have discussed about this topic the first time another person has said of sharing this problem of mine with this syntax.

C# foreach syntax uses the "in", and Python too uses it. Both languages are quite more used than D, are modern, and they care about their usability and readability.

If I don't talk about this topic I can't know if it's a common problem, or a personal one.

So even if I am wrong (and I am wrong all the time), and the current foreach syntax of D isn't bug-prone, I think the topic deserves a little discussion, so people can show who's right.

Bye,
bearophile
October 12, 2008
On Sun, Oct 12, 2008 at 10:46 AM, bearophile <bearophileHUGS@lycos.com> wrote:
> Jarrett Billingsley:
>> It's not "error-prone", it's "you're not used to it."  You very commonly fall into the fallacy that if you think something's bad/confusing/not what you're used to, then _everyone_ must think that way and therefore it _must_ change.  Sorry, that's not the way it works.  I haven't mistyped a foreach loop, ever.  Deal with it.
>
> I remember that when I have discussed about this topic the first time another person has said of sharing this problem of mine with this syntax.
>
> C# foreach syntax uses the "in", and Python too uses it. Both languages are quite more used than D, are modern, and they care about their usability and readability.
>
> If I don't talk about this topic I can't know if it's a common problem, or a personal one.
>
> So even if I am wrong (and I am wrong all the time), and the current foreach syntax of D isn't bug-prone, I think the topic deserves a little discussion, so people can show who's right.

I agree with you, Bearophile.  And I may be the person you remember agreeing with you before.  So we may be the only two.  :-)   Although clearly designers of C# and Python thought it looked nicer than other possibilities, so apparently they agree too.

But anyway it seems not to be an easy change to make it work in D
without ruining the easy syntax parsing.  So another idea for
unambiguous syntax is needed.   An 'of' keyword or make an
in-expression or something.
      foreach(x of thinglist) { ... }
      foreach(x in(thinglist)) { ... }
      foreach(x (in) thinglist) { ... }

But even then, the result has to be so much better than ";" that it's worth breaking backwards compatibility.  I think that's a hard sell. ";" works and its not totally terrible, and it does have precedent with the semicolons in regular for loops.

--bb
October 12, 2008
On Sun, Oct 12, 2008 at 11:02 AM, Bill Baxter <wbaxter@gmail.com> wrote:
> On Sun, Oct 12, 2008 at 10:46 AM, bearophile <bearophileHUGS@lycos.com> wrote:
>> Jarrett Billingsley:
>>> It's not "error-prone", it's "you're not used to it."  You very commonly fall into the fallacy that if you think something's bad/confusing/not what you're used to, then _everyone_ must think that way and therefore it _must_ change.  Sorry, that's not the way it works.  I haven't mistyped a foreach loop, ever.  Deal with it.
>>
>> I remember that when I have discussed about this topic the first time another person has said of sharing this problem of mine with this syntax.
>>
>> C# foreach syntax uses the "in", and Python too uses it. Both languages are quite more used than D, are modern, and they care about their usability and readability.
>>
>> If I don't talk about this topic I can't know if it's a common problem, or a personal one.
>>
>> So even if I am wrong (and I am wrong all the time), and the current foreach syntax of D isn't bug-prone, I think the topic deserves a little discussion, so people can show who's right.
>
> I agree with you, Bearophile.  And I may be the person you remember agreeing with you before.  So we may be the only two.  :-)   Although clearly designers of C# and Python thought it looked nicer than other possibilities, so apparently they agree too.
>
> But anyway it seems not to be an easy change to make it work in D
> without ruining the easy syntax parsing.  So another idea for
> unambiguous syntax is needed.   An 'of' keyword or make an
> in-expression or something.
>      foreach(x of thinglist) { ... }
>      foreach(x in(thinglist)) { ... }
>      foreach(x (in) thinglist) { ... }
>
> But even then, the result has to be so much better than ";" that it's worth breaking backwards compatibility.  I think that's a hard sell. ";" works and its not totally terrible, and it does have precedent with the semicolons in regular for loops.

Another thought -- personally I don't see much value in "in" as an expression.  Why can't that just be a library function?  I use foreach loops about 100x more often than I use lookup with "in".

--bb
October 12, 2008
Bill Baxter wrote:
> On Sun, Oct 12, 2008 at 10:46 AM, bearophile <bearophileHUGS@lycos.com> wrote:
>> Jarrett Billingsley:
>>> It's not "error-prone", it's "you're not used to it."  You very
>>> commonly fall into the fallacy that if you think something's
>>> bad/confusing/not what you're used to, then _everyone_ must think that
>>> way and therefore it _must_ change.  Sorry, that's not the way it
>>> works.  I haven't mistyped a foreach loop, ever.  Deal with it.
>> I remember that when I have discussed about this topic the first time another person has said of sharing this problem of mine with this syntax.
>>
>> C# foreach syntax uses the "in", and Python too uses it. Both languages are quite more used than D, are modern, and they care about their usability and readability.
>>
>> If I don't talk about this topic I can't know if it's a common problem, or a personal one.
>>
>> So even if I am wrong (and I am wrong all the time), and the current foreach syntax of D isn't bug-prone, I think the topic deserves a little discussion, so people can show who's right.
> 
> I agree with you, Bearophile.  And I may be the person you remember
> agreeing with you before.  So we may be the only two.  :-)   Although
> clearly designers of C# and Python thought it looked nicer than other
> possibilities, so apparently they agree too.
> 
> But anyway it seems not to be an easy change to make it work in D
> without ruining the easy syntax parsing.  So another idea for
> unambiguous syntax is needed.   An 'of' keyword or make an
> in-expression or something.
>       foreach(x of thinglist) { ... }
>       foreach(x in(thinglist)) { ... }
>       foreach(x (in) thinglist) { ... }
> 
> But even then, the result has to be so much better than ";" that it's
> worth breaking backwards compatibility.  I think that's a hard sell.
> ";" works and its not totally terrible, and it does have precedent
> with the semicolons in regular for loops.

I don't see any technical difficulty with allowing foreach (x in y).

Andrei
October 12, 2008
On Sun, Oct 12, 2008 at 11:07 AM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> Bill Baxter wrote:
>>
>> On Sun, Oct 12, 2008 at 10:46 AM, bearophile <bearophileHUGS@lycos.com> wrote:
>>>
>>> Jarrett Billingsley:
>>>>
>>>> It's not "error-prone", it's "you're not used to it."  You very commonly fall into the fallacy that if you think something's bad/confusing/not what you're used to, then _everyone_ must think that way and therefore it _must_ change.  Sorry, that's not the way it works.  I haven't mistyped a foreach loop, ever.  Deal with it.
>>>
>>> I remember that when I have discussed about this topic the first time another person has said of sharing this problem of mine with this syntax.
>>>
>>> C# foreach syntax uses the "in", and Python too uses it. Both languages are quite more used than D, are modern, and they care about their usability and readability.
>>>
>>> If I don't talk about this topic I can't know if it's a common problem, or a personal one.
>>>
>>> So even if I am wrong (and I am wrong all the time), and the current foreach syntax of D isn't bug-prone, I think the topic deserves a little discussion, so people can show who's right.
>>
>> I agree with you, Bearophile.  And I may be the person you remember agreeing with you before.  So we may be the only two.  :-)   Although clearly designers of C# and Python thought it looked nicer than other possibilities, so apparently they agree too.
>>
>> But anyway it seems not to be an easy change to make it work in D
>> without ruining the easy syntax parsing.  So another idea for
>> unambiguous syntax is needed.   An 'of' keyword or make an
>> in-expression or something.
>>      foreach(x of thinglist) { ... }
>>      foreach(x in(thinglist)) { ... }
>>      foreach(x (in) thinglist) { ... }
>>
>> But even then, the result has to be so much better than ";" that it's worth breaking backwards compatibility.  I think that's a hard sell. ";" works and its not totally terrible, and it does have precedent with the semicolons in regular for loops.
>
> I don't see any technical difficulty with allowing foreach (x in y).

Walter seems to think there is for some reason.  Maybe because of
foreach(x in y in z) ?

--bb
October 12, 2008
On Sun, Oct 12, 2008 at 4:16 AM, Bill Baxter <wbaxter@gmail.com> wrote:

>>> But even then, the result has to be so much better than ";" that it's worth breaking backwards compatibility.  I think that's a hard sell. ";" works and its not totally terrible, and it does have precedent with the semicolons in regular for loops.

It's no different than .() vs !() in that regard.

> Walter seems to think there is for some reason.  Maybe because of
> foreach(x in y in z) ?

It's still grammatically unambiguous.  The first 'in' is interpreted
as the end of the index list and the beginning of the container
expression; and the second 'in' is parsed as the container expression.
 It looks dumb but wouldn't come up that often anyway.
October 12, 2008
"Bent Rasmussen" <IncredibleShrinkingSphere@Gmail.com> wrote in message news:gcre4u$2dmb$1@digitalmars.com...
> In fact the days of "one language one syntax" is about to come to an end it would appear. This is witnessed by the massive hype surrounding domain-specific languages atm - perhaps spun off by Intentional Programming where demonstrations show radically different presentations for the same underlying abstract syntax.
>

The domain-specific language hype annoys me. Needs have grown since the days C/C++ was considered "general purpose", and C++'s changes haven't quite been able to keep up. That's a given. Formerly "general-purpose" languages like C++ just aren't really "general purpose" anymore. But I consider the "domain-specific language" movement to be purely systemic of the lack of a sufficient new general purpose language.

There's still a need, and IMO a potential, for a new general purpose language. It's just too hackish to be using a completely different language for every little thing. Most people seem to look at this recent explosion of less-than-mainstream languges like D, F#, OCaml, Groovy, Python, Delight, etc., as a trend towards an increasingly-segregated language arena. I see it as the playground/sandbox that's building the groundwork for a new general purpose language. If I understand my language history right, this is similar to how languages like ALGOL, B, BCPL, Fortran, Fourth and Cobol helped pave the way for C.


October 12, 2008
Nick Sabalausky wrote:
> "Dave" <Dave_member@pathlink.com> wrote in message news:gcqrbr$1cg4$1@digitalmars.com...
>> "KennyTM~" <kennytm@gmail.com> wrote in message news:gcqnqd$161r$1@digitalmars.com...
>>> Dave wrote:
>>>> a) It works for C++0x so it can be made to work for D using the same rules. I also assume that C# and Java compilers use the same methods as C++0x to work around the ambiguities with the right-shift operator.
>>> The argument against T<x> from the start is that it is more difficult to parse. It is not impossible, it is just difficult. You can blame Walter for being lazy.
>>>
>> Lazy doesn't mean to Walter what it means to the rest of us... To Walter, "lazy" is another way of saying for "I don't agree and I'd rather just do something else" <g>
>>
>> I just saw a post where Walter says he hates the angle brackets and that syntax matters. I agree that syntax does matter, and apparently many developers and other language designers don't have a problem with the "<>" syntax. So maybe Walter needs to bite the bullet and D should just use it. Maybe D is bucking a trend here where it shouldn't.
>>
> 
> One of the original guiding principles of D is that it be easy to parse. There were a number of valid reasons for this, not just lazyness.
> 
> Plus, I'm no compiler expert, but I think I rememebr hearing somewhere that overloadng <> to be usable for both comparisons and grouping would require non-context-free grammar. That would be a major increase in D's parsing complexity. C++ grammer is definately not context-free, that's why it can get away with it. Not sure about C# or Java, but I've been under the impression those aren't context-free either.

You can define a context-free grammar that accepts all syntactically correct C++ programs. This will accept many incorrect C++ programs, though, and you have to defer a lot of checking until the semantic phase.

The same is true of D. It's a question of how much checking has to be deferred, and whether a reasonably complete AST can be created from a context-free grammar. I don't know where C++ falls.

>>>> b) Easier and more natural for D newbies who've used C++ templates and/or C# / Java Generics.
>>> I agree.
>>>
>> This is probably the biggest issue since D has to win mindshare or else what is the point of this or any other discussion.
>>
> 
> I consider this a non-issue. D is a different language, it's expected that certain things are going to be different. Otherwise it would be the same damn language. I had used C++ templates before I came across D, and my entire thought on it was just "Ok, C++ uses <>, and D uses !()". Done. It's no more of an issue than switching between Java's "{}" and ";" and VB.NET's "X...end X" and "newline".

Hm. VB.NET can do just about everything that C# can. I can read C# easily. It takes a significant amount of effort for me to read VB.NET.

> D needs to win mindshare, sure, but there are better ways to do that than advertising a popular bikeshed color. 
> 
> 
October 12, 2008
Dave wrote:
> "Nick Sabalausky" <a@a.a> wrote in message news:gcqvfr$1k6i$1@digitalmars.com...
>> One of the original guiding principles of D is that it be easy to parse. There were a number of valid reasons for this, not just lazyness.
>>
>> Plus, I'm no compiler expert, but I think I rememebr hearing somewhere that overloadng <> to be usable for both comparisons and grouping would require non-context-free grammar. That would be a major increase in D's parsing complexity. C++ grammer is definately not context-free, that's why it can get away with it. Not sure about C# or Java, but I've been under the impression those aren't context-free either.
>>
> 
> I can see your point and to a point I think it is a valid concern.
> 
> But, most users could care less about that stuff IMO. Abstraction from what a compiler does is why we use higher-level languages in the first place <g>

C++ is much more popular than D, but I haven't found an IDE for it that has a significant advantage over Descent. Many users care a fair bit about IDEs -- I would, if I didn't work over ssh pretty much of the time.
October 12, 2008
On Sat, 11 Oct 2008 21:07:20 -0500, Andrei Alexandrescu wrote:

> I don't see any technical difficulty with allowing foreach (x in y).

Agreed. However, to my eye, "foreach(i, x in y)" seems to read as if both
'x' and 'i' are IN 'y'. Whereas I think of "foreach(i, x; y)" as a list of
variables, of which the last one is a placeholder for elements of 'y'.
Maybe it's just me though ;-)

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell