• Post Reply Bookmark Topic Watch Topic
  • New Topic

Appropriate variable names?  RSS feed

 
Amruta Jegarkal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Above is my code.....Suggest me appropriate variable names for i,j,k?
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Ranch,

Always use code tags for your code. That makes it much easier to go through it. I don't think anyone would bear the pain of going through your code until you useCodeTags. So, do it first

Vishal
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suggest me appropriate variable names for i,j,k?

The name you give to a variable should accurately describe its purpose eg if it holds the number of guests in a hotel use something numGuests or guestCount etc.
Many years ago someone far wiser than me told me if you can't think of a good descriptive name for your class, method or variable then stop coding immediately because you clearly don't fully understand the problem.
So basically what I'm saying is you should already know what these variables should be called, so what do they do?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code. I've added them for you this time.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony has given you a good advice about variable names. For what you asked, i, j, k are usually used as loop counters.

You seem to try to write clean code, so I would recommend you also be consistent with code formatting. Choose one style for your code, and try not to change it throughout the code.
 
Amruta Jegarkal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
j is a variable name used in loop so it doesn't matter for it.But k is holding a return value so what name i must give to that and even i is an array which holds return value of executeBacth()?So what kind of name i must use.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amruta Jegarkal wrote:j is a variable name used in loop so it doesn't matter for it.But k is holding a return value so what name i must give to that and even i is an array which holds return value of executeBacth()?So what kind of name i must use.

As Tony said, use a name that describes its use (or contents). In the case of executeBatch(), it returns an update count, so why not call it:
int updateCounts[] = preparedStatement.executeBatch();
or indeed
int batchResults[] = preparedStatement.executeBatch();
?


Winston
 
Amruta Jegarkal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!