14/09/2008

Getting dangerously ambitious!

The other night I worked out how to rotate a matrix. Well, to be more precise, what I actually did was take an Array of OrderedCollections - that held the result of the CSV parsing - and collect up the columns, and write them into a new Array of OrderedCollections.

The code, which is a little messy because it is coming straight from my workspace, looks like this:

newArray1 := Array new: ((oldArray1 collect: [:each| each size]) max)
(1 to: newArray1 size)do: [:count| newArray1 at: count put: OrderedCollection new]
oldArray1 do: [:each| (1 to: each size) do: [:count|| oc2| oc2:= (newArray1 at:count) . oc2 add: (each at:count) ]]


Looking at the code now makes me realise the importance of giving my variables 'intention revealing' names. I must pay closer attention to how the rest of the squeak code is written.

Anyway, having got this code to work, I now want a way to package into something reusable. There are various options, I could add it to Array, I could add it to CSVparser, I could try to add it to either Matrix or Array2D. However, I don't 'own' any of those classes, so although I could subclass them, I really don't know if that is a good way to do it. So, instead, I am going to try to write a CSV Browser. Yes, I am going to delve into Morphic, or Seaside, or perhaps both.

No comments: