food for thought - swift 5 released - bottom types, string interpolation, and stuff.

Timon Gehr timon.gehr at gmx.ch
Sun Apr 14 02:20:22 UTC 2019


On 14.04.19 02:42, mate wrote:
> On Sunday, 14 April 2019 at 00:27:18 UTC, Timon Gehr wrote:
>> There are of course other reasons why you would want to add functions 
>> with a simple implementations, I already mentioned standardization of 
>> function names, also, e.g. filter!isOdd is both faster to read and 
>> easier to type than filter!(x=>x&1).
> 
> Would not you check the function definition if you saw `isOdd()` in the 
> code?
> ...

Probably not. What would be the trigger for that?

>> Furthermore, it's just not nice when you are solving a problem and 
>> notice that a lot of functions you need to naturally express it are 
>> missing from the standard library and you need to add them to your own 
>> utility library first, presumably being too lazy to add the correct 
>> template constraints.
> 
> Maybe your math utils library(ies) would be popular on dub. Even if some 
> template constraints are missing, they would probably get fixed over 
> time by some willing contributing users.

Maybe. However, often, the quickest way to make the thing I was working 
on work with sufficient code quality is not actually to implement the 
missing standard library functions, even though it would have been 
easier with those functions there. (E.g., compute the thing with a a few 
for loops instead of with a more elegant and readable range-based 
solution.) I'll consider writing some libraries in the future, but right 
now I don't really get enough of my productive time to work on projects 
I already started, such as getting better tuple support, and I'd really 
prefer obvious omissions to be in the standard library. I see that scan 
has finally been added, but I'm a bit disappointed it was called 
cumulativeFold.

Here, I was mainly objecting to the general idea that functions that are 
simple to implement in terms of a few other functions/built-in operators 
have no business being in the standard library. (This has come up 
before.) It's not even consistently applied in Phobos. E.g., there is 
max and min even though they are trivially implemented in terms of each 
other by switching around the comparison predicate, but it would clearly 
be ridiculous to require this by arbitrarily picking one over the other. 
On the other hand, we have until, but not takeWhile, even though it is 
more common to want to specify the kinds of elements that you like 
instead of a condition on the first one that you don't want.


More information about the Digitalmars-d mailing list