Design of intuitive interfaces

Michel Fortin michel.fortin at
Sun Feb 21 06:27:28 PST 2010

On 2010-02-21 02:15:23 -0500, Norbert Nemec <Norbert at> said:

> I would suggest the solution in Python/NumPy:
> "sort" gives the command to sort data in-place
> "sorted" returns a sorted data, preserving the input
> similarly, I would suggest
> "reverse" to sort in-place
> "reversed" to return a modified copy

I that's a not so bad solution, applicable to almost any word. There 
are cases where it doesn't work ('split'), but probably not too much.

The remaining problem with this is that it can easily be confused with 
a boolean property. Does "array.sorted" return true or false depending 
on whether the array is sorted, or does it return a sorted array? 
Perhaps this is where a property would be useful:

	array.sort()   // sort in place
	array.sorted() // create sorted copy
	array.sorted   // tell if the array is sorted

but it doesn't scale when you need an argument. So I suggest that 
functions for evaluating a boolean characteristic start with the "is" 

	array.sort(predicate)     // sort in place using predicate
	array.sorted(predicate)   // create sorted copy using predicate
	array.isSorted(predicate) // tell if the array is sorted using predicate

I updated the D Programming Guidelines I wrote a while ago on Wiki4D to 
match this.

> The name "iota" seems confusing to me as well. Very few greek letters 
> do indeed have a conventional meaning (e.g. lambda-calculus, delta for 
> a difference or epsilon for a really small value). Calling a function 
> by a meaningless name is not a good idea. Don't have a better idea 
> right now, though...

Perhaps "interval"? After all, iota(1, 10) is the same concept as 1..10 
which denotes an interval. Ideally we could reuse the ".." operator to 
create an interval, but it seems we can't. The next good solution is to 
use the same terminology.

Michel Fortin
michel.fortin at

More information about the Digitalmars-d mailing list