eliminate junk from std.string?

bearophile bearophileHUGS at lycos.com
Mon Jan 10 00:41:51 PST 2011


Lars T. Kyllingstad:

> My suggestions for things to remove:
> 
> hexdigits, digits, octdigits, lowercase, letters, uppecase, whitespace
>  - What are these arrays useful for?
> 
> capwords()
>  - It tries to do too much.
> 
> zfill()
>  - The ljustify(),rjustify(), and center() functions
>    should instead take an optional padding character
>    that defaults to a space.
>  
> maketrans(), translate()
>  - I don't even understand what these do.
> 
> inPattern(), countchars(), removechars()
>  - Pattern matching is std.regex's charter.
> 
> squeeze(), succ(), tr(), soundex(), column()
>  - I am having a very hard time imagining myself ever
>    using these functions...

I agree with about nothing you have said :-)

How much string processing you do day by day? I am using most of those things... If you are used in using Python or Ruby you probably find most of those things useful. If Andrei removes arrays like lowercase, letters, uppecase, I will have to write them myself in code. ljustify(),rjustify(), and center() are very useful, even if they may be improved in some ways. maketrans() and translate() (as other things) come from Python string functions, and I have used them a hundred times in string processing code. I have used squeeze() some times. soundex is not hurting, because even if it's not commonly necessary, its name is easy to understand and it's not easy to miss for something different, so it doesn't add much noise to the library. And I've seen that it's easy to implement soundex wrongly, while the one in the std.string is correct.

I agree that too much stuff is generally bad in a library, because searching for something requires more time if there are more items to search into. In Bugzilla I have three or four bug reports that ask for few small changes in std.string (like removing chop and keeping chomp). But please don't remove too much. In a library more is often better.

Bye,
bearophile


More information about the Digitalmars-d mailing list