<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Horse&apos;s Mouth</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/horse/" />
<modified>2012-05-16T16:18:27Z</modified>
<tagline>Musing, events and thoughts from Graham Ellis</tagline>
<id>tag:www.wellho.net,2012:/horse/1</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2012, gje</copyright>
<entry>
<title>QR codes with marketing logos embedded</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003734" />
<modified>2012-05-16T16:18:27Z</modified>
<issued>2012-05-16T16:15:06Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3734</id>
<created>2012-05-16T16:15:06Z</created>
<summary type="text/plain">I&apos;ve been rather interested to notice a number of QR codes turn up recently in which there&apos;s an icon representing the site. Turns out not to be part of the standard library we use, but achievable through a handful of...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>I've been rather interested to notice a number of QR codes turn up recently in which there's an icon representing the site. Turns out not to be part of the standard library we use, but achievable through a handful of sites.  Here are some "marketing" QR code:</p>

<table width=100%><tr><td align=center width=33%><a href=http://www.melkshamchamber.org.uk><img src=http://www.wellho.net/pix/qr_chamber.jpg></a><td align=center width=33%><a href=http://www.grahamellis.co.uk/><img src=http://www.wellho.net/pix/qr_grahamellis.jpg></a><td align=center width=33%><a href=http://mobile.wellho.net/melksham/diary.html><img src=http://www.wellho.net/pix/qr_mobilediary.jpg></a></td></tr></table>

<p>The redundancy within the code is reduced / the size of the code may need to be larger, but it's quite neat.  I'm continuing to study the subject / look for a library that I can use within our website using existing server setups - and certainly I'll be doing demos to people on our courses even though I've nothing in an openly publishable form yet.</p>]]>

</content>
</entry>
<entry>
<title>More hazards of modern life</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003733" />
<modified>2012-05-15T08:23:31Z</modified>
<issued>2012-05-15T08:15:42Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3733</id>
<created>2012-05-15T08:15:42Z</created>
<summary type="text/plain"><![CDATA[Some article headlines in the paper this morning: &bull; Is your child's school bag harming their spine? &bull; Happy Pills can make you more depressed &bull; My beloved chocolate gave me ulcers and heartburn &bull; Why did one of these...]]></summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Some article headlines in the paper this morning:</p>

<p>&bull; Is your child's school bag harming their spine?</p>

<p>&bull; Happy Pills can make you more depressed</p>

<p>&bull; My beloved chocolate gave me ulcers and heartburn</p>

<p>&bull; Why did one of these twins have to die before their cough was taken seriously?</p>

<p>&bull; Moggie lovers beware! One bite from a cat can put you on the critical list</p>

<p>&bull; Girl dies of TB 'after being told she had bulimia'</p>

<p>&bull; No candles - Safety Police ruined my son's 3rd Birthday</p>

<p>&bull; Children planning a gap year?   Read this deeply worrying story before you wave goodbye</p>

<p>&bull; Why mid-life health kicks can WRECK men's bodies</p>

<p>Are we living in a more dangerous world, or is it just a slow news day?</p>]]>

</content>
</entry>
<entry>
<title>Ten more visitors to your premises every day?</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003732" />
<modified>2012-05-14T10:34:55Z</modified>
<issued>2012-05-14T10:33:50Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3732</id>
<created>2012-05-14T10:33:50Z</created>
<summary type="text/plain">Are you a shopkeeper in Melksham? Would you like another ten visitors to your premises every day? Over the past 6 to 8 weeks, I&apos;ve been helping to enhance the diary pages on the Melksham Chamber of Commerce&apos;s web site,...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Are you a shopkeeper in Melksham?  Would you like another ten visitors to your premises every day?</p>

<p>Over the past 6 to 8 weeks, I've been helping to enhance the diary pages on the Melksham Chamber of Commerce's web site, adding in special events and things that are happening in the Melksham Community Area.   Part of that enhancement has been to monitor the number of people who have been reading the diary, where abouts they're located (are they local or not?), and whether they're returning visitors / regular users of the diary, or just "single hits".</p>

<p>On average, we've had ten different visitors to our diary every day <b>from Melksham or from nearby towns</b>.  Within that same day, two or three of these visitors typically come back - and we're looking 'later in the day' here, not simply clicking back to the diary!</p>

<p>Taking a longer view, over 420 visits by over 270 different people have been made to the diary in the past month - that's a significantly higher proportion of repeat visits, and it shows that people are making a habit of coming back to see what's going on.  Only 1 visitor in 20 is from outside the UK, again showing the quality of the traffic as it fits in with the metric of most trader's customer bases.  There is bound to be some "noise" ... and we do get quite a few overseas visitors in Melksham; no great secret that we often have folks in at <a href=http://www.wellhousemanor.co.uk>Well House Manor</a> from overseas - the USA, Switzerland, Germany, and even China in just the last few weeks.</p>

<p><a href=http://www.melkshamchamber.org.uk/addevent.html><img border=0 src=http://www.wellho.net/pix/diaryadder.jpg align=right hspace=5></a><b>Inclusion of your event in the Chamber of Commerce diary is free</b>. It covers events which:<br />
&bull; Run up to ten times a year<br />
&bull; Are open and available to the general public / guests<br />
&bull; Take place in or effect the Melksham Community Area<br />
Commercial, Voluntary and Charity events welcome.  Public meetings and talks welcome. Council and board meetings too.</p>

<p>To view the diary, see <a href=http://www.melkshamchamber.org.uk/diary.html>[here]</a><br />
There's also a version for your mobile phone <a href=http://mobile.wellho.net/melksham/diary.html>[here]</a> (and visits there aren't even counted in my stats)<br />
And to add an entry for YOUR event, go <a href=http://www.melkshamchamber.org.uk/addevent.html>[here]</a>.</p>]]>

</content>
</entry>
<entry>
<title>Now Open - A Museum for Melksham. Come in and see us.</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003731" />
<modified>2012-05-13T10:09:13Z</modified>
<issued>2012-05-13T07:27:18Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3731</id>
<created>2012-05-13T07:27:18Z</created>
<summary type="text/plain">Yesterday morning, 11 a.m., &quot;The Well House Collection - a Branch of the Museum of Melksham&quot; was opened by the Town Crier, taking over one of our smaller meeting rooms as Well House Manor. The room has been fitted out...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p><img src=http://www.wellho.net/pix/opday_0.jpg align=left hspace=5 width=450>Yesterday morning, 11 a.m., "The Well House Collection - a Branch of the Museum of Melksham" was opened by the Town Crier, taking over one of our smaller meeting rooms as Well House Manor.  The room has been fitted out with display cases, panels and boards, with pictures hanging from the picture rails, and some of the larger artefacts being free standing.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/opday_1.jpg align=left hspace=5 width=450>Here's Phil - who's the curator of the collection - showing our Town Crier and an early arrival some of the artefacts and electronic information we have available.  Melksham has existed as a town since Saxon times, and although our current exhibition theme - based on travel and transport - primarily covers more recent times, we've got a huge and proud history to reflect.   With only limited space, and many of the photographic originals being in private collections and not suitable for repeated handling, much of data is provided by computer screen.  And it turns out that scanned photographs, enlarged to fill the screen, reveal far more than could be seen by the naked eye in the original.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/opday_2.jpg align=left hspace=5 width=450>We&nbsp;had an ideal flow of visitors all day yesterday - no big crowds to flood us out (so no need to call in the contingency plan!), but on the other hand we were kept on our feet, and interested all the time.   I only got the time out to get a few photos, as most of the time was spent talking with guests, directing them, and listening to them tell us more about this fascinating town.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/opday_3.jpg align=left hspace=5 width=450>You'll see that all the artefacts in the collection are carefully labelled (and they're catalogued too) - much hard work behind the scenes in recent weeks by Lisa and Phil.  And the cataloguing system continues.   We've been loaned a number of artefacts - nothing of any astounding value, but may unique / sole examples, and it's critically important that we take care of them, know which belongs to whom, and the detailed terms of the loan.  By having such a system in place, we've already been entrusted with a number of very interesting things - some on display, others which have been photographed and returned already.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/opday_4.jpg align=left hspace=5 width=450>Melksham has changed a great deal since the coming of photography, and will continue to change.  The King's Arms and the Church in the town are still recongisable, but some scenes are not.  And although the museum looks at tha past, it must also look to plans for its own future.   Wouldn't it be wonderful to have museum / exhibition space in Melksham's new Campus - to be seen and celebrated by many thousand visitors evey month, and to draw in people from outside the town to look not only at the exhibits, but also to use other Campus and town facilities too.  Truely, the museum can use th epast to help us build for our future.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/opday_5.jpg align=left hspace=5 width=450>And so - my last picture from yesterday is the first taken - before we opened, showing the mix of the old and new technologies to bring history to life and to the people of the town.   Please do come in and see us - <a href=http://www.twhc.org.uk/TWHC/Welcome.html>the museum and current exhibit</a> are open every afternoon from 2 p.m. to 5 p.m. at <a href=http://www.wellhousemanor.co.uk/>Well House Manor</a> on Spa Road, Melksham.  There's so much information that we have in the computers that we can only provide a glimpse - a tiny proportion - via our web sites and the internet - you really need to come in.   And when you do so, please make sure you allow plenty of time to stop and enjoy a strawberry cream tea too.<br clear=all></p>

<p>We finished yesterday tired but happy - indeed, so tired that I fell asleep before I got a chance to write up the day.  And to say "Thank you" to Phil, to Lisa  both of whom who've put so much into this ... and to everyone else too.  I started writing a list - and it's a very long one.  To those who have provided us with encouragement, artefacts and memories.  To the press who have helped us get word out about our launch (and will continue to tell people our success story, I hope).  To those who came along on the day - in both official, supportive and unofficial capacities. To the members of our own staff team who were on hand yesterday and will be on hand today and in coming days.  And to our visitors, without whom the whole thing simply couldn't work.</p>]]>

</content>
</entry>
<entry>
<title>What is a metatable?  How do I set one up? How do I use them? Lua</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003730" />
<modified>2012-05-13T09:48:33Z</modified>
<issued>2012-05-12T15:33:38Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3730</id>
<created>2012-05-12T15:33:38Z</created>
<summary type="text/plain">What is a metatable? In Lua, you can hold a whole bundle of information about something in a table, which gives you a convenient &quot;handle&quot; to that information - be that information in the form of values, or behaviours (i.e....</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p><u><b>What is a metatable?</b></u></p>

<p>In Lua, you can hold a whole bundle of information about something in a table, which gives you a convenient "handle" to that information - be that information in the form of values, or behaviours (i.e. conventional variable of code).  This is illustrated in earlier articles on <a href=http://www.wellho.net/mouth/3725_Lua-Tables.html target=zzz>Lua Tables</a> and on <a href=http://www.wellho.net/mouth/3727_Using-Lua-tables-as-objects.html target=zzz>Using Lua tables as objects</a>.</p>

<p>Let's look a stage further.  As well as unique pieces of information associated with a particular table / object, you'll want to have common members - pieces of code that run on every table of a certain type (in OO terminology, that's methods that can be run on every member of a class).   And this is where <b>Lua Metatables</b> come in.</p>

<p>A <b>metatable</b> is itself a table that contains variables and code.   It can be linked into / called up from any other table (a parent table, if you like) by using the <b>setmetatable</b> function.   And once that metatable has been set, references made to members that do not exist in the main (parent) table will be passed on to the metatable.  This isn't actually a one-to-one mapping - making it a bit harder for me to explain, but much more flexible when I come to use it.</p>

<p>Let's take a look at the standard behaviour of a table:</p>

<p><code>&nbsp;&nbsp;function newtrain(length)	-- set up objectish table<br />
&nbsp;&nbsp;&nbsp;&nbsp;local newone = {}<br />
&nbsp;&nbsp;&nbsp;&nbsp;newone.cars = length<br />
&nbsp;&nbsp;&nbsp;&nbsp;return newone<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;southampton = newtrain(2)<br />
&nbsp;&nbsp;cheltenham = newtrain(3)<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;print (southampton, cheltenham)	-- just prints address</code></p>

<p>And here's the output:</p>

<p><code>&nbsp;&nbsp;munchkin:lm12 grahamellis$ lua kitten<br />
&nbsp;&nbsp;table: 0x100106bb0      table: 0x100106c20<br />
&nbsp;&nbsp;munchkin:lm12 grahamellis$</code></p>

<p>Sample code - <a href=http://www.wellho.net/resources/ex.php4?item=u107/kitten>[here]</a></p>

<p><u><b>How do I create a Metatable?</b></u></p>

<p>Let's now say that I want ALL the tables created by the <b>newtrain</b> function to print out nicely, and I also want the abiity to define how to add such table togethers.   Rather than define all the extra functinallity lots of times, in Lua I can define a <b>metabable</b> and then say (in a single call for each of my parent tables) that the train tables all behave in the way defined in my metatable.  Let's take a look at how that works:</p>

<p>Firstly, I'll create a table (just an ordinary table) which I'm going to use for my additional functionallity.</p>

<p><code>&nbsp;&nbsp;demo_metatable = {}</code></p>

<p>I'll then add some code that's to be shared to that table:</p>

<p><code>&nbsp;&nbsp;function demo_metatable.__add(this, that) <br />
&nbsp;&nbsp;&nbsp;&nbsp;local newone = {}<br />
&nbsp;&nbsp;&nbsp;&nbsp;newone.cars =  this.cars + that.cars<br />
&nbsp;&nbsp;&nbsp;&nbsp;setmetatable(newone, demo_metatable)	-- so that we can piggyback additions<br />
&nbsp;&nbsp;&nbsp;&nbsp;return newone<br />
&nbsp;&nbsp;end<br />
&nbsp;<br />
&nbsp;&nbsp;function demo_metatable.___tostring(this) <br />
	&nbsp;&nbsp;&nbsp;&nbsp;return "A train of " .. this.cars .. " carriages"<br />
&nbsp;&nbsp;end</code></p>

<p>And finally I'll call up that table in my newtrain function as its metatable</p>

<p><code>&nbsp;&nbsp;function newtrain(length)<br />
&nbsp;&nbsp;&nbsp;&nbsp;local newone = {}<br />
&nbsp;&nbsp;&nbsp;&nbsp;newone.cars = length<br />
&nbsp;&nbsp;&nbsp;&nbsp;setmetatable(newone, demo_metatable)	-- so that we add them<br />
&nbsp;&nbsp;&nbsp;&nbsp;return newone<br />
&nbsp;&nbsp;end</code></p>

<p><u><b>How do I use a Metatable?</b></u></p>

<p>Any tables that I now create via the <b>newtrain</b> function will be "tuned" with the features of the metatable called <b>demo_metatable</b> ... adding together two tables (using the + operator) has been defined as producing a new table with "cars" members added, and I've also defined how to print such tables.</p>

<p>So I can now write some code to use these functions and the metatable:</p>

<p><code>&nbsp;&nbsp;southampton = newtrain(2)<br />
&nbsp;&nbsp;cheltenham = newtrain(3)<br />
&nbsp;&nbsp;service = southampton + cheltenham<br />
&nbsp;&nbsp;print (southampton, cheltenham, service)</code></p>

<p>and the behaviour is modified by the __add function so we don't get:</p>

<p><code>&nbsp;&nbsp;lua: tabby:27: attempt to perform arithmetic on global 'southampton' (a table value)<br />
&nbsp;&nbsp;stack traceback:<br />
&nbsp;&nbsp;&nbsp;&nbsp;tabby:27: in main chunk<br />
&nbsp;&nbsp;&nbsp;&nbsp;[C]: ?<br />
&nbsp;&nbsp;munchkin:lm12 grahamellis$ </code></p>

<p>but rather an addition is performed, and our printouts saying:</p>

<p><code>&nbsp;&nbsp;table: 0x100106c20</code></p>

<p>are replaced by the output from <b>__tostring</b>:</p>

<p><code>&nbsp;&nbsp;munchkin:lm12 grahamellis$ lua tabby<br />
&nbsp;&nbsp;A train of 2 carriages	A train of 3 carriages	A train of 5 carriages<br />
&nbsp;&nbsp;munchkin:lm12 grahamellis$ </code></p>

<p>Sample code <a href=http://www.wellho.net/resources/ex.php4?item=u107/tabby>[here]</a></p>

<p><u><b>Adding elements of other names to a metatable</b></u></p>

<p>What if I want to add another name of my own choice to every table of a certain type? I can do it, but <i>not</i> directly by adding that name to the metatable.   Instead, I have to provide a function called <b>__index</b> in the metatable, which can then branch out and act as appropriate.</p>

<p>So if i want this to work:</p>

<p><code>&nbsp;&nbsp;for _,v in pairs(options) do<br />
        &nbsp;&nbsp;&nbsp;&nbsp;print (v, v:getlength(), v.bums, v.capacity, v.earlobes)<br />
&nbsp;&nbsp;end</code></p>

<p>I might add the following to add the required extra definitions to the metatable:</p>

<p><code>&nbsp;&nbsp;function demo_metatable.__index(whichmaintable,whatcalled)<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (whatcalled == "getlength") then return demo_metatable.glen end<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (whatcalled == "bums") then return whichmaintable.cars * 73 end<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (whatcalled == "capacity") then return math.floor(whichmaintable.bums * 1.4) end<br />
&nbsp;&nbsp;&nbsp;&nbsp;return "teabag"		-- default<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;function demo_metatable.glen(source)<br />
&nbsp;&nbsp;&nbsp;&nbsp;return (source.cars * 23)<br />
&nbsp;&nbsp;end</code></p>

<p>Sample code <a href=http://www.wellho.net/resources/ex.php4?item=u107/cat>[here]</a><br />
</p>]]>

</content>
</entry>
<entry>
<title>Then and now pictures of Melksham - on show through the summer</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003729" />
<modified>2012-05-11T22:15:01Z</modified>
<issued>2012-05-11T22:13:15Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3729</id>
<created>2012-05-11T22:13:15Z</created>
<summary type="text/plain">Are you intrigued by the same view taken many years apart? Two pictures of Melksham station (roughly from the same spot), dated &quot;Circa 1940&quot; and Friday, 11th May 2012. There are many more old pictures of Melksham, and new pictures...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Are you intrigued by the same view taken many years apart?</p>

<p><img src=http://www.wellho.net/pix/mkmfse_1940.jpg align=left hspace=5 width=450><br clear=all></p>

<p><img src=http://www.wellho.net/pix/mkmfse_2012.jpg align=left hspace=5 width=450><br clear=all></p>

<p>Two pictures of Melksham station (roughly from the same spot), dated "Circa 1940" and Friday, 11th May 2012.</p>

<p>There are many more old pictures of Melksham, and new pictures too, on show in the Well House Collection - a museum for Melksham - which opens its doors at 11 a.m. tomorrow - that's Saturday 12th May 2012.  It'll be open all day, then every afternoon all through the summer.  Location - 48, Spa Road, Melksham.   Artefacts as well as pictures.   Free entry, free parking ... but please stop long enough to buy a bean-to-cup coffee or a strawberry cream tea.</p>

<p>See <a href=http://www.twhc.org.uk>[here]</a> for the museum website.</p>]]>

</content>
</entry>
<entry>
<title>The future needs for rail services to Melksham - change needed; current service an insult</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003728" />
<modified>2012-05-12T09:28:53Z</modified>
<issued>2012-05-11T10:10:26Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3728</id>
<created>2012-05-11T10:10:26Z</created>
<summary type="text/plain">Do you want to attend an event in London on a Sunday? There&apos;s museums, sporting fixtures and so much more, and what better way than to go by train to London. The requirement was rather proven by last year&apos;s trial...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Do you want to attend an event in London on a Sunday?   There's museums, sporting fixtures and so much more, and what better way than to go by train to London.   The requirement was rather proven by last year's trial service over just eight sundays when a train ran from Westbury at 07:30 with a London connection, and loaded up to some 70 people in spite of not appearing in the printed public timetables and with virtually no publicity.</p>

<p>Those of us who have been involved with rail for a while have heard talk of the "7 day, 24 hour" railway.  Alas, that remains just a pipe dream - an aspiration - and I was rather forcibly remined on that by a request in my mailbox overnight:</p>

