Naming conventions for functions in similar modules
Jonathan M Davis
jmdavisProg at gmx.com
Wed Jun 22 08:57:58 PDT 2011
On 2011-06-22 04:47, Lars T. Kyllingstad wrote:
> On Tue, 21 Jun 2011 23:30:49 -0700, Walter Bright wrote:
> > On 6/21/2011 10:38 PM, Jonathan M Davis wrote:
> >> For example, should we have
> >>
> >>>> std.ascii.toLower and std.uni.toLower or std.ascii.toAsciiLower and
> >>>> std.uni.toUniLower?
> >
> > I think we've failed if we have to name things std.ascii.toAsciiLower,
> > i.e. having to repeat the module name in the function name in order to
> > disambiguate it.
>
> One problem: std.uni only contains functions for dealing with upper/
> lower case and for checking whether something is an alpha character. If
> you want the other functions, such as isDigit(), isPunctuation(), etc.
> you still have to import std.ascii. And once you have imported both
> std.uni and std.ascii, you are forced to disambiguate every time you call
> a function which exists in both.
If it's a question of only generally a needing few functions, then static
imports or explicit imports should solve the problem of that causing conflicts
for all of the rest.
static import std.ascii;
import std.ascii : isDigit;
It's more of an issue when you have a _lot_ of functions that you want to
intermix (like might happen with std.algorithm and std.parallel_algorithm).
But it is true that dealing with that could get annoying.
> Would it make sense to move or add isDigit and so on to std.uni? Would
> Unicode-aware versions of these functions be different from the ASCII
> versions?
Yes. Look at Arabic Digits, Arabic-Indic Digits, and European Digits here:
http://unicode.org/glossary/ . It looks like the term digit in unicode is
restricted to either 0 - 9 or variations on them rather than anything that
might be considered a number (those would be considered numerals it seems:
http://en.wikipedia.org/wiki/Unicode_numerals ), but in at least some
circumstances, digits in unicode are more than just 0 - 9. I believe that
you'd have to do something like isEuropeanDigit to unambiguously mean 0 - 9 in
unicode. I expect that isHexDigit and isOctalDigit would be unambigously the
same in ascii and unicode but not isDigit.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list