eliminate junk from std.string?
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Mon Jan 10 01:08:22 PST 2011
On Mon, 10 Jan 2011 03:41:51 -0500, bearophile wrote:
> 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 think you may have misunderstood some of my suggestions. For instance,
I never proposed to remove ljustify(), rjustify(), and center(). Rather,
I would have them take an extra 'padding' parameter, so we can eliminate
zfill().
Before: auto s = zfill("123", 6);
After: auto s = rjustify("123", 6, '0');
As for the other things I suggested, well... those are the things i vote
to remove from std.string. If they only get that one vote, they stay. ;)
By the way, since you seem to be using these things quite often, maybe
you can answer this:
1. What are the hexdigits, digits, octdigits, lowercase, letters,
uppercase, and whitespace arrays useful for? The only thing I can think
of is to check whether a character belongs to one of them, but I think
that is better done with the std.ctype functions.
2. What do maketrans() and translate() do? (A brief example would be
nice.)
-Lars
More information about the Digitalmars-d
mailing list