| |||||||||||
| |||||||||||
Bellringing and Programming and Objects and Perl
For the second time this year (and it's only the second month), I find that I have a keen bellringer on my programming course ... he's off each evening to meet up with fellow bellringers in church towers in Wiltshire, and having a really good time outside course hours as well as during the day. I understand that there are a substantial number of excellent sets of bells (I know that the word "set" is wrong) in this area, and I listen in some awe to the complexity described in ringing sequences - how do you get from a string like x16x36x36 to a set of results like:
1 2 3 4 5 6 2 1 4 3 6 5 2 4 1 6 3 5 4 2 6 1 5 3 2 4 6 5 1 3 4 2 5 6 3 1 2 4 5 3 6 1 With so many questions like this one - "how do I get from 'A' to 'B'" - you only need one expert to tell you how to do it, write down and test the algorithm, and then anyone who can provide inputs and read outputs can use the algorithm. In Object Oriented terms, this "hiding information within" approach is known by the term "encapsulation". Helped by 'George' and 'Sandra', I've learn a little about ringing in the last weeks and yesterday George and I put together a sample program to ring some parts of bell changes, using Perl. Not exactly what he'll be using Perl for at work, but a parallel through which he can practise and learn further. Here's some of the code: use bells; push @method,new bells("Plain Bob",8); push @method,new bells("Grandsire Triples",7); push @method,new bells("St Clements",6); $method[0]->setplace("x18x18"); # etc ... $method[1]->setplace("3.1.7.1.7"); # etc ... $method[2]->setplace("x16x36x36"); # etc ... We've set up three methods of ringing, by name and by the number of bells involved in the changes. We've then called a method called "setplace" to define how the changes happen in place notation. Let's then ring the changes: foreach $curr_method(@method) { Printing out a header for each set of changes, and getting back an "action list" of what we need to apply: @chlist = $curr_method->getchanges(); $method_name = $curr_method->getname(); print "Ringing $method_name\n"; @order =$curr_method->getcurrent(); print "@order\n"; And then actually ringing the changes are reporting the order of the bells. foreach $chan (@chlist) { $curr_method->change($chan); @order =$curr_method->getcurrent(); print "@order\n"; } } Yes, that's all there is in my main application! The code that took us a while to work out which interprets the place notation strings and applies it to the rings of bells is all hidden within the file bells.pm which we called in at the top. The typical user doesn't need to know how it works. All they want to do is to run a program like the one above and read: Ringing Plain Bob 1 2 3 4 5 6 7 8 2 1 4 3 6 5 8 7 2 4 1 6 3 8 5 7 4 2 6 1 8 3 7 5 4 6 2 8 1 7 3 5 Ringing Grandsire Triples 1 2 3 4 5 6 7 2 1 3 5 4 7 6 2 3 1 4 5 6 7 3 2 4 1 6 5 7 3 4 2 6 1 7 5 4 3 6 2 7 1 5 Ringing St Clements 1 2 3 4 5 6 2 1 4 3 6 5 2 4 1 6 3 5 4 2 6 1 5 3 2 4 6 5 1 3 4 2 5 6 3 1 2 4 5 3 6 1 I HAVE placed the bells.pm on our website if you would like a look - there's a link to it from our Object Oriented Design - Individual Object module as this complex field has proven to be such a great example of the use of encapsulation, even on a quite small project. (written 2005-02-25 04:34:54) Associated topics are indexed under Q906 - Object Orientation and General technical topics - Object Orientation: Individual ObjectsP213 - Perl - Creating your own Classes P218 - Perl - More Objects
Some other Articles
Feedback as lifebloodCourse sizes - beware of marketing statistics A fortunate accident Beard Justification Bellringing and Programming and Objects and Perl Growing our systems 10 years and counting YOUR application and YOUR data There is a function in PHP to do that Who are all these visitors? 1635 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||