Phobos - breaking existing code

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 29 03:59:35 PST 2014


Walter Bright:

> Changing names makes the situation worse by consuming scarce 
> resources.

Changing names make the language/library better, and this can 
increase the retention rate of new D programmers.


> That's largely speculation. I doubt there's an objective case 
> that "globMatch" is superior to "fnmatch". Not only that, 
> "fnmatch" is a familiar and widely used name across diverse 
> languages. Nobody else uses "globMatch".

Some examples of classes of situations/problems:
- In Phobos there are good functions like std.math.feqrel that 
people aren't using (I have again and again suggested its usage 
in D.learn) probably because of their bad names.
- In Phobos there are names like schwartzSort that while 
descriptive (if you know what a Schwartz transform is), are 
awfully hard/bad to type and remember (I suggested a "sortKey" or 
something equally simple, that is less descriptive, but this is 
not a big problem because schwartzSort is meant to be used quite 
frequently in D code).
- In Phobos there are also redundant names like 
std.random.randomShuffle, where in both Python and now C++ 
"shuffle" suffices.
- Regarding the name "familiarity" point you often raise, this 
has done not so good to D. We have names like "wchar", "dchar" 
that have no useful meaning, and you need memory to remember 
their sizes. We have exceptionally badly type names as "byte" and 
"ubyte" that are bug-prone, etc. Not all future D programmers 
have 20 years of C/C++ experience of programming. Sometimes a 
more "algorithmic" naming scheme for types as in Rust is better 
(it uses a number to denote the length in bytes of number types).


Good function names are useful because:
- It's simpler to find them when you don't know if Phobos 
contains something you need;
- Once they are found, a well chosen name allows the programmer 
to understand faster if that's the right function to pick;
- Once they are used in the code, a good name makes the code more 
easy to understand;
- Bad names can even cause bugs;
- Sometimes when you can't find a good name for a function is a 
code smell, it means your function is badly designed or should be 
split in two or more parts.

Good naming is essential in programming. Improving some D/Phobos 
names is very important. I understand the need for API stability, 
but this doesn't kill the importance of good naming. Adding 
@deprecated to Phobos for years is often acceptable.


> and the lack of a rich set of libraries because of bit rot.

This is not a valid argument. The lack of D libraries has various 
causes, probably the main one is the lack of D developers and the 
lack of their interest in keeping the code updated (perhaps 
because they have left D community?). If you take a look at the 
Julia language community, the libraries 
(http://pkg.julialang.org/ ) are being refactored and some names 
change, but there are lot of people that work furiously improving 
those libs, so they don't rot, they blossom. Julia is a young 
language but it already has most numerical libraries for all 
kinds of scientific work (also because writing average-quality 
Julia library code requires little time).

Bye,
bearophile


More information about the Digitalmars-d mailing list