February 28, 2006 Re: if(;){} opinion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:44047C36.8060200@nospam.org... > Walter Bright wrote: >> The idea behind m; was to be like foreach. What do the "victims" <g> think of: >> >> if (auto m = std.regexp.search("abcdef", "b(c)d")) > > Another round, and everyone had no problem immediately understanding the code. And the word "auto" was universally assumed as in "autotype". > > Found one "still virgin" non-D programmer, and even he immediately assumed the correct functionality, and took for granted that "auto" meant that the compiler figures out the actual type. Thanks for doing this. The result is pretty clear <g>. |
February 28, 2006 Re: if(;){} opinion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | On Wed, 01 Mar 2006 03:37:10 +1100, Georg Wrede <georg.wrede@nospam.org> wrote: >>> Flaunting this around (to both the original programmers, and also >>> to virgin victims), gave the same, _immediate_ comment from >>> everybody: "Ah, that's neat!" >> The idea behind m; was to be like foreach. What do the "victims" <g> >> think of: >> if (auto m = std.regexp.search("abcdef", "b(c)d")) > > Another round, and everyone had no problem immediately understanding the code. And the word "auto" was universally assumed as in "autotype". > > Found one "still virgin" non-D programmer, and even he immediately assumed the correct functionality, and took for granted that "auto" meant that the compiler figures out the actual type. Georg, you have done a great service to the D language with this market research. I hope the boss addresses it appropriately. -- Derek Parnell Melbourne, Australia |
February 28, 2006 Re: if(;){} opinion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Wed, 01 Mar 2006 06:20:35 +1100, Walter Bright <newshound@digitalmars.com> wrote: > > "Derek Parnell" <derek@psych.ward> wrote in message > news:op.s5ol8l1e6b8z09@ginger.vic.bigpond.net.au... >> I've forgotten: what's the syntax to automatically allocate on the static, >> a variable whose type is automatically type-cast? Is it ... >> >> auto auto x = readtext(somefile); > > automatically allocate on the static? I don't understand. LOL... "static" is a mispelled "stack" sorry for my late night typing. -- Derek Parnell Melbourne, Australia |
March 02, 2006 Re: if(;){} opinion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | Georg Wrede wrote:
> David Medlock wrote:
>
>> Georg Wrede wrote:
>>
>>> Better 'fess up front: the intent of this post is to once and for all murder, pulverize and extradite the new if construct.
>>>
>>> Consider:
>>>
>>> if (m; std.regexp.search("abcdef", "b(c)d"))
>>> {
>>> writefln("[%s]", m.pre); // prints [a]
>>> writefln("[%s]", m.post); // prints [ef]
>>> writefln("[%s]", m.match(0)); // prints [bcd]
>>> writefln("[%s]", m.match(1)); // prints [c]
>>> writefln("[%s]", m.match(2)); // prints []
>>> }
>>>
>>> Flauting this around has shown that experienced programmers have a hard time figuring out what is going on here.
>>>
>
>>
>> I would say extend the with(...) construct to silently fail( and take an else clause ) if the object of the with statement is null.
>
>
> if (m; std.regexp.search("abcdef", "b(c)d"))
> {
> writefln("Yippee!");
> }
> else
> {
> writefln("Bad-ee.");
> }
>
> works already.
>
> (Replace "abcdef" with "abXdef" to see.)
It may work but you are making a new nest of corner cases with a known programming construct with specific behavior.
Looks as if one mistyped semicolon could introduce very interesting behavior...
-DavidM
|
March 03, 2006 Re: if(;){} opinion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> "clayasaurus" <clayasaurus@gmail.com> wrote in message news:dtvmkf$2e1a$1@digitaldaemon.com...
>> I'll vote against it because I don't understand the value of
>>
>> if (m; search("abcdef", "BcdasdfD"))
>>
>> over
>>
>> if (Regexp m = search("abcdef", "BcdasdfD") ) .
>>
>> Maybe someone can enlighten me?
>
> 1) m is implicitly typed
> 2) looks like the foreach
> 3) more concise
I've given this some thought and decided I don't see any value in:
if( m; search( "", "" ) )
over:
if( auto m = search( "", "" ) )
Both are implicitly typed and I feel the latter is more meaningful. It also has the arguable benefit of being consistent with C++. Also, I think the desire for with foreach is a red herring, as the meaning of foreach is entirely unique within D: "for each thing in this sequence, do something." That is, it's clear that a value or value/key pair must be assigned or the loop is meaningless. Contrast this with if, while, and even for loops whose purpose is condition evaluation (or perhaps counting in the case of a for loop) and the meaning of the declarative syntax present in foreach is much less clear. This also leaves 'for' as the odd man out, as I assume it's meaningless to do this:
for( m; search( "", "" ); )
If this were legal I'd be tempted to suggest simply doing away with foreach entirely, which doesn't seem at all reasonable.
So basically, I think that foreach is a special case and should be treated as such. While adding a type name (or 'auto') and an assignment may be a bit more verbose than the existing syntax, I think it benefits from being far more meaningful in expressions where such assignments are not necessary, and does not lose any flexibility over the current method.
Sean
|
Copyright © 1999-2021 by the D Language Foundation