After another couple of hours debugging the code, I now have it working for at least 8 x 8 squares (Too time consuming to check it works on larger numbers as I don't have any graphical output yet). I also have it working (I think) in all 4 directions and clockwise or anti-clockwise.
Refactoring the C++ has been pretty painless, for some reason C++ seems to really reward your efforts in refactoring - now nearly every line in the actual recursive methods deals with plotting the curve, with only a couple of calls to a method that tracks it and updates the internal data structures... having just recompiled and checked its just over 200 lines excluding comments. I think if it was any smaller it would start to sacrifice clarity and I plan to write C++ like my Perl - working and clear. Shame there don't seem to be any nice simple unit-testing frameworks like Test::Simple and Test::More, I have found log4cpp which will probably be added to my (currently very small) collection of essential C++ libraries.
Looking at the C++ I can see that I can probably reduce the LoC and improve the clarity and even performance (possibly) of the Perl version. I look forward to having both the C++ and Perl versions side-by-side having both been refactored.
Refactoring code in a different language forces you to look at the original in a different light, I might try and find other modules I have written in Perl and rewrite them in C++, which should improve both my Perl and C++ skills. Oddly writing more C++ means I am rereading K&R with renewed interest, hopefully I should be able to flick through Stroustrop's book with similar interest and ease after another month of two hacking with his creation.
Oh yeah - you can find them on my 'other blog'
Re:OO
TeeJay on 2004-06-15T17:06:18
I like OO, but I like prefer to use it when needed not all the time. Something that works in Perl and to a lesser degree in C++ is to write some procedural prototypes or functions to prove a concept, then refactor and re-implement in purer OO as the requirements and solution become clearer.I assume Ruby doesn't have the 'Everything must be an object' OO puritanism of Java.
I would look at Ruby but getting up to speed on C++ is work enough and I don't see Ruby bringing in a salary anytime soon.
I plan to learn the minimal PHP and Python to get by with those should I need to hack some of either language but I dislike them both (although knowhere near the degree of vbscript).
Perhaps I can look at ruby once I have some more popular and widely-used, if less fashionable and modern, languages.
Besides, by the time I can learn Ruby, Perl 6 will have knicked most of its good bits anyway
;)
Re:OO
djberg96 on 2004-06-15T20:45:48
You are correct - you can use a functional style in Ruby if you wish.I assume Ruby doesn't have the 'Everything must be an object' OO puritanism of Java.Now that you mention it, it might be interesting to see how your code looks in Java.
:) Re:OO
TeeJay on 2004-06-15T23:14:30
who needs ruby when we have scozens;)