How to determine which object type name will be good?
For example we often see that construction:
Object object = new Object();
or i.e. BufferReader bufferReader = new BufferReader(); - why the type name is BufferReader but no BffReadr for example? Does the type name matter in real life?
Object type name
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
DeCC
24 June 2019, 21:21
I would say it depends on the type of object you're giving the name to. There are many common and often used shorten names for objects, for example:
String s = new String("string");
Character c = new Character('c');
Scanner sc = new Scanner(System.in);
Take these three, they are common names for objects of these types. So people who potentially work with your code, can easily understand it, because they're, in most cases, probably also use these shorten versions in their code themselves.
Shorten names of object types also shorten the code in a whole and make it better to read.
For your example with 'BufferedReader': There isn't really any shorten form that's commonly used and also tells something about the object itself. 'BffReadr' isn't much shorter than the original name and would just complicate it more, so you could just name it 'reader' or something like that.
To wrap it up: Of course you can name any object as you want it to be called. But to make it easy to read and understand for other people and of course for you as well, you should use common names or names that tell what kind of object your handling with.
+1