Safer casts

Janice Caron caron800 at googlemail.com
Mon May 12 14:52:58 PDT 2008


On 12/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  > The type of a is the type of the array element. This is obvious.
>
> again, obvious to you, not that dude five years from now reading your
>  code. documented is not the same as compiler checked, and we both know
>  that documentation could get out of sync with the code.

I'm talking about the documentation for std.algorithm.sort. What are
you talking about?

It is perfectly reasonable to expect that anyone using
std.algorithm.sort will have read the documentation on how to use it.


>  also, why do I have to go and search the docs if the code is in front of me?

You don't. You learn how to use std.algorithm.sort, and then you use
it, going back to the docs only occasionally.

It's the same with anything. If I want to use a std::vector in C++,
I'd better have read up on what std::vectors are and how to use them
first.

So yes, it's obvious what the "a" and "b" mean.



> > The benefit is choice.
>
>  choice of what?

Of everything. Of having it do whatever you want, whatever that is.


> You've said so yourself, both templated and
> non-templated versions of the sort-with-delegate are identical.

I have said no such thing! (And I take great offense at being misquoted)

I may have said that *one particular instantiation* of the template is
identical to the delegate version. Fair enough. But I can also make
different instantiations.


>  you want those string templates (which i don't like) than fine, define
>  them as templates and i won't use them. but the version with the
>  delegate is needlessly a template.

There /is/ no "version with the delegate". But you can /make/ a
version with a delegate out of the template.

And those string parameters are brilliant! Today I wanted to strip out
all underscores from a string. So I sat down to write the function -
it's not really hard, after all - but then, with a flash of
inspiration, I realised the function already exists. It is:

    filter!("a != '_'")(s);

That is just /so/ amazing.



>  ideally (not possible in current D) both forms should have the
>  same syntax, so the end user (me) doesn't need to know nor care about
>  what sort of implementation was chosen.

You haven't heard of aliases or wrapper functions then?



More information about the Digitalmars-d mailing list