Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TeeJay (2309)

TeeJay
  (email not shown publicly)
http://www.aarontrevena.co.uk/

Working in Truro
Graduate with BSc (Hons) in Computer Systems and Networks
pm : london.pm, bath.pm, devoncornwall.pm
lug : Devon & Cornwall LUG
CPAN : TEEJAY [cpan.org]
irc : TeeJay
skype : hashbangperl
livejournal : hashbangperl [livejournal.com]
flickr :hashbangperl [flickr.com]

Journal of TeeJay (2309)

Tuesday June 15, 2004
07:04 AM

'Final' version of C++ class for Hilberts Curve

[ #19261 ]
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'

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If you find yourself enjoying the OO paradigm, might I suggest learning a bit of Ruby and seeing how it stacks up against the Perl and C++ versions? If not, I'll await your final Perl product and see what I can come up with. :)
    • 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

      --

      @JAPH = qw(Hacker Perl Another Just);
      print reverse @JAPH;
      • I assume Ruby doesn't have the 'Everything must be an object' OO puritanism of Java.
        You are correct - you can use a functional style in Ruby if you wish.

        Now that you mention it, it might be interesting to see how your code looks in Java. :)

    • who needs ruby when we have scozens [cpan.org] ;)
      --

      @JAPH = qw(Hacker Perl Another Just);
      print reverse @JAPH;