Share your code snippets, screen shots etc. here
TOPIC: Putting the record straight ! zero and one are equally good !!
Putting the record straight ! zero and one are equally good !! 1 year 7 months ago #3238
Hi all X# Forum guys,
For any of you who have read any posts in the Forum about 'zero based arrays' etc., etc., etc. you DO need to read this post - we have been getting things all wrong up until now. All of us.
Only because I have done some serious research for Cologne 2018 have I uncovered the truth, and the truth was not mentioned in any Forum post I was aware of, or internet article either.
Let me explain with just the .NET array class, that in the System namespace.
The Array class can be thought of as a tool (software tool) which we can use to code ourselves all sorts of suitable array based solutions. Works well.
So far we have been focusing on the index base value of the general array 'tool' and not how it can be best used by us - the tool that is..
In playing around with System.Array I found that I could do just about anything I wished, as long as I wrote a small and suitable 'wrapper' class to go around my .NET array.
In the class for System.Array is a static method called 'CreateInstance' and with this we make an array of the size and dimensions we require - BUT - then the trick is to add to the wrapper class a couple of simple methods which converts and translates the index values. So the actual array uses zero as the base of the index but not the developer code which uses the wrapper indexes.
This way we don't code translated values in our methods etc. ONLY in the wrapper class and the Transform/Translate method.
For my "ClickStartXSharp" eNotes I have written a small app to analyse some customer survey results. The results are for three questions (so we have three dimensions) and each answer can range from -3 through zero to +3, with all possible integer values in that range.
The app handles 13,000 customer results in just a second or less. The array I create is a 7 by 7 by 7 (3D) grid and the almost 350 grid points are actually objects in the array called 'XYZ_GridPoint'. For each customer 'landing' on a grid value, the running total value is incremented by one. This way we can tell the most popular answers, and the worst
Below is an image of the analysed results :-
Okay then, what's my point ? It is that in order to do anything to suit more than a trivial business 'case' we need to supply our own index limits, for each dimension, and that writing a wrapper class is almost trivial, but it may be tricky some times. This way we get exactly what each of us requires, 0,1, or +-N, its up to us.
I have found the .NET Array class quite a pleasure to work with once I discovered my previous mistake in misunderstanding what was on offer to us as developers. And, the one base situation does not really change things, we still need a wrapper and to transform / translate index values. We should never have seized on this issue / topic as anything to argue about - we all got too close to it.
The performance of my test app seemed FAST enough indeed. I tested it up to quite a few million survey results, storing each was as an incremented GridPoint property.
Now then, did you also realise that for example a 3D array can be simulated in a wrapper class by providing a simple formula to use X, Y, and Z index values to create a single array index so that elements can be actually kept in a one-dimensional array, but appear to be in a 3D one.
Personally, I would use the 'CreateInstance' overload for 3D as I have done in my "Electric Car" survey results analysis app.
I will update my growing eNotes for 'ClickStartXSharp' before I post you another link to my OneDrive for you to download the upgrade.
So lets put this now 'tedious argument' to bed, and learn from it - .NET gives us the tools, but sometimes we need to shape them a little to suit our needs. Have we got lazy, or do we expect too much from .NET ?
Hope this interest a few guys out there .........