Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is isJavaLetterOrDigit deprecated?

Why is the method isJavaLetterOrDigit in java.lang.Character deprecated?

The docs say that the method isJavaIdentifierPart should be used instead, but don't indicate why. The documentation for the two methods is otherwise identical. Googling the subject did not turn up any explanation.

In fact, a source code search shows that nowadays, one just calls the other, so there is no difference in behavior. Was it just deprecated because it had a more confusing name? Seems like a rather strange decision.

@Deprecated
public static boolean isJavaLetterOrDigit(char ch) {
    return isJavaIdentifierPart(ch);
}
like image 880
Antimony Avatar asked Apr 28 '13 02:04

Antimony


2 Answers

The old (deprecated) name does not properly reflect what the implementation actually does; e.g. it accepts characters that are neither letters or digits. I imagine this would have resulted in a few "bug" reports and support requests from confused developers. IMO, that is the most likely reason that they took the (significant) step of creating a new method and deprecating the old one.

(Other reasons proposed by @HuiZheng are valid points at an intellectual level, but NOT sufficient to justify deprecating a method. The Java folks DO NOT go around changing APIs purely on the basis of good API design principles. Deprecating methods makes work for developers, and Oracle does not want to alienate companies who pay those programmers' salaries. Java has gained so much traction in the Enterprise world because of its reputation as a stable platform!)

Anyway, deprecating this method seems (to me) like an obvious and sensible API design decision taken for the right reasons. Either way, our opinions are moot.

like image 156
Stephen C Avatar answered Oct 21 '22 00:10

Stephen C


Reason 1:

A good API name should be abstract enough(but not too abstract). isJavaLetterOrDigit is too implementation-oriented. If you that's what you really want, use isLetterOrDigit instead.

Reason 2:

A good API name should exactly specify its purpose and should be implemented correctly. isJavaLetterOrDigit is misnomer because it actually allows non-letterOrDigit character such as "_" or "$".

Reason 3:

A good API name should be harmonic with others. isJavaIdentifierPart is consistent with other APIs such asisJavaIdentifierStart, isUnicodeIdentifierPart, isIdentifierIgnorable.

Lastly, just because there is no difference in behavior between these two APIs doesn't mean they are identical. Misleading API names poison your code. Furthermore, always dump the deprecated APIs ASAP, as they will eventually(or highly possibly) be dumped by library providers.

like image 26
Hui Zheng Avatar answered Oct 20 '22 23:10

Hui Zheng