Is the term "natural ordering" specific to Java?

java, terminology

Solution

This is not a reference to the type of natural ordering where numbers inside of strings are sorted "naturally" instead of lexicographically digit-by-digit. Java defines the term differently.

Let's change the emphasis:

`Comparable` implementations provide a natural ordering for a class, which allows objects of that class to be sorted automatically.

The word "natural" means that if you implement `Comparable` then users of your class can sort it easily without needing a custom comparator. The sorting is natural; it's built in; it's free, no thinking required.

Is the term "natural ordering" specific to Java, or language-independent?

Yes. No. Both? It's specific to Java insofar as the documentation italicizes the term and there is a `naturalOrder` method. The concept is applicable to other languages, though, sure.

For example, could I talk about "natural ordering" in Ruby?

You could. If you were talking off the cuff you could use the term. If you were writing formally it would be prudent to define it. Because of the confusion with Atwood's use of the term, I'd prefer a different one. Say, "default ordering".

Problem

The tutorial Object Ordering refers to the concept of "natural ordering": If the List consists of String elements, it will be sorted into alphabetical order. If it consists of Date elements, it will be sorted into chronological order. How does this happen? String and Date both implement the Comparable interface. Comparable implementations provide a natural ordering for a class, which allows objects of that class to be sorted automatically. The following table summarizes some of the more important Java platform classes that implement Comparable. Is the term "natural ordering" specific to Java, or language-independent? For example, could I talk about "natural ordering" in Ruby? (Note: I'm not talking about Natural sort order, mentioned in Jeff Atwood's blog post Sorting for Humans : Natural Sort Order)

Original source

Related problems