Adding appendHex method to StringBuilder

Mark Reinhold mark.reinhold at oracle.com
Mon Oct 2 18:31:22 UTC 2023


2023/10/2 10:01:10 -0400, shaojin.wensj at alibaba-inc.com:
> StringTemplate is great and I wish I can submit PR to improve it. But
> I still think StringBuilder.appendHex is a basic API, not a formatted
> API. Just like Integer.toHexString and Long.toHexString, they are very
> commonly used and should be built-in.

Think carefully about where this leads.

One of the keys to making an API understandable is to have each class or
interface express a single concept with a single purpose.  This allows
developers to build up clean mental models of which part of an API is
used for which functionality, and then cleanly compose them.

When we add convenience methods to a class or interface, we pollute its
design.  If we do so whenever we identify a common method combination
then the class or interface eventually becomes a grab-bag of methods
that perform the functions of two (or three or four ...) classes.  This
muddies the conceptual model, making the API more difficult to use.

Adding convenience methods is, sometimes, justifiable.  The fact that a
particular method pairing is common in a single code base -- even if
that code base is the JDK itself -- is far from a compelling argument.

- Mark


More information about the core-libs-dev mailing list