<p><b>For the last 4 years I've run the BUPA 10000 in London..... for the first 2 driving up and making a weekend of it and the last two going up on the 07:00 (or near) train on the day just for the race. This year the earliest train from these parts seems to arrive at 09:45 which is no good whatsoever as the race starts at 10:00. I'm wondering if there's a cunning way of getting there earlier?  Race this year is Sunday 27th May (Bank Holiday weekend).</b></p>

<p>Perfectly reasonable requirement, you would have thought.</p>

<p>The first train from Chippenham runs at 08:10, which is scheduled to get into Paddington at 09:44.  Even by driving up to Swindon, you'll catch the same train and only get to London at 09:44.</p>

<p>How about the next line to the south - from Westbury or Pewsey?  Lazy daisies over there - first train out of Westbury isn't until 09:41, getting to London at 11:29, by which time the race is probably over.   How about from Bedwyn, the extreme of the London suburban service which just pokes its nose into Wiltshire?  Oh - the first train from there doesn't run until 09:51, getting to London at 12:22 having had you on a bus for part of the way!</p>

<p>Of course, I (and my correpondent too) live in Melksham, a town of some 24,000 people.  <font color=magenta>Our Sunday train service is totally inappropriate for days out on a Sunday</font>.  First train is at 17:25, with a connection that gets to London at 19:26.  Frankly, the service we're offered on sundays this summer is an insult.   Whilst slightly late for the BUPA 10000 race, last year's 07:45 departure getting into London at 09:44 was a fantastic (and much used, even in 8 weeks) facility that should at least have been offered again this summer, and really should run on every (52) sunday in the year.</p>

<p>My correspondent asked about a "cunning plan".  There are earlier trains on South West Train's line in the south of the county - from Salisbury, there's a train which gets to London at 08:19 - a full hour and 20 minutes before First Great Western wake up and provide a service from Wiltshire; what a pity it's a huge dogleg from Melksham to go via Salisbury and (of course) there isn't an early train from Melksham to Salisbury - in fact the first train there isn't provided until 18:44</p>

<p>What a tremendous scope we have for improvement to something much more appropriate for our needs in the next franchise!</p>

<hr>

<p>A business visitor is coming to see us from the Bristol direction on Tuesday. She's looking to arrive in the town at around 09:30 (and happy to be an hour or so earlier or an hour or so later), and she does not drive.   We don't know how long she'll be with us - best guess is about 4 or 5 hours, so ideally she'll want to return at around 3 p.m. </p>

<p>Bristol is a major city; Melksham's a town of some 24,000 miles just under 30 miles from Bristol, and within Bristol's natural catchment - so this should be easy enough - an hour's journey at the most, right?  <b>WRONG!</b></p>

<p>She'll need to leave Bristol Temple Meads at 05:44, change at Trowbridge (42 minute wait) to reach Melksham at 07:19, as the following train doesn't leave Bristol until 18:30 for a 19:10 arrival in Melksham (to prove it CAN be done in 40 minutes!).  For the return journeys, there's a train at 19:11 and another at 19:48, both taking under an hour. Rather late for that 3 p.m. departure, but those are the first trains after 07:20 in the morning!  <i>Using the bus, the journey of 30 miles from Bristol takes 99 minutes each way</i>.</p>

<p><font color=magenta>Our Monday to Friday public transport service is totally inappropriate for business visitors to our town.</font></p>

<hr>

<p>The train services that we currently have on the TransWilts line that provides the service to Melksham (and from other West Wilts towns to Chippenham and Swindon, and betwen those places and Salisbury) may have been adequate ten years ago - but now they're woefully inadequate and that has a serious negative effect on the economy of the area the line serves.</p>

<p>The current franchise, operated by the First group, runs a service level that's based on usage figures that are now ten years old (and even then were depressed by a lack of trains) and assumed a growth rate of 1% per annum.  Contrast that growth rate to the growth actually experienced in West Wiltshire over the past decade:<br />
<img src=http://www.wellho.net/pix/wcgraphrail.jpg align=left hspace=5 width=450><br />
and you'll see that the figures for train use have nearly doubled - the growth rate's been something like ten times the rate predicted, which was broadly in line with population growth.  Plans simply didn't allow for the modal shift to rail that's happened, and continues to happen.</p>

<p>Graph presented at a public meeting in early April in Trowbridge by Richard Gamble, Portfolio holder for public transport in Wiltshire Council and reproduced with his permission.</p>

<p>What's needed for the next franchise period, then?  Services all day, every day. People will move their journeys forward or backwards by an hour, but not much more - so that's a train every 2 hours.  This appropriate service level has been tested as an economic case - <font color=green>it passed with flying colours</font>.   For operational feasabiity - <font color=green>it passed with flying colours</font>.  In a business survery - <font color=green>it got excellent support</font>.  In a public survey - <font color=green>support is massive</font>.  Even in a trial service last summer - which was <font color=green>so busy it's a victim of its own success</font> this year.</p>

<p>But I do one further samity test.   I real travel requirements I hear of, such as the two at the top of this article, and I measure them against the service that's being asked for.   I ask "would the requested service meet the requirement".   And I get the strong answer, again and again, YES, it would.<br clear=all></p>

<p>Please ... can we have this well researched and appropriate service in the next franchise?</p>]]>

</content>
</entry>
<entry>
<title>Using Lua tables as objects</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003727" />
<modified>2012-05-11T06:40:51Z</modified>
<issued>2012-05-11T06:40:14Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3727</id>
<created>2012-05-11T06:40:14Z</created>
<summary type="text/plain">Since tables in Lua can hold data members of different types, they can be used as the base structure for an Object Oriented design approach, where each table represents an object with numbers, strings, other tables (&quot;objects&quot;) and callable blocks...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Since tables in Lua can hold data members of different types, they can be used as the base structure for an Object Oriented design approach, where each table represents an object with numbers, strings, other tables ("objects") and callable blocks ("functions" or methods) as members.  And if you take it one step further and put all the common code relating to a type of data into another table that's named after the data type, you can in effect design a class.</p>

<p>There's a new example of this <a href=http://www.wellho.net/resources/ex.php4?item=u107/acobj>[here]</a> on our web site, from yesterday's <a href=http://www.wellho.net/course/lua.html>Lua Course</a>.</p>

<p>I created a series of "archive access objects" from our web server log file, where each object is a blog archive request to the server.  The code to create each object (and add it to a table of such objects) is:<br />
<code>&nbsp;&nbsp;pages[#pages+1] = archive.new(num,nam)</code><br />
and I then looped through all members of the table or archive objects, printing out their details:<br />
<code>&nbsp;&nbsp;for _,access in pairs(pages) do<br />
&nbsp;&nbsp;&nbsp;&nbsp;print (access:getnum(), access:getnam())<br />
&nbsp;&nbsp;end</code></p>

<p>As ever with object orientation, the clever stuff is hidden within the class - in this case the archive table which I defined to hold a piece of code called new.  new sets up a new table each time it's called, into which the data, and also a reference to functions getnum and getnam, are stored.<br />
<code>&nbsp;&nbsp;archive.new = function (index, title)<br />
&nbsp;&nbsp;&nbsp;&nbsp;local current = {}<br />
&nbsp;&nbsp;&nbsp;&nbsp;current.index = index <br />
&nbsp;&nbsp;&nbsp;&nbsp;current.title = title<br />
&nbsp;&nbsp;&nbsp;&nbsp;current.getnum = archive.getnum<br />
&nbsp;&nbsp;&nbsp;&nbsp;current.getnam = archive.getnam<br />
&nbsp;&nbsp;&nbsp;&nbsp;return current<br />
&nbsp;&nbsp;end</code><br />
(the originals of getnam and getnum are stored in archive purely for convenience)</p>

<p>Rather than copy all the methods across into each object, Lua includes a facility called metatables that I'll be going on to look at during today's course ...</p>]]>

</content>
</entry>
<entry>
<title>Press Release - Museum to explore the story of Melksham</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003726" />
<modified>2012-05-11T05:50:00Z</modified>
<issued>2012-05-11T05:39:14Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3726</id>
<created>2012-05-11T05:39:14Z</created>
<summary type="text/plain">Press Release: 01/05/2012New museum to explore the story of MelkshamOn Saturday 12th May 2012 a new and exciting museum will open in Melksham. The Well House Collection will explore the story of Melksham through a series of themed exhibitions.The Well...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<table cellpadding=10 width=100%<<tr><td bgcolor=#FFE8DE><b>Press Release: 01/05/2012</b><br><br>New museum to explore the story of Melksham<br><br>On Saturday 12th May 2012 a new and exciting museum will open in Melksham. The Well House Collection will explore the story of Melksham through a series of themed exhibitions.<br><br>The Well House Collection team are now busy preparing the museum and need the help of Melksham residents to help bring the story to life. From keepsakes from the past to trinkets of the modern age, the team needs your assistance in finding objects.  Over the next few months we will be asking for your help to find items for certain themes behind the story of Melksham. The first theme we are collecting items for concerns transport.<br><br>Transport has long been a key storyline in Melksham, from the 17th century when the main stagecoach route between Bristol and London passed through Melksham, to the 18th century when the inland waterways of the River Avon and the Wilts and Berks Canal allowed for a cheaper alternative route; from the opening of the Great Western Railway in the mid 19th century, to the establishment of industries linked to transport in the 20th century. Then there’s the coaches and buses, the bikes, the horses and the cars. Transport gives us many stories to tell - and we need your help in finding items that can help tell it.</td></tr></table>

<p>Opens 11 a.m., Saturday 12th May 2012, at Well House Manor, then every afternoon through the summer.</p>

