This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Naming an array with an existing string variable

 
Jake Cirino
Greenhorn
Posts: 17
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I'm making a ASCII character 'game engine' persay.

I want flexibility for other programmers and ease of making and generating new areas.

So I have a function with 5 params; the character you want to generate, the width and height of the generation, a boolean which determines if you want an array with data of the characters and their positions, and the name of the array.

The problem is, I don't know how to actually take the name that they input into the code and turn it into the array's name.

 
Ashwin Sridhar
Ranch Hand
Posts: 272
Flex Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure the need to have a variable name dynamically. What is the purpose of doing so. If you have something to do with the name given as input and the array, why can you not go for Map. This seems to be weird solution, hoping to get something better.
 
Jake Cirino
Greenhorn
Posts: 17
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Sridhar wrote:I am not sure the need to have a variable name dynamically. What is the purpose of doing so. If you have something to do with the name given as input and the array, why can you not go for Map. This seems to be weird solution, hoping to get something better.

I'm trying to make an ASCII game engine so that other developers can easily render multiple things and be able to keep track of them in an array.

It's just for flexibility and ease of use within the program.
 
Ashwin Sridhar
Ranch Hand
Posts: 272
Flex Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just for flexibility and ease of use within the program


Not sure if this would contribute to the purpose. You could very well have a more meaningful name, say gameEngineArray or something which makes more sense.

One more thing which I would suggest is, instead of using



you could use



This good be a good coding practice.
 
Jake Cirino
Greenhorn
Posts: 17
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Sridhar wrote:
It's just for flexibility and ease of use within the program


Not sure if this would contribute to the purpose. You could very well have a more meaningful name, say gameEngineArray or something which makes more sense.

One more thing which I would suggest is, instead of using



you could use



This good be a good coding practice.

So basically, what I'm wanting to do is impossible in java?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So would following established naming conventions.
 
Jake Cirino
Greenhorn
Posts: 17
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:So would following established naming conventions.

Alright thank you guys.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a very peculiar design you are trying to achieve. The only thing I can think of is that you create a Map<String, Foo[]> and you can put names in as the keys and the arrays as the values. You cannot change the names of variables unless you create a program which emits the code and compiles it later.
As well as naming conventions, please avoid such long lines and use spaces, not tabs, for indentation.
Also avoid == true and == false like the plague, as already suggested.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic