In most languages I’ve used it’s common practice to replace the reserved word class
with clazz
when you have a variable that refers to a class. This has become a sort of de facto convention, to the point where if I see klass
it surprises me.
Is there any “replacement word” that’s even close to as popular for the interface
keyword?
32
No.
If we’re talking about Java, it’s very rare that you need to distinguish a Class
object as being distinct from an interface. They’re all basically types, and calling them all classes is reinforced by the fact that there is only a Class
class (with an isInterface()
method), and they are compiled to .class
files. So I’ve seen clazz
, cls
, c
… clazz
is pretty common.
If you did need to reference something knowing full well that it was an interface, and you wanted to convey that fact, then you’d have to invent your own name; it’s pretty unusual, and you only get conventions for frequently-used concepts.
If I felt compelled to select a name, then why not intyMcInterface? – seeing as how Boaty McBoatface topped the famous Name This Boat poll. Or you could call it sirDavidAttenborough, like they ended up doing, but you might get some WTFs for that.
The reason that you see people trying to name a variable for this is that you can indeed get an instance of the reflective Class
object for a given object. I don’t know of any equivalent object that represents the reflected metadata of an interface.
I would probably still just use cls
anyway.
And I won’t even troll you by “seriously” suggesting you name the variable if
for InterFace.
Using reserved words for variable names is bad form, but it can be done.
C# Example:
string @interface = "Using reserved words for variable names is bad form.";
Console.Write(@interface);
With this in mind. If you have to use a reserved word, try and think of something similar to use instead.
http://www.thesaurus.com/browse/interface
Or preface it with something specific:
- NetworkInterface
- DatabaseInterface
3