File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What's wrong with assigning the file descriptor to a class called Names? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

What's wrong with assigning the file descriptor to a class called Names?

Armando Moncada
Ranch Hand

Joined: Nov 14, 2011
Posts: 30

What's wrong with assigning the file descriptor to a class called Names?
See line 24


Armando
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Well, actually, in that code you're trying to assign it to a variable called Names, not a class.

But what makes you think there is something wrong with it?
Armando Moncada
Ranch Hand

Joined: Nov 14, 2011
Posts: 30

Well, my nitpicker said, "you're assigning the file descriptor to a class called Names? That can't be right."
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

However, naming conventions dictate that variables should begin with a lowercase character. But it's just a convention (though not following it makes code surprisingly hard to read).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

What Bear said!

Check this out:



You see how similar these two lines are? As a trained Java programmer, because of the capitalization I immediately think these are both static method calls, one on a class named "Names", and one on a class named "Collections". The fact that there is a class named "Names", and it doesn't actually have a method named "close()" is a source of great cognitive dissonance. It's a time waster, now, because I have to figure out what the heck is going on. If the variable name started with a lower-case letter, then I'd know it was a variable, and I'd first find out what type it was before trying to find any information about close().


[Jess in Action][AskingGoodQuestions]
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Also, you're using the name "Names" twice, for two completely different things. One is the static class Names, and the other is for a local variable of type TextFileIn. This would be very confusing even if you weren't violating the name convention that Bear and Ernest are talking about. You should have different names for different things.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's wrong with assigning the file descriptor to a class called Names?