<p>Well House Manor is on Spa Road (the Devizes road from Melksham's market square), a few hundred yard from the centre of town.  Free parking on site.   Coffees, teas, cream teas available daily. Please do pop in and have a look!</p>]]>

</content>
</entry>
<entry>
<title>Lua Tables</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003725" />
<modified>2012-05-12T09:18:34Z</modified>
<issued>2012-05-10T07:53:26Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3725</id>
<created>2012-05-10T07:53:26Z</created>
<summary type="text/plain"><![CDATA[Lua's Tables are its "collection" variables - in other words, they hold a whole series of other variables, which can be looked up by a key of some sort. I can set up a table like this: &nbsp;&nbsp;occupancy = {2,5,5,3,2}...]]></summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Lua's Tables are its "collection" variables - in other words, they hold a whole series of other variables, which can be looked up by a key of some sort.</p>

<p>I can set up a table like this:<br />
<code>&nbsp;&nbsp;occupancy = {2,5,5,3,2}</code><br />
which will set up a Lua variable called "occupancy" with five members, numbered 1 to 5, with values 2, 5, 5, 3 and 2.</p>

<p>I can then reference the values by their position, using square brackets:<br />
<code>&nbsp;&nbsp;print (occupancy[4])</code><br />
will give me the result <b>3</b> since the fourth element - element number 4 - contains the value 3.</p>

<p>I can change values, for example:<br />
<code>&nbsp;&nbsp;occupancy[4] = occupancy[4] + 2</code><br />
and even extend the table by adding another element onto the end<br />
<code>&nbsp;&nbsp;occupancy[6] = 4</code></p>

<p>I can use a variable to refer to a the position number in a table too - thus:<br />
<code>&nbsp;&nbsp;k=2<br />
&nbsp;&nbsp;print (occupancy[k])</code><br />
will give me the result <b>5</b> as that's the value in the second position (position number 2) of the table.</p>

<p>By using a # sign in front of a table, I can refer to the number of elements in a table - thus I can write a generic piece of code to extend a table:<br />
<code>&nbsp;&nbsp;occupancy[#occupancy + 1] = 2</code><br />
and I can loop through every member of a table such as the one in the example I have used so far using a loop:<br />
<code>&nbsp;&nbsp;roomnights = 0<br />
&nbsp;&nbsp;for k = 1,#occupancy do<br />
&nbsp;&nbsp;&nbsp;&nbsp;roomnights = roomnights + occupancy[k]<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;print ("You have a total occupancy of "..roomnights.." room nights")</code></p>

<p>And I can set up an empty table like this:<br />
<code>&nbsp;&nbsp;another = {}</code></p>

<p>In the example above, I've only stored numbers in my table (in Lua, all numbers are actually double precision floats, so there's no "integer v real" question to address).  But I'm not limited to that - I can store anything that I can store into a regular variable into a table, including:<br />
&bull; a number<br />
&bull; a string of text<br />
&bull; a function (a callable piece of code)<br />
&bull; another table<br />
and I can even store different types of data into different elements of the same table.</p>

<p>There's an example from the course notes - showing what I've talked about above - <a href=http://www.wellho.net/resources/ex.php4?item=u105/tabo>[here]</a>.</p>

<hr>

<p>So far, I have used position <i>numbers</i> starting from 1 within my example tables - and so it's been rather like a <b>list</b> if you're familiar with Perl, Python or Tcl, like an <b>array</b> if you're familiar with C or PHP, or like a <b>vector</b> if you're familiar with C++ or Java.</p>

<p>But in Lua I can go further and use <i>named</i> elements in my table.  That will mean I can compare with a <b>hash</b> in Perl or Java, an <b>associative array</b> in PHP, a <b>dict</b> in Python, an <b>array</b> or a <b>dict</b> in Tcl, etc.  Let's see how that works:</p>

<p>Setting up a table with named members:<br />
<code>&nbsp;&nbsp;roles = {chair = "Sion", treasurer = "Chris", secretary = "Phil"}</code><br />
adding on more:<br />
<code>&nbsp;&nbsp;roles["vicechair"] = "Peter"<br />
&nbsp;&nbsp;roles["press and publicity"] = "Graham"</code></p>

<p>I can then access individual members using the key name:<br />
<code>&nbsp;&nbsp;print (roles["secretary"])</code><br />
or indeed using a variable which contains the role name:<br />
<code>&nbsp;&nbsp;contact = "press and publicity"<br />
&nbsp;&nbsp;print (roles[contact])</code></p>

<p>If I re-use a key as I assign a value, I'm replacing a member (cell) of my table. If I give a new key, then that will add a new member to my table:<br />
<code>&nbsp;&nbsp;roles["supporter"] = "Dominic" -- adds new then ...<br />
&nbsp;&nbsp;roles["supporter"] = "Roger" -- replaces that value</code></p>

<p><i>When I had numbered elements</i> I could easily loop through my table, but now that the elements are named, I can't simply write a loop in quite the same way as the names are unpredictable. However, I'm provided with a function in the Lua standard implementation called <b>pairs</b> which lets me loop through all the  key / value pairs of a table so that I can perform an action on each of them in turn:<br />
<code>&nbsp;&nbsp;for k,v in pairs(roles) do<br />
&nbsp;&nbsp;&nbsp;&nbsp;print (v .. " is in the role " .. k)<br />
&nbsp;&nbsp;end</code></p>

<p>results:</p>

<p><code>&nbsp;&nbsp;Sion is in the role chair<br />
&nbsp;&nbsp;Graham is in the role press and publicity<br />
&nbsp;&nbsp;Phil is in the role secretary<br />
&nbsp;&nbsp;Roger is in the role supporter<br />
&nbsp;&nbsp;Peter is in the role vicechair<br />
&nbsp;&nbsp;Chris is in the role treasurer</code></p>

<p>You'll notice that the order is unpredicatable (and certainly not useful) and this is because a "hashing algorithm" is used, which makes it very fast to access individual elements, but impossible to sort them directly into any form or order.</p>

<p>I can delete individual members by setting them to <b>nil</b>, and I can delete an entire table by setting in to <b>nil</b>.</p>

<p>An alternative notation for table members allows me to replace the pair of square brackets for a named member with a dot - you'll see this commonly used, and forming an object-like approach in the process if you're familiar with object oriented programming.  Thus<br />
<code>&nbsp;&nbsp;print (roles["vicechair"])<br />
&nbsp;&nbsp;print (roles.vicechair)</code><br />
use different syntax to mean exactly the same thing.</p>

<p>There's an example of a table with named members from our course material <a href=http://www.wellho.net/resources/ex.php4?item=u105/taba>[here]</a>.</p>

<p>On yesterday's <a href=http://www.wellho.net/course/ubfull.html>Lua Programming Course</a>, this was the point we got to in tables.  There's an extra colon notation to cover yet, and the whole big subject of <b>metatables</b> ... something for me to come back to later today - or you can find some examples already from the course notes and previous courses via <a href=http://www.wellho.net/resources/ex.php4?item=u107/visit.lua>[here]</a>.</p>

<p>The final example from yesterday is <a href=http://www.wellho.net/resources/ex.php4?item=u105/tinies>[here]</a>. We put together string handling, file handling and tables to produce a useful piece of code which reads the records in a file, etracts some key / value pairs from selected columns, and stores all of the pairs which meet certain criteria.  Once the table has been set up, our demonstration simply prints out the whole table, but we could go on and extend the application to do much more.   In fact, I'm sure we'll start today by sorting the results - it's not directly possible, but indirectly it's very easy indeed when you know how ;-)</p>]]>

</content>
</entry>
<entry>
<title>Learning to Program in Lua - public / open training course / class</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003724" />
<modified>2012-05-12T08:45:35Z</modified>
<issued>2012-05-09T08:01:03Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3724</id>
<created>2012-05-09T08:01:03Z</created>
<summary type="text/plain">Yesterday was the first day of our public &quot;Learning to progam in Lua&quot; course. Lua is an open source language, with a very open license indeed which allows it to be incorporated into other products without raising complex onward licensing...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Yesterday was the first day of our public <a href=http://www.wellho.net/course/ulfull.html>"Learning to progam in Lua" course</a>.</p>

<p>Lua is an open source language, with a very open license indeed which allows it to be incorporated into other products without raising complex onward licensing issues even if the resultant product isn't itself open source.   So this makes it rather good for incorporating into software such as computer games to provide a tailoring interface for knowledgable users.  It has small footprints too, and again that makes it rather good for building into other products, especially where those other products may be running on smaller systems rather than meaty server computers.  Paradoxically, the smaller footprint means that some things are left out of the language - features which are in a standard library routine in Python or Tcl need to be coded from first principles in Lua, or downloaded from another library / source, or built into your own library.  Which makes learning the smaller language a <i>slightly</i> bigger task - I say "slightly" because <a href=http://management.about.com/cs/generalmanagement/a/Pareto081202.htm>Pareto's Principle - the "80:20" rule</a> applies - Lua's a langauge that's less that 20% of the size of others, but actually does well over 80% of what most people want to do with it.</p>

<p>Delegates coming to Well House to learn a programming language come with two different backgrounds.  The first group comes with some prior programming knowledge, and is looking for something of a "conversion course" - there will be things that are different from the langauges they already know, but <b>principles</b> such as naming memory elements ("variables"), conditionals, loops, and named blocks of program ("functions") still apply.  The second group comes without any prior programming experience, and so they need to learn these principles as well as the language itself and how they're implemented in the language.</p>

<p>How do we handle these two different starting points / groups on our courses?   We can't just run a single course.  It would EITHER be far too slow for those with prior experience OR it would be far too fast for newcomers to programming.  But with some of the niche subjects we train in (Lua, Tcl etc), it wouldn't be cost effective to run two completely separate courses.  So here's what we do:</p>

<p>&bull; Newcomers to programing join us on the first day for "Learning to program in XXX" - an easy introduction to the priciples of variables, loops, conditionals, data types, etc, presented <b>in the programming language that they'll be learning all week</b>. This day starts with a blank canvas - no book of "here is one I wrote earlier" examples, but rather with clear explanations from scratch, importantly showing delegates not only what a particular program does but also - and much more importantly - <b>how to write such a program</b>.</p>

<p>&bull; Delegates with prior programming experience join us on the second morning.  A much faster introduction to variables, loops, etc for them - showing too how they differ from the other languages that those delegates know - acts as a re-inforcer of the principles learned on day one by the newcomers to programming, and the course can then carry on with both groups working together.</p>

<p><i>Every delegate on our courses who have prior programming experience was once a complete novice</i>, so those delegates joining us from day two have a tremendous appreciation of what the "day one folks" are going through.  It extends beyond sympathy - it means they can and will provide truely interactive help during practical sessions.  And it means they'll be challenged to explain their own understanding of first principles - a big gain for them in making sure that their groundworks are correct and secure too as we go on through the course.</p>

<p>Our formula for training both newcomers to a language, and newcomers to programming, works in such a way that both receive an excellent course.  Today is the second day of "Learning to program in Lua" and the first day of <a href=http://www.wellho.net/course/ubfull.html>"Lua Programming"</a>.  In about an hour's time, I'll be talking about the principles of variables again, but this time with a slighly more technical slant to paint a slighly deeper picture for yesterday's delagate, and to highlight the differences between Lua, Java and PHP (I'm pre-altered to prior knowledge in my group of those two) for those who are converting.</p>

<hr>

<p>From yesterday's course ... I've put the examples online for the delegates to refer back to later:<br />
&bull; Simple program - read keyboard, calculate, output result in Lua: <a href=http://www.wellho.net/resources/ex.php4?item=u101/simples>[link]</a><br />
&bull; Adding in a condtional test - <a href=http://www.wellho.net/resources/ex.php4?item=u101/easys>[link]</a><br />
&bull; And with a loop, producing a whole series of outputs - <a href=http://www.wellho.net/resources/ex.php4?item=u101/straightforwards>[link]</a></p>

<p>Please follow the course links in this article to read full course descritpions, and find our current schedule of dates, prices, and our location. As well as public courses, we can run private courses at our training centre, or on your site if you have a larger group who require the same course at the same time.<br />
</p>]]>

</content>
</entry>
<entry>
<title>Bank Holiday Monday, so it was pouring with rain.</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003723" />
<modified>2012-05-12T08:38:00Z</modified>
<issued>2012-05-07T23:24:53Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3723</id>
<created>2012-05-07T23:24:53Z</created>
<summary type="text/plain">We have visitors staying at the hotel who arrived over the weekend from China, and wanted to see Stonehenge today. It&apos;s when you get a request like that that you realise just how impractical this is - especially on a...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p><img src=http://www.wellho.net/pix/kbchinastonehenge.jpg align=left hspace=5 width=450>We have visitors staying at the hotel who arrived over the weekend from China, and wanted to see Stonehenge today.  It's when you get a request like that that you realise just how impractical this is - especially on a bank holiday - by public transport.  So I ran them over to Stonehenge, which I've seen before - so the best picture I can give you is the car park.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/kbchinasalisbury.jpg align=left hspace=5 width=450>Then onto Salisbury, with their picture taken to prove their presence here.  Very odd to find those cafes that were open were bursting to overflowing, and yet many places - and the Tourist Information Centre - were closed.  You would have thought that Salisbury would have learned the balance over the years, but it was good to see it busy in stark contrast to Melksham earlier in the morning, where the TIC was also closed.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/kbchinawestbury.jpg align=left hspace=5 width=450>Even the wet weather hadn't dampend the beauty of Wiltshire - the newly-cleaned Westbury White Horse on our way home.  And what a joy to be showing guests around to whom the country was so new - to whom our verant greenness was an excitement, and who delighted in the grass and tree, horses and cows, ducks and swans in Salisbury and the glorious old buildings> They tell me it's very different to Guangzhou<br clear=all></p>]]>

</content>
</entry>
<entry>
<title>Walking by the wiver</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003722" />
<modified>2012-05-12T08:35:37Z</modified>
<issued>2012-05-06T20:19:03Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3722</id>
<created>2012-05-06T20:19:03Z</created>
<summary type="text/plain">The doggies and I went for a walk down by the wiver towards Twowbwidge today. And we took some lovely pictures. There were lots of twains wunning by today - the main Bewks and Hants line being closed for wepair....</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p><img src=http://www.wellho.net/pix/wiver000.jpg align=left width=450>The doggies and I went for a walk down by the wiver towards Twowbwidge today.  And we took some lovely pictures.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/wiver001.jpg align=left width=450>There were lots of twains wunning by today - the main Bewks and Hants line being closed for wepair.  And a beautiful cloudy sky.<br clear=all></p>

<p><img src=http://www.wellho.net/pix/wiver002.jpg align=left width=450>This last week, The Sun got itself into twouble by picking on the new England Football Manager's pronounciations of "r" as "w". Hmm ... it's just a way of speaking - he wouldn't make a speech thewapist but that's not his new wole. (And neither would I, for I have the same thing), but it needn't hold him back<br clear=all></p>

<p><img src=http://www.wellho.net/pix/wiver003.jpg align=left width=450>Trowbridge doesn't have the best of reputations, but beside its waterways it's bustling, and we look forward to waterway improvements in Melksham<br clear=all></p>

<p>The pictures are scaled down on the live blog.  Click <a href=http://www.wellho.net/mouth/3722_Walking-by-the-wiver.html>[here]</a> to see the archive, where they're 9 times the size.</p>]]>

</content>
</entry>
<entry>
<title>Naming blocks of code, structures and Object Orientation - efficient coding in manageable chunks</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003721" />
<modified>2012-05-12T08:34:02Z</modified>
<issued>2012-05-06T11:09:05Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3721</id>
<created>2012-05-06T11:09:05Z</created>
<summary type="text/plain">Soon after you start to program, you&apos;ll learn that you want to re-use code. And that re-use will sometimes come in the form of loops, and at other times in the form of named blocks of code which you&apos;ll call...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Soon after you start to program, you'll learn that you want to re-use code.  And that re-use will sometimes come in the form of loops, and at other times in the form of named blocks of code which you'll call up from multiple places in your program, or indeed from multiple programmers.</p>

<p>&bull; A good programmer is a <b>lazy</b> programmer, who won't want to redo work that (s)he has already done.</p>

<p>&bull; A lazy programmer is an <b>efficient</b> programmer, as that means better use of development time</p>

<p>&bull; A program that was efficient to write because it only includes each piece of logic once is also an efficient program to <b>maintain</b> through its life. <i>There's only one place in the code that needs amending as requirements are updated, or where unplanned circumstances need to be accommodated</i></p>

<p>How do named blocks of code work?</p>

<p>You'll come across words such as <b>function</b>s, <b>subroutine</b>s, <b>macro</b>s, <b>procedure</b>s, <b>command</b>s, <b>macro</b>s, <b>method</b>s, <b>def</b>s <b>callable object</b>s and perhaps a few more, <i>and they all follow similar principles</i></p>

<p>1. In your program, you define one of these blocks of code and you give it a name.  They syntax will vary from language to langauge.</p>

<p>1a. Within the named block, you will make use of a number of <b>parameters</b> - values which are passed in to the named block for it to operate on.</p>

<p>1b. At the end of your block, you will provide a <b>return</b> statement or value, which is the result that's provided to the calling code.</p>

<p>2. Within your main program, you will <b>call</b> the named block.</p>

<p>2a. You will include  in the call which values are to be passed in at that particular place when it runs.</p>

<p>2b. You will take the result that the named block returns and save it to a variable (or test it, or perform further logic on it) in your main program.</p>

<p>Here's an example in Python.   Firstly - the definition of the named block:</p>

<p><code>&nbsp;&nbsp;def capacity(seats_per_vehicle, vehicles):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total_seats = seats_per_vehicle * vehicles<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cap = int(total_seats * 1.4)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return cap</code></p>

<p>Then an example of its use:</p>

<p><code>&nbsp;&nbsp;hs125_v = 8<br />
&nbsp;&nbsp;hs125_spv = 65<br />
&nbsp;&nbsp;london = capacity(hs125_spv,hs125_v)<br />
&nbsp;&nbsp;print "Capacity to London is",london</code></p>

<p>And another example of it use:</p>

<p><code>&nbsp;&nbsp;todays_length = int(raw_input("How many vehicles on the TransWilts? "))<br />
&nbsp;&nbsp;salisbury = capacity(73,todays_length)<br />
&nbsp;&nbsp;print "Capacity on the TransWilts to Salisbury is",salisbury</code></p>

<p>Sample output:</p>

<p><code>&nbsp;&nbsp;munchkin:rcp grahamellis$ python pyfunc <br />
&nbsp;&nbsp;Capacity to London is 728<br />
&nbsp;&nbsp;How many vehicles on the TransWilts? 2<br />
&nbsp;&nbsp;Capacity on the TransWilts to Salisbury is 204<br />
&nbsp;&nbsp;munchkin:rcp grahamellis$</code></p>

<p>The names that I've used in the function definition (seats_per_vehicle and vehicles) are generic names - in other words, a common name that might be applied to any set of values passed in when considering the functionallity that's being provided.</p>

<p>The names used in the calling code are more specific - and indeed they can be variables, constant values, or even expressions.</p>

<p>The values passed in are position dependent.  The function requires two paramaters in this example, so the call must be made with two values.   The first of these values is passed into the first named parameter, and the second value is passed into the second named parameter.</p>

<p>In most langauges (including Python, used above, and C and C++, below), variablenames within the named block of code are in a different <b>namespace</b> to variables in the main code.  In other words, it doesn't matter what names are used within the function - they can't be seen in the calling code.   They could even be the same names, but they're actually different memory location.   <i>Think of it like forenames and surnames.   I talk about "John", but "John Smith" and "John Brown" are different people.</i></p>

<hr>

<p>But there's very often much more than just two numbers to be passed into a function - you'll very often have a whole raft of values and the calling sequence would expand from one or two parameters to a very much higher number if something better wasn't done.</p>

<p>As a starting point for this demonstration, I've placed a C function definition and used in a sample program <a href=http://www.wellho.net/resources/ex.php4?item=q906/after2.c>[here]</a>. The function has two parameters - a width and a height:</p>

<p><code>&nbsp;&nbsp;float getdoggie(float w, float h) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;float rv;<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (w > h) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rv = h/2.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rv = w/2.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;return rv;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></p>

<p>and so it's called with two parameters:</p>

<p><code>&nbsp;&nbsp;d = getdoggie(w,h);</code></p>

<p>Using a <b>structure</b> in C, we can gather all of the values we want to handle in our function into a group, and simply pass in the group (or, better, the address of the group) into the function.   Sample code <a href=http://www.wellho.net/resources/ex.php4?item=q906/after3.c>[here]</a>.</p>

<p>Structure definition:</p>

<p><code>&nbsp;&nbsp;typedef struct {<br />
&nbsp;&nbsp;&nbsp;&nbsp;int width;<br />
&nbsp;&nbsp;&nbsp;&nbsp;int height;<br />
&nbsp;&nbsp;&nbsp;&nbsp;char *material; } table; </code></p>

<p>The function definition then has only a single parameter:</p>

<p><code>&nbsp;&nbsp;float getdoggie(table current) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;float rv;<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (current.width > current.height) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rv = current.height/2.0; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rv = current.width/2.0; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;return rv; }</code></p>

