std.experimental.checkedint is ready for comments!

tsbockman via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 15 08:44:22 PDT 2016


On Wednesday, 15 June 2016 at 07:16:18 UTC, Walter Bright wrote:
> On 6/14/2016 9:48 PM, tsbockman wrote:
>> `Int`? `Base`?
>
> 'Integer' would work fine.

`BaseInt`?

`SmartInt!Integer` looks weird to me, because of the repetition. 
Also, if we're going to use a long name like that I think it 
should hint at the fact that the true base type of a checked 
integer type is always a basic type, not a custom type like 
`SmartInt` or `BigInt`.

> Besides, the signature will be the actual type name, not the 
> alias for it.

I'm not sure what you're getting at here?

I'm concerned about how stuff like this appears in the docs 
(which is the only place where the user will ever see this name). 
Obviously the docs must use the alias, since they are for the 
generic type, rather than a specific instantiation.

>> I have seen all of `S`, `F`, `G`, `X`, `R`, `C`, `A`, and `B` 
>> used as template
>> parameter names in Phobos. Often there is no particular 
>> significance to the
>> letter chosen, but the purpose of the parameter is obvious 
>> from the context,
>> anyway.
>
> 1. Each one should be evaluated on its own merits.
> 2. Style is not something cast in stone, we try to constant 
> evolve better ways.

Obviously I don't think your way is better.  :-)

> 3. Bad practice in one case is not a rationale to use bad 
> practice elsewhere :-)

But when a practice works out fine in one case, that *is* 
evidence that it is likely to work out in others.

> 4. You mentioned greppability - 'N' is as ungreppable as it 
> gets!

Which is irrelevant, because `N`/`BaseIntegralType`/whatever will 
never appear in the user's code (but `bscal` will).

>> Using short template parameter names helps keep D's 
>> already-very-long signatures
>> from growing even longer than they already are.
>
> The parameter names don't appear in the signature.

They appear in the docs. I'm talking about the docs, because 
that's the only place anyone outside the Phobos dev team will 
ever see the `N`/`Integer`/whatever name.

>> Again, this needs to be short for readability and usability. 
>> Normally it's not
>> needed at all, but when it is needed (like in the 
>> implementation of `SmartInt`
>> and `SafeInt`), it tends to be needed *a lot*.
>
> Internal to the implementation does not require it to be short.

Keeping names that don't need to be long short(ish) makes it a 
lot easier for me to read code.

Also, in practice people usually choose convenience over safety. 
If writing an algorithm using `checkedint` instead of the basic 
integer types makes the algorithm twice as long, the vast 
majority of people simply won't use `checkedint`.

For me, there is no point to pursuing inclusion of `checkedint` 
in Phobos if doing so requires making the API so verbose that no 
one will want to use it. (Which is not to say that `.bscal` => 
`.integer` is such a problem.)



More information about the Digitalmars-d mailing list