14/09/2008

Subscribing to teh Squeaksource rss feed

I noticed, browsing around squeaksource today, that it has an RSS feed. Out of curiosity I subscribed, not expecting many changes. Boy, was I surprised. If the feed is correct, i.e. it isn't reporting old changes, then there is a real blizzard of activity. I haven't worked out whether any of it is useful yet, but it is interesting to see what people are working on.

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.

12/09/2008

New day, new problem ;-)

So, after having learned about the CVSParser, I am now becoming more interested in the various squeak repositories. I say, 'various', because there do seem to be a lot of them. And, I don't really understand how the various package management tools in Squeak work.

Monticello, as far as I can tell, is a version management system, and I suspect that I would use it to manage my own code, as well as pull down other people's. The Monticello browser allows me to access numerous repositories. However, there is also a Package Universe browser. This lets me download packages (which seem to be Monticello files) from various sources. It doesn't seem to offer any upload capability, and therefore seems to be a 'consumer' tool. The problem is that this leaves me with several unanswered questions.
  1. Which respositories is the package universe browser accessing?
  2. How is that list kept up to date, and can I/should I add new repositories to the list?
  3. Is this now the preferred way of getting code (a bit like app-get on Linux)?
  4. What about the squeakmap browser, that I stumbled across as well?
  5. Finally, is there any kind of quality control in the packages that package universe lists? I don't mean it in a formal sense, after all no one is really 'in charge' of squeak, but rather is there any kind of rating system, because it seems as though squeaksource and squeakmap contain more items than are listed in the package universe.
Answers must be found!

11/09/2008

Maybe I am beginning to understand this stuff ;-)

This should probably be filed under the heading of "famous last words". However, I have actually succeed in doing something useful with Squeak. I think this is quite an important milestone. Up to this point I have been scratching my head and trying to understand individual methods, whilst all the while feeling that things weren't quite making sense. This evening, however, was different.

After I loaded Avi Bryant's CSV parser, I was able to create a stream from a file, figure out to how process the contents and ended up with an array of OrderedCollections. I wanted to pull the first item from each collection (basically, I was rotating a matrix), and display it in the Transcript. So... I typed in:

(CSVParser on: (FileStream readOnlyFileNamed: 'ifadqs.csv')) rows do: [:each| Transcript show: each first; cr].

And it worked :-)

Starting to use Monticello

Loading Avi's CSV parser, nudged me into using the Monticello browser. I had played with it before, but this time I had to work out how to 'hit' a different server - turns out you just click the +Repository button.

One strange thing about the browser is that I can't work out how to remove repositories from the list. Probably not important at the moment, but curious none the less

Characters != String

I am sure it makes perfect sense but...

The fact that:
$a = 'a'
returns false is a bit unhelpful. Still, worth noting for the future. Also

$a = ('a' at:1)
returns true.

Parsing CSV files and thinking in objects

I have a google spreadsheet that contains the answers to a questionnaire. I wanted to do some simple processing on the responses, so I thought it would be a good idea to use Squeak to munge the data around. However, that raised the question of how to get the data into the system. CSV to the rescue!

Google can export the file as CSV, so I thought it should be reasonably easy to convert it to some sort of OrderedCollection. The question was how to do it? I played around with some methods for a while, and then decided to ask on the beginners' list. The reason I wanted help was that I had the feeling that I was still thinking in far too procedural manner.

Zulq was kind enough to offer this solution
I ususally do something like this:

(((FileStream readOnlyFileNamed: 'file.csv')
contentsOfEntireFile " read and close "
findTokens: String crlf) " split into lines "
reject: [:e | e isEmpty]) " lose empty lines "
collect: [:e | e findTokens: $,] " split into fields "

Regards,
Zulq.


Squeak is so powerful, it is just amazing. It also highlights that I am still nowhere near getting the OO thinking right. Ah well, time enough. However, when I dug into the CSV a bit more I realised that the solution wasn't complete.

The CSV spec covers the situations where:
  1. data fields don't contain embedded commas
  2. where they do
  3. where they contain double quotes
This is important because - basically - if a field contains a comma then that field must be enclosed in double quotes e.g.
this is data,"so, is this"
So the findToken solution wouldn't be quite correct because it would split the line at every comma.

I was pondering this for a while, largely thinking how to solve this in the most elegant way, when it dawned on me that probably I should find the point in the existing solution that would produce the new solution, and create the least disruption - maybe a new heuristic? It seemed to me that if I could subclass (or perhaps replace) the findToken routine, then I would have changed the least amount of code, and still solved the problem. I am not really using the Test Driven Development approach yet - don't understand how to do it at a practical level - but that should be my next move.

Time to write some code