Naming things
Philpax via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 20 03:13:01 PDT 2015
On Saturday, 20 June 2015 at 09:27:16 UTC, Vladimir Panteleev
wrote:
> Naming things
>
> There are only two hard things
> in Computer Science: cache
> invalidation and naming things.
> -- Phil Karlton
>
> Hello,
>
> There has been a lot of recent debate regarding the names of
> some new functions recently added to Phobos.
> ...
I'd like to note my support for consistent/standardized naming
(especially with regards to `withExtension`/`setExt`). As an
end-user of D, it's very important to me that a precedent be set
for naming prior to D releases - it means less time spent upfront
perusing documentation, and less time spent trying to understand
how a particular function works. When I'm viewing code "in the
wild," so to speak, time spent trying to understand byzantine
names is time wasted.
In this particular case, `withExtension` is objectively better
than `setExt.` The `with` prefix indicates lazy operation - this
is a much better cue as to the function's operation than the
truncation of an already-existing name. Truncating the name will,
without a doubt, lead to user confusion: these two functions have
the same goal, but operate in fundamentally different ways, and
the name should reflect this. The alphanumerical sorting argument
has little validity, especially seeing as the "See Also" section
serves the same purpose.
I understand that the community's been beset with naming
discussions for the longest of times - and yes, they can often be
non-productive - but there are some cases in which it is very
much worth the time choosing a better name. `setExt` is
objectively confusing and uncommunicative of its actual
functionality - and it can be fixed now, before it becomes a
permanent wart.
As a final note, naming conventions are very important for the
end-user of a programming language. If one goes with a 'pick the
first name that works' approach, the result is a very
unproductive, contradictory language; an extreme example of this
can be seen in PHP, where programmers often have to consult the
documentation for *every* function to find the correct name for
every function. We have the ability to prevent that from
happening here.
More information about the Digitalmars-d
mailing list