Whither Tango?

Jonathan M Davis jmdavisProg at gmail.com
Sat Feb 20 19:39:03 PST 2010


Michel Fortin wrote:

> On 2010-02-20 11:14:48 -0500, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> said:
> 
>> Michel Fortin wrote:
>>> I don't think there are really any 'silly' names (except perhaps iota),
>>> it's just that many don't do exactly what you think they do on first
>>> reading.
>> 
>> The lengthy post below talks about _one_. If there are "many", you
>> should be able to effortlessly list a handful.
> 
> It takes some time to notice them as they're more subtle that just
> names that look wrong. I'm sure I encountered a couple of them while
> using Phobos, although I can't remember others right now (which might
> be due to me avoiding them now). If you're interested, I can dig a
> little.
> 
> But if you're just going to dismiss the criticism by asserting they're
> good semantics anyway (just different that what I expect), then I'm not
> sure it's worth the time finding them and explaining the problem for
> each of them. I'd do better create my own range module and use it
> instead, as I already have some other reasons pushing in that direction.
> 
> 
>> At the end of the day you can't expect to fly blind through an entire
>> library.
> 
> I'm speaking of one function right now, not an entire library. Assuming
> someone knows the concept of ranges, I think a function called "take"
> taking a range and a length argument should be pretty obvious without
> looking at the documentation.
> 
>> "take" could be defined with a number of arguably good semantics.
> 
> The minimal thing I'd expect of a "take" function is that it takes
> something when you call it. But this one doesn't. I don't see how you
> can call that "good semantics".
> 
> But now I wonder, what is everyone's expectation of a function called
> "take"?
> 
> 

Actually, take does _exactly_ what I'd expect. It functions like the take 
function in Haskell (where altering the list would be impossible since all 
variables are immutable). I think that I've seen Andrei mention stuff about 
Haskell stuff before, so I suspect that that's where he got it from.

Honestly, I don't know how you could know for certain whether a given 
function alters what you pass to it ahead of time unless you look at the 
function signature and description in the docs. I suppose that you could 
make functions have names like takeConst and takeNonConst, or takeImmutable, 
takeMutable, or something like that to indicate whether it alters its 
arguments or not, but that gets ugly fast.

The name take does give you a basic idea of what the function is doing, as 
do many function names, but when it comes down to it, you're going to have 
to read the docs to know exactly what a function does. I don't see any way 
around that. Picking names which give a clear indication of what a function 
does helps a lot, but in the end, you have to look up exactly what they do 
if you want to know for sure.

- Jonathan M Davis



More information about the Digitalmars-d mailing list