<p>and it's called with a single parameter:</p>

<p><code>&nbsp;&nbsp;d = getdoggie(mytable);</code></p>

<p>With a structure, it's still possible to call a function on the wrong type of structure, and each function name can only be used once.   By adding the object oriented language facilities of C++, we can also associate named blocks of code with particular pieces of data.  Not only does this tighten up on possible erroneous use, but it provides a separate namespace.  And in turn that leads to us being able to share code within truely massive programs, but have that code well segmented for tested and maintainance purposes.   The full example showing this from <a href=http://www.wellho.net/course/c.html>last week's C and C++ course</a> is shown <a href=http://www.wellho.net/resources/ex.php4?item=q906/develop.cpp>[here]</a>.</p>

<p>Here's the function definition:</p>

<p><code>&nbsp;&nbsp;float Table::getdoggie() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;float rv;<br />
&nbsp;&nbsp;&nbsp;&nbsp;rv = ((this->width > this->height) ?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this->height : this-> width ) /2.0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return rv;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></p>

<p>and the call to it:</p>

<p><code>&nbsp;&nbsp;float reach = dining.getdoggie();<br />
&nbsp;&nbsp;cout << "Dog Reach " << reach << endl;</code></p>

<p>The next series of public C and C++ courses runs in mid July ... if you're coming late to this article, though - don't worry.  The course runs again in the autumn, and there will be three or four opportunities next year too <a href=http://www.wellho.net/course/index.html>[schedule]</a>. If you've got a group of 4 or 5 (or more) delegates, it's probably more cost effective for us to run a private course for you; that way, the course can be tuned to the exact background and target application of your delegate group.  </p>]]>

