Re: how to make a variable based on array length and member value



Catsquotl wrote:
Hi

I have an array full_array[] of an arbitrary number of transaction
objects.
within the transaction is a Date member..

From the array I have created a new array years[].uniq! based on the
Date.year members

what id like to do is take the new arrays members and use them as
names for variables..

Say the array holds members for 2007, 2008, 2009
i`d like to iterate through the full_array and map all members from
2008 in an array.

my options are creating an array based on years.length where each
member holds all transactions from a specific year.

or iterate through the members of years and create an array based on
the value or index of years..

I can`t seem to think of the logic to accomplish this..

Any ideas?

Build up a suite of tests and the code in parallel, like this.

1) Think of a very simple case that isn't yet covered by your code.
Start with a very simple cases, and proceed to edge cases and
pathological cases.

2) Write a new test to run your code and test the result, and run it. It
will fail, because you HAVE NOT YET WRITTEN THE CODE. (If it doesn't
fail, you have made a mistake somewhere).

3) Alter your code to pass the new test and all of the old ones. Only
when this is the case, may you proceed to stage 4.

4) Improve you code in some small way - Remove duplicate code, repair a
bad choice of variable names etc.

5) After each improvement, Rerun all the tests. If any fail, you
introduced an error. Fix before proceeding.

6) When the all pass and your code is nice and clean, save code (and
tests) to the version control system.

7) If the code is not yet complete, go to step 1.

The key is to go in really tiny baby steps at stages 1 and 4, and to
push stage 4 until you have really nice code you would be proud to show
anyone. Note - you are testing for anything that might break/be broken,
not aiming for 100% code coverage.

You will find that defining the tests will clarify your thinking about
what is required. Stage 4 means the code remains clean and easy to
modify. The test suite will stop you introducing errors into your code
later.

When you are done, you have nice code, that you can demonstrate is correct.

Regards

Ian


.



Relevant Pages

  • Re: visibility matter on converting object to array
    ... i'll get an array having keys that from member variable's name ... i guessed "i can get public members but not protected, private, static ... Is it right way to access object members?(by converting to ...
    (comp.lang.php)
  • Re: Array Design
    ... ITOH it's pretty sure you are referencing an element in the array that you ... > When the application starts I initialise a state class, ... > I ask the user how many members to create. ... >>> have exceptions cropping up. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: extract items from list in single field
    ... Try using the Splitfunction to change the delimited string into an array. ... You would then loop through the members of the array and write one record to ...
    (microsoft.public.access.modulesdaovba)
  • Re: how to make a variable based on array length and member value
    ... I have an array full_arrayof an arbitrary number of transaction objects. ... Date.year members ...
    (comp.lang.ruby)
  • RE: Xml serialization, arrays, XmlAnyAttribute
    ... an array type property/member. ... The use case I was trying to implement involved adding an xml attribute to ... .NET class's static members, correct? ... the .NET Xmlserializer based xml serialization ...
    (microsoft.public.dotnet.framework)