Occasionally, the most logical name for something (e.g. a variable) is a reserved keyword in the language or environment of choice. When there is no equally appropriate synonym, how does one name it?
I imagine there are best practice heuristics for this problem. These could be provided by the creators or governors of programming languages and environments. For example, if python.org (or Guido van Rossum) says how to deal with it in Python, that would be a good guideline in my book. An MSDN link on how to deal with it in C# would be good too.
Alternatively, guidelines provided by major influencers in software engineering should also be valuable. Perhaps Google/Alphabet has a nice style guide that teaches us how to deal with it?
Here's just an example: in the C# language, "default" is a reserved keyword. When I use an enum, I might like to name the default value "default" (analogous to "switch" statements), but can't.
(C# is case-sensitive, and enum constants should be capitalized, so "Default" is the obvious choice here, but let's assume our current style guide dictates all enum constants are to be lower-case.)
We could consider the word "defaultus", but this does not adhere to the Principle of Least Astonishment. We should also consider "standard" and "initial", but unfortunately "default" is the word that exactly conveys its purpose in this situation.
dflt
is a relatively common substitute fordefault
that I'd say everybody would understand. For other reserved words there might be different common substitutions (such asclazz
forclass
, at least in Java) – Darkhogg Jan 02 '17 at 14:29clazz
is practically a de-facto standard. It essentially is part of the platform naming convention. Doing anything else would be a violation of expectations that others might have reading your code, so should only be done if absolutely necessary. – Periata Breatta Jan 02 '17 at 15:08class_
. It's probably aestethically ugly, but I prefer it to mispellings which, if not well known, can be obscure. – Bakuriu Jan 02 '17 at 17:32clazz
are part of Java's standard library. Hard to argue against the designers of the language :) – Andres F. Jan 02 '17 at 18:56clazz
then in the context we're talking about? – Voo Jan 02 '17 at 20:20_class
in Java, somewhat like the Python convention.clazz
is just offensively hideous. – Torisuda Jan 02 '17 at 20:37public <U> Class<? extends U> asSubclass(Class<U> clazz)
fromjava.lang.Class
. How would you refer to the parameter? If you suggest a shorterc
I, being a fan of Haskell, would agree. But Java devs are used to longer names even for generic parameters, so that won't do and it would be a serious violation of naming conventions. What matters is that if you break a widely accepted convention, you're doing it wrong :) – Andres F. Jan 02 '17 at 20:58c
) or appending some filler char (egclass_
which is what python standardized on) are alternatives but none is objectively better than the other. – Voo Jan 02 '17 at 21:32c
in Java, I'd almost immediately assume it's achar
variable. Single-character names were conventionally used for simple, foo-bar-ish primitive values mostly (int i, byte b, char c, boolean b, float f, long l, double d, short s
etc.), withString s
appearing from time to time since it's a commonly used builtin type too (I preferString str
to avoid confusion withshort
; in most contexts the difference between them is obvious enough, though). – Jan 02 '17 at 22:30subclass
? – CJ Dennis Jan 03 '17 at 00:06clazz
you could use a shorter name likec
, like some other languages favor; however with Java you're stuck with existing conventions. When using a language, it's always best to stick to what's already in use, instead of using conventions of, say, Python in Java. – Andres F. Jan 03 '17 at 01:49asSubClass
means it's a class, because a class can't also be a subclass. I'll keep that in mind when I'm programming in Java: Java programmers like to name things misleadingly. I guess all strings should be namedztring
ors
, all arraysarrai
ora
, etc. to avoid confusion. – CJ Dennis Jan 03 '17 at 01:59ztring
norarrai
are needed in Java because neitherstring
norarray
is a reserved word. I've already explained whys
anda
, while not terrible choices, are not the most common in Java (but you'd be fine using this convention in other languages). I understand you might not like the convention, but it's not there for you to like it -- it's there for you to have a common language with other programmers. – Andres F. Jan 03 '17 at 02:04subclass
is a bad name despiteasSubClass
appearing right before the actual class being named? I've obviously missed your point. – CJ Dennis Jan 03 '17 at 02:10subclass
makes no sense. – JollyJoker Jan 03 '17 at 12:49superClass
. Yes, it's still clumsy, but it uses information about the parameter and its properties to name it. No extraneous characters. No spelling mistakes. – MetaFight Jan 03 '17 at 13:50c
is the standard convention. I'd like to use it in Java as well, but it's not the convention there so I usually don't. This is unrelated to cowboy coding and you're using the term incorrectly. – Andres F. Jan 03 '17 at 14:20clazz
is an acceptable name. If it wasn't the convention, then it wouldn't be acceptable. But it is. Following an alternative convention (say, Python's or Haskell's) would be a "less than good" idea ;) – Andres F. Jan 03 '17 at 14:22Default
with no issues at all. – Harrison Paine Jan 03 '17 at 16:15CaseSensitivity.Default
do, for example? – anaximander Jan 03 '17 at 19:07