• Post Reply Bookmark Topic Watch Topic
  • New Topic

array maybe? args array? not sure need help  RSS feed

 
Christina Fox
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CAn someone please tell me what this piece of code does. I think it creates an array or something, maybe the args array, but I'm not sure I've never used this before, I'm very new to java and programming.
It's important I understand this...

Any help is appreciated. Thanks



 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It defines a bunch of array variables and allocates the corresponding arrays. If you want to learn more about Java arrays, see here or your text or tutorial of choice.

I'm not sure what that particular code is intended to be used for, but whatever it is, it's lousy design.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
I'm not sure what that particular code is intended to be used for, but whatever it is, it's lousy design.


Jeff how do you consider that as a lousy design?? is it because all the variables are declared at one go..?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ishan Pandya wrote:
Jeff Verdegan wrote:
I'm not sure what that particular code is intended to be used for, but whatever it is, it's lousy design.


Jeff how do you consider that as a lousy design?? is it because all the variables are declared at one go..?


That wasn't what I was thinking, but yes, it's also poor form to declare multiple variables on one line. That's not a design issue though; it's just coding style.

The bad design is this:



1. Hardcoded length values rather than named constants. (Debatable, if they're all one use only.)

2. None of those makes sense as an array of Strings. Either the variables are very poorly named, or else the author thinks he's creating a couple Strings that can be up to length 20, one that can be up to length 50, etc., which means he's confused about a very fundamental Java concept.

3. Maybe the author meant those to be char arrays instead of String arrays. That makes more sense for what they're named, but that's still the wrong approach. If he wants strings he should use String, not char[]. And if he wants length limitations, there should be validation methods to handle that.

4. If we take the length, validation, and semantics notions a step further, then rather than Strings, there could be a Name class, a Street class, etc., that could each implement a common interface and/or extend a common abstract base class, and each could have its own validation method.

5. If those items are ever going to be used together outside the main method, then a class should be defined to encapsulate all of them.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That really added up in to my knowledge.. thaks jeff for the details of design..
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
1. Hardcoded length values rather than named constants. (Debatable, if they're all one use only.)


For that you meant like using "Final Variables" as named constants? right?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ishan Pandya wrote:
Jeff Verdegan wrote:
1. Hardcoded length values rather than named constants. (Debatable, if they're all one use only.)


For that you meant like using "Final Variables" as named constants? right?


Yes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!