Saturday, 14 December 2013

Maven (not the space probe)

Until recently I had always used ant and ivy to manage building my Java projects. It works well except for one really annoying thing. Actually maybe it is several. When you have a team of programmers maintaining ant scripts it is easy for standards to drift, various projects have 'special needs' in their builds and that has to be catered for. Sometimes people just create projects with a different directory structure because they feel like it. I'm all for freedom of choice in these matters, except when it is late at night with a delivery in the morning and I am trying to work out someone's odd build arrangement that isn't working. Then my inner fascist surfaces and I wonder if we couldn't do better.

So I moved all (um, nearly all) my projects to use an included ant file containing all the standard targets we need for a build and the builds just have to conform to those. That worked quite well, then the really annoying thing turned up.

I wanted the builds to be easy to get started, so you can pull the project from source control and just run the build. I'm assuming ant is already installed, but I'm not assuming anything else. What about ivy? Okay, my included file looks for an ivy directory and pulls the ivy jar file if it isn't there. Ivy pulls everything else.

What about the include file? Well that has to be committed into the project. But it is the *same* include file in every project, committing multiple times violates DRY. Yuck. Plus when I change it I have to change it in lots of places, well that's why we say DRY, isn't it?

You've already seen the title so you know where I'm going. I thought I would try maven. Maven uses plugins to do those targets the include file delivers but, because plugins are just jar files they can be managed as dependencies, so maven will pull whatever plugins I specify from the repository. They've pretty much all been written already and I just have to conform to the standards they dictate. That means so does everyone else and we all understand they layout etc of our projects and how they are built. Great. Even better, you just have to have maven installed then any build you pull can be just run by invoking maven. No need to do tricky things with a dependency manager. The entire build+dependencies for the project is defined in a pom.xml file.

How does this work in practice?

Quite well, better than I expected in fact. But there are a some tricky bits that weren't immediately obvious.

First, all my builds use MaduraDocs which was basically an xsd to define the format, a couple of xsl files and a load of ant files to pull it together. Every build uses MaduraDocs. So it was immediately clear this would have to be a maven plugin. That was good. Rewriting the scripts into Java made them simpler and I could make use of some OO techniques to make things more flexible. I ran into one issue there: how does a project build when it depends on a plugin that is itself. MaduraDocs depends on the MaduraDocs plugin. Well, I cheated a little. I invoke the MaduraDocs code from one of the tests and that builds the documentation for MaduraDocs itself, rather than invoking the plugin.

The next challenge was MaduraObjects. MaduraObjects is a JAXB plugin. Not to be confused with a maven plugin. Though, and here's the tricky bit, there is a maven plugin for JAXB called maven-jaxb22-plugin. maven-jaxb22-plugin  accepts JAXB plugins and MaduraObjects is one of those. My initial approach was to simply add maven-jaxb22-plugin to my project and have it run, invoking the MaduraObjects code. Except it doesn't. For some reason I did not figure out it refused to find the MaduraObjects code so I had to try another approach. Again I fell back on tests. I wrote a test that invokes maven-jaxb22-plugin making sure the MaduraObjects code is on the classpath and that works. It results in some generated Java which then needs to be recognised by the phase that compiles the test code. To do that I use the build-helper-maven-plugin which can tell maven to include another directory in with the test code. If you use the build-helper-maven-plugin just right the Eclipse maven plugin uses it to recognise the generated source directory and adds it to the project classpath, that avoids various red Xs in Eclipse.

MaduraBundles is even more fun. The test code requires three small jar files to be built and loaded into a sweep directory. MaduraBundles loads small jar files as sub-applications and the tests have to try that out. Maven is *very* keen on the 'one project one output' approach and this project doesn't actually violate that, it just needs to generate some test jars. This is the most complex and the oddest of my projects. It works and is not so very complicated, but I suspect this is a rare case of extreme complexity.

Finally MaduraRules needed another maven plugin and this one generates source files, so it has the same issue that MaduraDocs has in that it must avoid invoking itself, and it needs to have the generated code added to the test code for compiling. In practice the code that does the work is invoked by tests in the MaduraRules project and the plugin is a simple wrapper to that code placed in a separate project.

These tricky bits took some working out but overall it ends up simpler, I think. One of the things that made me sceptical of maven initially was how I would handle the various configurations I was using in ant+ivy. When using Ivy I normally had configurations for test, compile, package, build and so on. I could define whatever ones I wanted and just use them. I could pull all the dependencies of, say, the build configuration, into a directory and use that as the classpath for the build. Specifically I would use this for invoking JAXB to generate Java from an XSD file or to generate rules from a rules file. I knew that maven had more strictness around this with a specific set of phases that, while it could be extended, was best left alone. How would I manage my builds?

The answer is delightfully simple. Because plugins can have dependencies and those dependencies are managed by maven directly you don't need a build configuration, you just specify the plugin you want. The dependencies of the plugin are distinct from dependencies of the project itself. So I don't need a build configuration anymore, nor do I have to write scripts to pull the build dependencies into a directory. As for compile, test and package there are equivalents in maven. Test dependencies are only used in the test phase, compile dependencies are everything the project needs to compile against and these are always packaged as well. There is sometimes a case where the project needs to compile against something but not package it, in this case you tell maven it is 'provided'.

There are some more things in maven that I haven't had to look at closely. It seems the pom.xml file can specify a parent to inherit, which means if you have a lot of common stuff in your pom files you can consolidate that into one file and inherit it. Superficially this looks like the included ant file I mentioned earlier but there is a key difference. The parent pom file can be kept in the repository and fetched by the maven dependency manager. That means you don't have to violate DRY, and you still don't have to jump through hoops to get the parent file into your project.

So for me the maven builds turn out generally simpler, more consistent and there is no violation of DRY.

Friday, 13 December 2013

Tama Lakes


This is a picture of the Upper Tama Lake near Mt Ruapehu which is in the middle of the North Island of New Zealand.

It is also a picture of my foot, but we'll come back to that. Know for now that the foot is deliberate, not a mistake.

There are two Tama lakes, an upper and a lower and they are both volcanic craters. Pretty much everything in this area is volcanic and they used places like this to stand in for Mordor in the LOTR movies. Ngaruahoe, the mountain they used for Mt Doom is the rising edge on the left of the picture.

To get to the lakes takes about three hours walk from Whakapapa Village, which you can drive to. I've walked this track three times now and the last time I did it the Whakapapa end was a bit dodgy and hard going. I'm pleased to say there has been a lot of good work done there. Much of the track would be okay to walk with a pushchair if you had to. There are some steps here and there but the rest of it is nicely gravelled walkways and quite a lot of it is flat.

However once past the lower lake the going is a bit tougher because the track degenerates to a 'poled route' by which you scramble up a steep slope and along a ridge. It's only about 45 minutes going and not too tough really, and from the ridge top you get this view to the upper lake. Then you turn around and go back.

Now about the foot.

You'll notice I am not wearing boots, I'm wearing sandals. I have boots but I've given up wearing them. The sandals, sometimes padded with socks as shown but usually not, really do the job for me. They don't compress my toes like boots do and even over rough ground they seem to protect my feet just fine. If I have to wade a stream they dry out faster (I take the socks off first). This track does not require stream wading, plenty of streams but there are bridges if the stream is bigger than a jump.

If I were walking through serious snow I'd probably wear boots, though earlier this year I was happily walking through light snow in sandals without socks. These are, of course, heavy duty sandals and they can take a bit of punishment. Mine are Tevas, but Mrs has a different brand so the particular type doesn't matter too much I think.




The socks also keep the sun off my feet which mattered on this occasion because I was silly enough to forget to put sunscreen on the rest of me (cloudy day... not really an excuse) and I paid for it later on my knees, nose and hands. But my feet were fine.

Saturday, 7 December 2013

The Waters of Mars

If you haven't seen it, 'The Waters of Mars' is an episode of Dr Who in which some alarming things are discovered about frozen water beneath the Martian surface, and some other alarming things are discovered about the crew of the first manned Martian base (a British one, of course). It is a good yarn and it gave me the idea for this post.

But this is not about strange things in the Martian water, it is more about the water itself and the fact that is seems to be there at all, or possibly it isn't now, but it definitely was once, which is more or less the point.

When I was a kid I read stories by Heinlein and Blish where people (mostly kids, actually) wandered about the surface of Mars and found it a challenging environment but not much more challenging than, say, Antactica. The air pressure was lower and it was a lot colder, but with some breathing apparatus and suitable clothing, trekking across the Martian wastes was practical enough. And there were signs of life. Lichens mostly but, in Heinlein's stories, more sophisticated plants as well as animal life and even intelligent life. There was a sense that the environment had once been a lot more friendly to our kind of life but it had changed for some reason and this was all that was left. The Dr Who episode followed a similar line.

The recent rover missions to Mars support the idea that Mars once had a decent atmosphere and running water on its surface. The two go together. Under very low pressure, such as that on Mars today, water boils even at low temperatures and doesn't exist long in liquid form. So to support the geological findings of old stream beds etc there needs to have been more atmosphere, and for the water to not be frozen, it needs to have been warmer.

The science fiction I read as a kid was more hopeful than the science at the time. Although a few decades earlier some astronomers had suggested there was a global civilisation on Mars, we all knew that it was too tough an environment to support any such thing. Very little atmosphere, harsh radiation and very cold. If there was any life there it was hard to see how it could have started, let alone survived.

Did you spot the mistake there? Actually there are two of them, but the second one is subtle.

The more obvious mistake is the problem of induction. We make observations and we assume that what we see is how things are, which is okay. Then we project those observations to say something like 'it has always been like this' which is not so okay. We also often project them to say 'it is like this everywhere', in this case everywhere on Mars but we are pretty quick to project our findings to everywhere in the universe. For example the speed of light, the law of conservation of mass and even the notion of cause and effect, we assume to apply everywhere. We do this because we don't have better information. When we get better information (evidence that Mars has had a different environment in the past) we find we were wrong and we have to adjust our thinking. Being willing and able to adjust our thinking is a huge virtue, clinging to outmoded ideas in the face of conflicting evidence is not, though sometimes people try and say it is. But adjusting our thinking doesn't solve the problem of induction. We might be wrong about everything because of this.

The less obvious mistake involves just why we keep on inducing things despite it being obvious that we keep getting it wrong. We insist on keeping to the simplest explanation we can come up with. It is so much simpler to assume that things are consistent across space and time, simpler to assume Mars has always been the same as it is now, so that is what we do. Then we find it is more complicated and have to adjust. The simplest explanation seems to be actually never the right answer, though it is a long tradition in science and any other form of knowledge that keeping things as simple as possible is a good thing. But we need to be clear eyed about this. We pick simple explanations because we like them, not because they are in any way better or more true. We simply choose to believe, for the moment, until we are proven wrong anyway, that the simpler explanation is correct.

We think we know how the Martian water got there, something like icy meteorites crashing into the planet, possibly even bringing the strange life forms in the Dr Who episode. But it might have been something completely different that is much more complicated. In fact, it probably was.

Wednesday, 4 September 2013

Teensy3 piggyback board

This is about the PCB I made that adds some functionality to the Teensy3.


The Teensy3 has a MK20DX128 32 bit ARM Cortex-M4 processor on board, as well as a USB interface and a heap of other handy stuff, not all of which I pretend to understand. The whole package is just over an inch long so it is suitable for use when you need a processor but there is no room. The kinds of things I build such as the laser pistol and the vortex manipulator tend to be tight for space so larger platforms, such as the Arduino aren't really an option.

But Arduinos do a neat trick with their shields. Each shield is a board that plugs into the basic Arduino and adds functionality. They're designed so you don't need to even solder them, which isn't a goal for me, but the notion of using a fairly standard add-on board to the main processor board definitely is. Even so the basic idea for this came from Paul Stoffregen, the guy who makes the Teensy boards, he sells several add-on boards for his other Teensy models.

The board we're looking at here has several functions, these are things I keep needing in my projects and having a way of adding them compactly to an already compact platform is the main goal. I can add them in other ways but they all take up more room and, actually, end up more difficult. Here are the functions:
  • Micro SD Card. These are the little cards that fit inside phones and some cameras. They can hold a lot of data and they basically replace the disk drive a larger machine would use.
  • Battery charger. The Teensy gets power from the USB port by default, but when you want an untethered device you need a battery and you want a way to charge the battery. The right battery is a LIPO because its power to size beats the other technologies. This is why they use them in phones. But they are complex to charge and if you do it wrong they can catch fire and explode. So I wanted a reliable charging circuit that also fed off the USB port. I don't want a second thing to plug in, that's a waste of space.
  • Voltage measure. I want to be able to measure the voltage the battery has so I can pass it to the processor which can then display it somewhere eg on a screen.
  • Boot button. The Teensy3 has a button on it that causes it to reboot. My board will, of course, cover the button (unless I put it the other way up, but there are reasons not to). So I need to add a similar button to my board to do the same thing.
The process for making this is really very standard stuff, but this is the first time I did it myself so I'm documenting it for myself and any other first timers who want to read along. The resulting board is a PCB with SMD parts soldered to it. Here are the steps I took:

Design the circuit

I used Eagle V6.5, which is free and runs on Linux. Probably other places too but Linux is what I use. I used someone else's charger circuit based on the MCP73831 chip. With Eagle, and probably similar systems, you sketch out the schematic (sch file) which is basically a circuit diagram and then you press a button and it generates a board (brd) which shows how the final board is laid out. There are a number of tricks to all this but I don't want to rewrite the Eagle docs here. It isn't particularly hard. You can nudge things around and get things positioned sensibly and so on. Part of this involves getting hold of the part description of each part you want. For the most part the Eagle libraries contain everything you need but I had to hunt around for a switch and the SD card description. You can make your own descriptions but I didn't want to introduce that level of complexity this time around.

Upload the Design

Upload the design to OSH Park. These guys will, for a small fee (just over$NZ5 for three of these in my case, including shipping) make the boards. The boards come with wire traces through them and pads to attach the parts. They take about 3 weeks to deliver to me from the US. Your freight time might be shorter.

If you want to use my design you are welcome to. I have uploaded it to google code.

Get the SMD parts

These can be ordered from lots of places, such as element14 or mindkits. Those are New Zealand links, you may have more local ones. Parts like these are mostly really small, just little specks, and they come in tapes suitable for feeding into the huge pick-and-place machine you have in your cellar allowing you to mass produce your device... you don't have a pick-and-place machine? Neither do I. Read on.

Get some solder paste

It comes in tiny quantities, I got a 40g punnet. It goes off so you don't want to stockpile it and you need hardly any. To make one board I used just about none of the 40g, ie I can't see the difference. It is odd stuff. It behaves like paste at room temperature but when you heat it up to about 200C it liquefies and then goes solid as it cools down.

When cooled it is like ordinary solder, ie shiny, conductive and quite solid, no longer paste. When it liquefies something happens that looks like magic.

Put the solder paste onto the pads on the board

You need very little, just a small blob on each pad. The pads for the Micro SD are very close together and you'll probably not be able to separate the blobs of solder on them. Don't worry about that. Some magic will happen there later.

I used a sewing pin to put the blobs of solder in place and it was pretty tedious. You can get tubes of paste which might be easier 'cos then you can squirt a blob on each pad. Some people make more elaborate foot controlled devices, but they probably do all this more often than I do. Others make a template of clear plastic with a hole for each pad and you just spread the paste over the plastic with the board held in place under it. You need to be making several boards at once to justify that.

Place each part

Because these are truly tiny take steps to ensure you can find them when you drop them. And you will drop some of them. A cloth across your knees etc is good, consider sweeping the floor first and do not do this over carpet. You will need tweezers (unless you have that pick and place machine in the cellar). I've seen a neat arrangement with vacuum powered 'tweezers' with a foot control that I see the point of now. But ordinary tweezers do the job eventually.

The trickiest one is the LED which has to be the right way around. The docs on whatever LED you buy will say how you tell. Do the largest parts first, and the Micro SD is easily the largest. There is space for the battery connector but that is not an SMD part. It is a 'thru-hole' part. Leave it for later. Also ignore the holes around the edges for now for the same reason.

The skillet

Now get your skillet. What you want is a free standing thing that you don't expect to use for cooking food again. It doesn't matter about non-stick coatings. You aren't frying eggs. If you have an old electric fry pan that's ideal. Give it a run first, heat it up and make sure you know where the hot spots are. I have a temperature sensor on my multimeter which helped. Make sure it gets up to 200C. Now turn it off and let it cool. You should be well ventilated for this, I took mine outside.

Put the board on the (now cool) hotspot, part side up, and turn on the skillet. Just let it heat up to the max temperature and watch carefully. The idea is for it to heat fairly slowly, so don't dump it onto a pre-heated surface. When it reaches the magic point the paste will go shiny and liquid. Okay, that's nice. And then you realise is it awesome. Remember those pads in the Micro SD that were so close together you couldn't separate them? Well the solder paste does something like capillary action. It balls together on the pads, separating them from each other. There are videos of this on Youtube. Even after seeing them I didn't quite believe it would be that easy. Of course it does depend on you having positioned the Micro SD just right, not too hard because there are white lines on the board to help.

Give it a couple of seconds or so after liquefaction to make sure all of the paste did it, then slide it off the skillet and let it cool. Naturally you want to avoid bumping any of the SMDs while things are still hot. It is very small so cooling doesn't take very long.

Thru-hole

At this point you are ready to do the thru-hole parts. There are holes to add pins around the edges and these match up to holes on the Teensy3. You want to add pins to all of those holes except the three on the end next to the button. You also want to add the battery connector which is next to the Micro SD. However you might consider just attaching wires to the two battery connector holes if, like me, you're trying to keep this small. The battery connector is quite big and, as I said, I am all about keeping this small. At this point you are using ordinary solder and an ordinary soldering iron and you've put the paste away.

Testing the board

Now you need to test the board to make sure nothing went wrong. You might have bad solder connections etc and you want to find them. Because you left off those three pins on the end you can put this onto a breadboard with a Teensy3 next to it and check all the functions out. But you will need two of those three pins on the end connected: The 3.3v and GND. These are pins 1 and 2 if you count from the side where the battery connector is (from the bottom up if you are looking at the photo below). In my case I found I had swapped the two resistors that control the voltage measure function, so that feature was broken. This is worth knowing. If you want to be even more careful you can test the third pin with a multimeter. It ought to connect to GND when you press the button.

This is what my test breadboard looks like. I have a Teensy3 with all the pins soldered (on the left) and I just use that Teensy3 for testing (these things are cheap enough to run a spare or two). Note that you need to separate the pads underneath the Teensy3 to detach the USB power (VUSB) from the rest of the Teensy3 (VIN). We want power to come from the battery not the USB.  The pads are shown in the top right on the diagram shown below. Cut them apart with a sharp knife. You can solder them together again if you change your mind about all this.
I also had to add a wire the the VUSB hole on the Teensy3, this is one of the holes not on the edge so isn't quite breadboard-friendly, but you can't have all the holes on the edge without making the board bigger so the answer is to just run a wire from there and plug it into a convenient hole in the breadboard. There looks to be a tangle of wires there but there is an easy pattern. Every pin on the piggy back should connect to the equivalent pin on the Teensy3, that's all there is to it.

You can see the battery connector trailing over to the right, the battery isn't plugged into it just now, and there is a second battery in the lower part of the picture. We're not using that today but it is the power supply for the clock function on the Teensy3.

You'll want to connect a battery. I used a Lipo 1000mAh 3.7v and, of course, you'll want a USB cable attached.

To test the board you need to load some software. I'll assume you have your Arduino environment set up properly for the Teensy3 and you know how to load programs into it. You'll find a test program in the google code link I gave earlier. This does the following once it starts:

  1. Wait 5 seconds to give you time to open a serial monitor
  2. Scans the micro SD card for files and prints a directory to the serial monitor. This verifies the SD card is working okay.
  3. Loops, printing the value of A0 and it's scaled value, which should be about 4 volts. The LED on the Teensy3 will flash slowly. This verifies that the voltage measure is working okay.
The LED on the piggyback should be on steady. Make sure the switch position is on the Right (or Down if you look at the picture above). This is the normal ON position for the board. Now unplug the USB cable and the LED should continue flashing, running on battery.

With the USB cable still unplugged move the switch to the Left position. The flashing should stop. This is the OFF position. The battery is not being used now. Move it back to the Right and the flashing should restart.

Be aware that if the USB cable is in and you move the switch position it will cause a restart because power is cut briefly to the Teensy as the switch moves. Possibly I could use this instead of the reboot button.

The final assembly

Once you are happy with the board you can finish it off. Add the three pins you missed before and, yes, it will be a bit fiddly because you already soldered wires to two of them and you can remove those. Then slide the Teensy3 onto the pins underneath the board and solder it all together. You'll want to solder other things to the other Teensy3 connectors, of course, but the Micro SD etc are all taken care of. In the picture mine still has the end wires, but you can see the whole thing is very small. I plan to snip the bottom ends of the pins off.

Friday, 30 August 2013

RIP Elaine Morgan

I've only just heard Elaine Morgan died a couple of months ago. She made it to 92, which is a good run
and not something to be desperately sad about. But we have a particular  fondness for her in our house.

Morgan wrote a book in 1972 called 'The Descent of Woman' which explored the idea that our pre-human ancestors went through an aquatic phase, and that this has left us with features that make us different from our near cousins such as walking upright, hairlessness etc.

She was particularly keen to explore how features of the female of the species turned up. All of the standard narratives concentrated on 'man the mighty hunter' who climbed down from the trees, grabbed a stick to use as a spear, and ran off across the savannah pursuing antelopes.

The Aquatic Ape Hypothesis is a controversial theory, and when I say controversial I mean it is largely dismissed by professional anthropologists. Whenever I hear it being dismissed I find myself unconvinced by the dismisser, but I'm no anthropologist. They may be right. Morgan herself was a writer rather than a scientist, but she was a very good writer, and her book caused quite a storm at the time. She pursued the theory with more books over the years.

Our particular fondness comes from our courting days. Mrs and I were a couple of geeky kids (perhaps the only two geeky kids in our small town) who found each other not very long after Morgan's book came out. Mrs had a biology teacher (yes, still at school) who was happy to loan her books so we spent our dates reading things like Morgan and Goodall and talking about them. Happy days!

But a bit more than that. Until around then I had been pretty much only interested in physics. Not that I was very good at it, but it is what I liked. Mrs had interests in biology and actually a ton of other stuff I had never given a thought to. So Morgan's book, for me, represents a general leap in awareness of things that don't involve rockets or electrons but do involve evolution and Jane Austen.

I like to think the Aquatic Ape Hypothesis has merit, but even if it doesn't I feel I owe much to Elaine Morgan. Mrs and I still share our geeky books over 40 years later.

Sunday, 25 August 2013

How many moderate Christians are there?

I did some digging on this when responding to a G+ post here and I find myself referring back to it and having to search (again). So I've turned it into this blog post. The G+ post was talking about the number of people who say they believe everything in the Bible and yet don't actually read it, which would be an odd way to go about things.

But here I'm just wondering how many Christians actually do believe the Bible is the unerring word of God? Whether they read it or not.
One of the links on the G+ post pointed to something that said this:
"The survey showed the Bible is still firmly rooted in American soil: 88 percent of respondents said they own a Bible, 80 percent think the Bible is sacred, 61 percent wish they read the Bible more, and the average household has 4.4 Bibles." 

Now, that isn't the same as asking if they think the Bible is the unerring word of God. I'd answer 'yes' to a question about the Bible being sacred. But 'no' to an 'unerring word of God' question. And I have 4.4 Bibles :)

It took some digging to find an appropriate survey but I found one here. The stats quoted are from US surveys.
Since it is on the Internet I assume it is perfectly accurate :) and it tells me:
"58% believe that the Bible is "totally accurate in all its teachings"

There it is, a bit more than half, but not much more. Some of the ra-ra noises the media makes you'd think it would be more. Well, there are the numbers. it isn't.

But there is more information in that second link. It also refers to a poll in 1987 of American clergy. They were asked whether they believed that the Scriptures are the inspired and inerrant Word of God in faith, history, and secular matters:
95% of Episcopalians,
87% of Methodists,
82% of Presbyterians,
77% of American Lutherans, and
67% of American Baptists said 
Wait for it....

"No."

Remember these are the people who preach to the Christians who actually turn up on a Sunday. You might expect their congregations to at least roughly accept the views of the clergy who preach to them. 

There's a discrepancy in the numbers, from 58% of everyone to 67% of Baptists, the lowest number. It would be explained by more people belonging to the Baptist churches, and the more fundamentalist ones being bigger, but also note there aren't figures for Catholics here. So we're in pretty woolly territory and everything is approximate. Also I am a little suspicious of the 58% figure because people who don't really think that much about Christianity may have answered yes because they thought it was the right answer.

I am using the term 'moderate Christian' here to contrast with 'fundamentalist Christian'. I don't quite like the term 'moderate'. It is not as if our love for Jesus is necessarily moderate, just that we don't think the Bible trumps everything when there is any question of any kind to answer. We use the Bible as a guidebook for getting to know God rather than a body of legislation. We know it was written by men (no, there aren't any women writers in there, sadly) who were embedded in a culture different from ours and we know that we are allowed to make progress in our thinking about God. So when St Paul comes across as misogynistic and seems comfortable with slavery we can just shrug and say he didn't know any better. And that's okay. When we read some Psalm that rejoices in the hope that God will smite the writer's enemies it's much the same. And when we read about the world being created in seven days that's really not a problem. It was never a science textbook and those early writers were not scientists.

The odd thing is that the people who say they believe absolutely every word of it also pick the bits they like and ignore the bits they don't care for. They don't like gays because it says in Leviticus that they have to be put to death. But they don't want them actually put to death (that's good, actually). Same with adulterers. That could get awkward, couldn't it? There are some seriously heavy words about divorce in the New Testament where Jesus points out that the Old Testament divorce laws (that allowed divorce) were a kind of cop out, and not strict enough. I am reminded of the line in 'Pirates of the Caribbean'. They're not rules, they're guidelines.

There might be some rare exceptions but by this definition all Christians are moderate. It's just that some of us admit it and some don't.

Saturday, 15 June 2013

Michelangelo's Creation of Man

Everyone recognises this picture. It has been reproduced over and over and even if you don't recall the details of where it originally comes from you know it is God and Adam and something to do with the creation, unless it is the version where Adam is replaced by a robot in which case it is... something else.
Let me remind you of some of the details because they are interesting. The picture is a detail from the Sistine Chapel in Rome and it was painted by Michelangelo around 1500AD. I've been lucky enough to see it twice, once before the major restoration work when it looked a bit gloomy and once afterwards when it looked like the version shown here. The Sistine Chapel was painted in two phases and this detail was from the second half.
Michelangelo was an astonishing artist. The first thing we know he did, a relief carving of the Virgin and Child in Florence, is just brilliant. Artists often trained themselves with a daily exercise involving drawing their left hand. Visari recounts that Michelangelo normally drew both, which probably means he was ambidextrous. That would have helped his painting and carving, but his genius was in conceiving the things in the first place. He was, however, primarily a sculptor and even once remarked 'I am no painter'.
In those days getting anything done at all was a huge challenge. You need to get 80 feet up to the ceiling to paint? Well you've got to design and build your scaffolding. And you'll need paint, you'll need to make it yourself. They often got apprentices to do this but Michelangelo had trouble keeping apprentices and ended up doing much of this himself. The technique for painting on ceilings like this involved putting plaster onto the stone, laying a drawing over the plastered section and punching holes into the outline, then painting directly into the plaster before it dried, ie quickly. All the while you have to have enough paint mixed and ready and you are working either lying on your back or bending your neck back.
Like I said he did it in two phases, reusing the scaffolding, so it wasn't until he had finished the first phase and taken down the scaffolding that he could stand on the floor and see what it really looked like from a distance.
It looked like this. The middle panel is Adam and Eve accepting the forbidden fruit and, in the second part, being kicked out of the Garden of Eden. it seems Michelangelo refined his ideas for the next phase of the work and the panels got bigger and more dynamic. It is all good stuff but the second half gets the most attention and is arguably better.
There's one more technical detail worth mentioning about the work. The shape of the ceiling mean he had to use perspective adjustments to make the figures look right, things like making the heads of those guys sitting around the edges bigger than they ought to be. The geometry involved makes my head hurt.
So it is brilliant both conceptually and technically and it was all done in spite of huge challenges and I haven't even mentioned the nagging pope who was paying for it.
But take a look at that first image again. There's Adam sitting on some kind of rock looking like a body builder, most of Michelangelo's figures look like they work out a lot, including the girls. And there's God, the one with the white beard floating on something that looks like a raft of angels and a cape. The image has been reproduced so many times now that some of us think this is what God is really like, an elderly but vigorous guy who floats in the sky somehow. Actually that's not quite what I mean. I think this is what people who don't believe in God think that people who do believe in God think we think He is like. You might want to read that sentence again.
But most believers I know see this for what it is, a brilliant artist's attempt to capture a moment in paint. When such moments involve God he has to resort to symbols, and fair enough. Any description of God resorts to symbols whether in paint or not. And most of us know that.

Sunday, 7 April 2013

On The Atheist's Litany

This one isn't addressed to me because his atheism doesn't offend me. I'm Christian, the kind that goes to church and knows the minister. I'm okay talking with atheists unless they are actually trying hard to be offensive.

I'm guessing he has run into religious people who were making an effort to rub him up the wrong way and I can understand this reaction to that.

My problem here is that the words contain a false premise and I'd like to open that up and take a look at it.

There is a litany of bad stuff that religious people have done through history: jihads, crusades etc. And it's all true. Bad stuff sure happened. It was even done by people calling themselves religious. And this is on-going, we've all come across people using religion to justify, say, hatred of gays. No denial here. The writer clearly credits religion for causing all this evil. I've seen quite a few comments from atheists that suggest this view is common. And there's the false premise I want to look at.

Let's take the Crusades as an example. What happened was that a lot of Christians went over to West Asia (and some other places like Africa and, strangely, Southern France) with the idea of taking control of those lands away from the non-Christians who held them. This was initially about taking Jerusalem away from the Muslims. People were told that they would have all their sins forgiven if they did this, which helped swell the ranks. So, sure, religion was involved. But so was something else.

The feudal system in Europe was geared towards looking after the oldest son, younger sons got a raw deal. They wanted land. So their goal when going on crusade was to carve out an estate for themselves, ideally a big one they could call a kingdom. This explains the conquest of Syria which is not particularly close to Jerusalem, and similar activity in Egypt. It was at least as much about land and power as religion. If it were only about religion then why did they sack Byzantium (which was Christian) during the 4th Crusade in 1204? It brought a ton of treasure to Venice who seems to have instigated it and the 4th Crusade never did make it to Jerusalem.

We might question if some of these people were actually Christian or just self interested bad guys. I won't go there because we cannot see into their hearts. If they say they're Christian I'll accept that. But I don't have to agree with every other Christian and I can call it evil when I see it.


So that one was about wealth and or power. One way or another it always is, unless it is about fear and ignorance. Sometimes people manage all four. But what happens with these things is that people decide what they want to do and they co-opt whatever they can to convince other people. During most of our history religion has been one of the things they co-opt. It is a tool they use, but it isn't the cause. The younger sons wanted land, they found a way to convince others to follow them and they went for it. Yes I know the pope at the time endorsed the crusades, this is still just religion being co-opted, it is not religion as such being the cause of a land grab by Europeans in West Asia.

We can make similar arguments about homophobia. Our early ancestors had to out breed those guys in the next valley so they could defend ourselves from them, or take them over or whatever. So anyone compromising that agenda is a threat to the tribe. Again they'll co-opt religion to enforce their view. Interestingly in ancient Greece they had a problem with too much population and homosexuality was socially acceptable, even the default in some circles. And to add a twist to the notion religion is always against homosexual behaviour, it seems it various times in the past it has actually endorsed it. Blessing gay unions has been going on in my church for a while now. There are other things going on with this too. A lot of guys are homophobic because they fear rape, stuff like that. It's unnecessary and wrong, but they'll use religion to justify their position if they can.

I'm not going to go over every other piece of evil in the litany, it is a representative sample anyway.

If religion was the main cause for all this nastiness then we would expect to see societies that were not religious behave differently. Before about 1850 we could not get any experimental data on this because there were so few people then who called themselves atheists. But nowadays we actually can. We have various Marxist  regimes which are avowedly atheistic. Do they behave better or are they just the same as the religious ones?

Not really. Stalin's purges in Soviet Russia had a higher body count than Hitler's. Various spin off Maoist movements such as Shining_Path, Naxalite_insurgency and the truly dreadful Khmer Rouge claim to be atheist just as the crusaders claimed to be Christians.  I will take their word for it.

Oh, but these are not 'my' kind of atheist, you might say. Actually I hope, if you're an atheist that is exactly what you'd say. I would not suggest that this kind of behaviour is an inevitable result of atheism because it obviously isn't. And the religious people referred to in the litany above are not my kind of Christian. Religion or the absence of it, is not the cause of these evils, but the people who get involved will use whatever is to hand to do what they want.

But there is one more point I have to make. Just as all those bad guys in history claimed to be religious and did awful things, there were a lot of good people who also claimed to be religious. Remember everyone for most of our history has claimed to be religious and that is all we have to go on. If you really were still arguing that religion is the cause of all the bad stuff you have to also argue that it is the cause of all the good stuff. That means every advancement in art, science, politics and so on before around 1850 has to be credited to religion. This includes heroes like Copernicus, Galileo and Newton (who was very religious in an unconventional way, and quite an unlikeable character too). You might say those advances would have happened anyway, which is pretty much my view, but then you have to be even handed and say the evil would have happened anyway too. Certainly there is good reason to believe that the abolition of slavery in the West (there are still slaves in other places today, unfortunately) was instigated by Christians who, by their own accounts, felt moved to act because of their faith.

So can we please take a more balanced view of religion? Even if you don't agree with it there is no cause to call everything about it evil and no cause to suggest it is responsible for every evil.

Tuesday, 12 February 2013

Mobile Madura

A while back I wrote something about delivering web apps as mobile apps and I have at last got around to building something to show it working. Most of what I have done is just picking up other people's work and implementing it, and documenting how I got on in this blog. I also wanted to show that it all works with my Madura software.

The good news is that it does, and very nicely. A key goal of Madura is to make it easy to implement serious back end logic independent of the User Interface, and yet have that UI cooperate with the back end logic intimately. In its first test of this, switching from a conventional browser environment to one designed for a mobile phone I really did only have to change the UI, not the underlying logic. In fact my sample application has both UIs embedded in it, and it picks the right one depending on your browser. Both of them talk to the same business rules and business objects. So no redevelopment of the underlying layers, just the UI.

And when I say the UI, well, there isn't much to it. The Vaadin support code I already wrote happily ties in validation, dynamic field adjustments etc which propagate from the business logic. So the UI is fairly bare. Code to enable buttons to enable or disable at the right time, for example, doesn't need to be written, it just happens.

Let's see what it looks like. The Mobile UI shows a configurable pizza where you pick the base, size and topping. There are a couple of test fields at the bottom and an amount.

You can only pick some combinations of size and topping and once you pick a topping the list of options for the size will change, or vice versa if you pick size first. It only ever shows you valid choices.

The size determines the amount so once you pick a size the amount will change. This is done by rules not by some embedded logic in the UI.

The two buttons at the bottom are interesting too, although the Save doesn't do anything. If there is a required field that has no value the Save will be disabled. You only see a required field if Size is set to Medium, then a new field appears and it is required, and  empty, and Save is disabled.

Again, none of this is done in the UI logic. It is all handled in the back end rules. The other UI does similar things and it is driven by the same rules, not a slightly adjusted copy of them, the exact same rules.

All of the UI here is using Vaadin, which is just brilliant. It also uses an add-on to the standard Vaadin called the TouchKit, also developed by Vaadin. That handles the Mobile specifics like touch screen etc.

So this is a web app that looks like a phone app. But shouldn't it be a proper phone app that you can put into the app store where people can find it? Maybe you can charge for it and deliver ads through it. I'm not sure about the ads, but you can package this as a phone app and it is very easy. The steps are well documented using a product called PhoneGap which takes some combination of html and javascript and turns it into an app. Not only does it deliver Android apps, it delivers them for iOS and Windows phone and all the other mobile platforms you didn't know you could write apps for. The process is trivial to do and seems to work just fine for Vaadin apps.

My code for all of this is here with an online demo here. The demo will show you the non-mobile UI if you use a non-webkit browser like FireFox. If you use Chrome it will show you the mobile UI. Of course if you browse there from a phone you'll see the mobile as well. I've only tried it on Android so far.

The project also makes an apk file which can be side loaded as an application to an Android device. The main difference between running from the app is that you don't see the URL box from the browser, it just looks like an ordinary native app.

I didn't need to take things this far but Vaadin's demos include getting the location (GPS) information and there seems to be mechanisms to get at the camera and other phone hardware too. For now, all I wanted to prove was that Madura could run in this environment.



Wednesday, 6 February 2013

The Meaning of Wex

We need a new English word to refer to the exclusive 'we', or we-but-not-you. Have you ever been talking to someone and said something like 'We are going to the beach' but the 'we' did not include the person you were talking to, it just meant you and some other people. The person you are talking to can easily misunderstand. If you'd said something like 'we are going to bed' the misunderstanding might get very awkward.

So I propose a new word: 'wex' to mean we-but-not-you, or the exclusive 'we'.
It has lots of advantages:
  1. It is short and easy to spell
  2. It has an X in it. Anyone from marketing will tell you that is a good idea.
  3. I thought of it.
Anyone can use it. You don't have to send me any royalties.

Tolkien
Interestingly when J R R Tolkien defined his own language, Quenya, he put an equivalent of wex in it. He used a different word, of course. But it is nice to know he agreed with me. Since then I've found Maori, in common with other Polynesian languages, has a similar word. So at least one real language has seen a need for a wex-like word.

This isn't the only idea I have for tidying up the rougher edges of English. We have issues with the plural of 'you', for which there are ugly solutions like y'all and yous (okay, maybe you don't think those are ugly, but this is my blog and I do). And wouldn't it make life easier for people learning English if we stopped modifying word endings all over the place when we don't need to.

But no one is going to make any progress on those ideas. Wex, however, is a simple and easy addition to the language we can just start using today. Let me know how it goes for you.