Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Armando Moncada
Ranch Hand
Posts: 30
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with assigning the file descriptor to a class called Names?
See line 24
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic