Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Naming an array with an existing string variable

 
Greenhorn
Posts: 17
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67671
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So would following established naming conventions.
 
Jake Cirino
Greenhorn
Posts: 17
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:So would following established naming conventions.


Alright thank you guys.
 
Marshal
Posts: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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've been selected to go to the moon! All thanks to this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic