More on Rust

Jean Crystof a at a.a
Thu Feb 10 08:23:06 PST 2011


spir Wrote:

> On 02/10/2011 06:43 AM, Nick Sabalausky wrote:
> > "bearophile"<bearophileHUGS at lycos.com>  wrote in message
> > news:iivb5n$na3$1 at digitalmars.com...
> >>
> >> auto x;
> >> if (localtime().hours>= 8) {
> >>     x = "awake!"
> >> } else {
> >>     x = "asleep, go away."
> >> }
> >> log "I'm " + x;
> >>
> >
> > That would be really nice to have in D. There's been many times I've needed
> > to move a declaration up one scope from its initialization and was therefore
> > forced to get rid of the "auto". Not a major problem obviously, but that
> > sure would be nice.
> 
> I don't like that at all. The second main feature of staticity if self-doc 
> code. How is one, as a reader, supposed to guess what x is and means?
> I'm not a great fan of auto, neither, use it would happily live w/o it, except 
> for functions operating on ranges, that return types coming from who-knows 
> where (certainly another planet).

How about this?
spir Wrote:

auto x =
  if (localtime().hours>= 8) {
    "awake!"
  } else {
    "asleep, go away."
  };

log "I'm " + x;

I think it solves the problem of unkown type for x nicely. And it's very close to what we already have. something ? foo : bar might do the same, but if() [} else {} is much more readable IMO.


More information about the Digitalmars-d mailing list