(git HEAD) std.datetime spewing deprecation messages

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 5 18:30:19 PDT 2014


On 06/06/14 02:34, Jonathan M Davis via Digitalmars-d wrote:
> On Thu, 05 Jun 2014 23:54:49 +0200
> Artur Skawina via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> 
>> I'm just saying that encouraging that kind of
>> return-by-weakly-typed-pointers-with-string-selectors interfaces
>> is /not/ a good idea; there are other, much better, options in D.
> 
> There's no weak typing here at all. The closest that there is to weak typing
> is the fact that it will accept pointer to any integral type which risks
> overflow if you select a type which is too small to hold the value. Everything
> else about this is strongly typed. Accepting strings as template arguments is

One can mistakenly store milliseconds in a seconds field etc. Without distinct
types the compiler can not spot all such errors (when the types happen to be 
compatible or identical, and/or when the manual checks inside the 'split'
implementation aren't sufficient).

> split as presented is incredibly straightforward and simple to use - and it's
> quite type safe - whereas what you're suggesting is far more complicated and
> to no real benefit as far as I can tell.

My /implementation/ was obviously just an example, to show how it would work,
with a bit of "Real Programmers only need one-liners" humor. Ignore that part, 
it can actually be written in a more sane way. :)

All I'm suggesting is that instead of taking a string DSL and placing the
result into several objects provided by the caller, an alternative is to
take that very same string DSL, and instead build and return an ad-hoc structure
with the values. RVO can turn that into a /hidden/ return-by-ref, so the
perf implications are minimal, often non-existent. And you get an API which
looks like this:
      
   auto r = d.split!q{ days, seconds, msecs };
   // access r.days etc

I don't know if this would be appropriate for your module. But it is an
option in D, so the *C* idiom of returning-multiple-values-via-ptr isn't
the only one.

artur


More information about the Digitalmars-d mailing list