</content>
</entry>
<entry>
<title>Melksham ATC - freedom of the town</title>
<link rel="alternate" type="text/html" href="http://www.wellho.net/archives/2012/05/index.html#003720" />
<modified>2012-05-12T08:15:49Z</modified>
<issued>2012-05-05T11:42:23Z</issued>
<id>tag:www.wellho.net,2012:/horse/1.3720</id>
<created>2012-05-05T11:42:23Z</created>
<summary type="text/plain">Pictures from this morning in Melksham - Melksham ATC is awarded freedom of the town...</summary>
<author>
<name>gje</name>

<email>graham@wellho.net</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.wellho.net/horse/">
<![CDATA[<p>Pictures from this morning in Melksham - Melksham ATC is awarded freedom of the town</p>

<p><img src=http://www.wellho.net/pix/atc000.jpg align=left hspace=5 width=450><br clear=all></p>

<p><img src=http://www.wellho.net/pix/atc001.jpg align=left hspace=5 width=450><br clear=all></p>

<p><img src=http://www.wellho.net/pix/atc002.jpg align=left hspace=5 width=450><br clear=all></p>

<p><img src=http://www.wellho.net/pix/atc003.jpg align=left hspace=5 width=450><br clear=all></p>

<p><img src=http://www.wellho.net/pix/atc004.jpg align=left hspace=5 width=450><br clear=all></p>

<p><img src=http://www.wellho.net/pix/atc005.jpg align=left hspace=5 width=450><br clear=all></p>]]>

</content>
</entry>

</feed>
