# This way up!

This way up!

By Frances Buontempo

Directions in computing can be very confusing. Frances Buontempo wonders if we know our right from left.

Following instructions can be very difficult. For example, writing an editorial every two months with no idea what to write about, simply having to fill two pages, is a regular challenge. Could I get someone to draw me a cartoon strip? (Budding artists get in touch, please). Can I use a gigantic font? (Apparently not.) Lacking any direction should be liberating, but can be confounding. Even if you are given directions, things can go awry. Have you ever told someone to go left at the next turn, only to see them indicate right? Far too often a cry of, “No, left!” meets with “Yes, I’m going left!!” The simplest solution is to try, “No, the other left” instead. That has worked on several occasions for me.

Spatial awareness is vital in many situations. Even sitting at your desk all day, you need to be able to reach out and grasp your mug of coffee – assuming you are caffeine-powered like many programmers – or move your fingers around a keyboard. Practising can help you improve; you learn where the home keys are and how much to move to hit the keys you need, rather like practising scales when you learn an instrument. Some keys are better hit with the right hand; others with the left hand. I constantly have to remind myself there are two shift and control keys. Note to self; for combinations like Ctrl-A, it makes much more sense to use the right hand Crtl key with the A.

At other times, spatial words are used arbitrarily: a binary operator can take an lhs and a rhs – left hand side and right hand side – stemming from how the code is written. The operator could be seen as taking a first and second operand, avoiding the tempting and common abbreviations lhs and rhs. Whether infix notation 3 + 4 or something like 3.operator+(4), you have a left and right operand. If you start chaining operators – 2*3+4 – you still have a left and right, though to parse the expression you will build an expression tree. If you evaluate this in Q you will get 14 [Q operators] . You may have been expecting 10, (2*3)+4, but Q evaluates from right to left. Unconventional; you need braces to ensure it follows your instincts. What about x < y < z? In some languages this would compare the result of x < y, a Boolean, with z, which may not have been the intention; you need to spell out (x < y) and (y < z). However, in Python, the operators can be chained [Python operator] . For almost all data types, you would expect transitivity to follow: that x < z. This might not happen, either due to bugs or by design, depending on the definition of less than. Unconventional approaches can lead to surprises. Of course, conventions and instincts are built on top of what has happened before. Challenging norms leads to new and interesting ideas. New branches of mathematics often sprout this way. As Kevlin Henney recently pointed out, “ Tradition [noun]; A practice or belief that is repeated and passed on without rationale, except that ‘We’ve always done it this way.’ [Henney]

Sticking to conventions and repeating the way you do things is not always a bad idea. Typing with your left hand on the left of a keyboard and your right on the right is a good thing. Doing touch typing drills can be a good thing, if like me you frequently end up with a mess of typos when you write. Building up a muscle memory makes so many things become instinctive. Rather than sitting at your desk all day, it is good to get some physical exercise. Going for a short walk round the block counts, though some people choose more formal sets of exercises, possibly in a gym. Calisthenics are a way of using your own body’s weight to exercise, without needing kit, so you can do this in a gym or outdoors. Think sit ups or similar. If you search, you will find lists of exercises to try that work out your whole body, claiming to improve balance, muscle tone and the rest. If you’d rather sit at your desk and code, try out Object Calisthenics by Jeff Bay. These are included in the Thoughtworks anthology [Thoughtworks] and can be found online [Object Calisthenics] . He points out that many object-oriented examples “ encourage poor OO design in the name of performance or simple weight of history ”. Tradition, as ever. They consist of nine rules of thumb to nudge your OO code towards seven code qualities; cohesion, loose coupling, no redundancy, encapsulation, testability, readability, and focus. Rule six is “ Don’t abbreviate ”, or “ Do not abbreviate ”. So, lhs and rhs mentioned above are bad parameter names, and “Ctrl” was just careless. I apologise. In terms of code, I’m sure you can think of many examples of abbreviations such as ``` getNoChildren ``` rather than ``` getNumberOfChildren ``` or even ``` numberOfChildren ``` . Of course, rule nine says no getters, so the problem is nipped in the bud.

Left and right seem like obvious ideas, but I recall lots of problems trying to remember which was which when I was a small child. Parents often resort to writing on shoes, gloves, etc. to help reinforce the words. Can you recall how you learnt which side was which? Do you remember when you discovered whether you were left or right handed? Can you write with both hands? Since more people are right handed, many things are set up for right handed people. To scan a travel pass you usually hold it to your right, unless you get on a bus in the UK. You may have spotted people scanning the card on the left and then walking into a closed barrier. Right-handed scissors don’t work if you use them in your left hand. Other setups are purely driven by convention, including driving; the gear stick in a car is by your left if you have a right hand drive car, and by your right if you have a left hand drive car. The hand you use depends on which side of the road you are supposed to be driving on. One will seem more natural depending on your experience.

The idea of handedness, or chirality, applies to molecules as well as people. Thalidomide, a drug produced to combat morning sickness, caused malformation of limbs in the babies. I am not a chemist, but I understand small batches were tested which appeared to be fine, but when enterprise sized production batches were produced, slightly different ‘enantiomers’ or optical isomer of the chemical were manufactured. One is a mirror image of the other; they contain the same elements arranged similarly. The only difference is the chirality. The molecules can then slot into different places and cause different outcomes in vivo. A warning against enterprise-grade endeavours? Maybe, maybe not. Turning to physics, when Feynman discusses anti-matter in Six Not So Easy Pieces [Feynman] he identifies the chiral opposite of normal matter as antimatter. Starting with beta-decay, he considers reflective symmetry in nature and recounts an experiment which shows decaying cobalt atoms emitting electrons which tend to go up, under some specific conditions. You could describe this experimental setup to a Martian, and then have a way to describe right and left (or up and down) without pointing. A genuine problem, assuming you can speak Martian, and find a Martian to talk to. How do you describe left or right? In words, without pointing. Cobalt; check. Martian; check. So far, so good. However, the ‘broken symmetry’ – that sometimes electrons tend to spin left, or go up, with no good reason – is curious. He encourages you to imagine antimatter, which annihilates matter on contact. If the Martian is made of antimatter and you talk him through the cobalt experiment to communicate left and right, and arrange to meet, what will happen? His anti-matter cobalt will send electrons down, so his left and right will be the other way round to yours. Feynman says,

What would happen when, after much conversation back and forth, we each have taught the other to make space ships and we meet halfway in empty space? We have instructed each other on our traditions, and so forth, and the two of us come rushing out to shake hands. Well, if he puts out his left hand, watch out! [Feynman online]

Perhaps you can’t describe left and right in exact terms. Gisin gives a short, though maths-heavy discussion of the same topic [Gisin] , called ‘Quantum gloves’, starting “ Assume that two distance partners like to compare the chiralities of their Cartesian reference frames. ” It talks through frames of reference and information encoding, and leaves me none-the-wiser as to which way is up; highly recommended if you like your maths, though. Pointing is sometimes the only way. Of course, that is something of a human convention. Some animals can understand it, but a cat will often just look at your finger rather than what you are pointing to.

Arbitrary assignments, such as left or right-handed applied to molecules, apply in computing too. Algorithms, as well as design, processing, investing or parsing can be described as top down or bottom up. The internet tells me that top down parsing starts at the “ highest level of a parse tree [Wikipedia] . Without following the link, I am certain the highest part of this tree will be a root. Trees in computing are almost always upside down. Top-down starts with the big picture moving on to details, while bottom up figures out the details, and pieces the parts together to make the big picture or final answer. Bottom-up can also mean capsizing a yacht, though figuring out which way up a boat should go should be straightforward enough, even for a Martian. Markup and markdown is a different matter. I presume we draw the root at the top of a page to add the details as we go down since we tend to start writing at the top of a page. This leads to another source of confusion, at least for me. Many drawing packages are based on printing to a screen, and tends to have 0 as the top of the screen. In contrast, 0 is at the bottom when you plot data on axes; for many plotting packages, going up gives bigger numbers. Watch out for different idioms, conventions and scales as you switch contexts.

If you are told to turn something round, what do you do? Does ‘flip’ suggest something different to ‘rotate’? Can I describe what I mean clearly using only words? Many software applications come with some form of documentation, frequently of varying quality, and part of that often includes some form of diagrams. I personally tend to find drawing an architecture diagram of a complicated system by hand more useful than attempting to decipher a diagram with hundreds of parts. Where do you look first? A simple diagram, with a couple of blobs indicating different parts of the system and one or two arrows showing connections, either as data flow or processing can be helpful. More than that is often confusing. Making clear diagrams is as much of skill as writing well. You probably don’t need a detailed map of your software landscape, at least initially, though a spot clearly marked ‘Here be dragons’ is useful. There is no shame in a simple sketch on a white board, if you have a whiteboard. Failing that a hand-drawn sketch on paper will do.

Some of the confusion we have considered is inherent in language, while some is through ambiguities, careless abbreviations, or assumptions about experience. Some of the issues arise from pedantry or precision. One language will parse a statement left to right, while another might go right to left, or special case operators. Humans do the same too. Children can have difficulty with ambiguous statements: “ the man fished from the bank [Rowland] … Some children get the hang of this type of statement more quickly than others. Sometimes autism is blamed, though this book suggests autistic children’s difficulties in communication are not purely down to autism. The author cites various studies including ‘Barking up the wrong tree?’ [Norbury] of language impairment in autistic children, considering the use of metaphor and simile comprehension in a group of children with various degrees of language impairment and autistic symptoms. The study concludes that children with autism who struggled with the metaphors also had language impairment, and were indistinguishable from those without autism. It concludes that “ a number of top-down (contextual processing, world knowledge, and experience) and bottom-up (semantic analysis) processes that work synergistically to arrive at metaphor understanding. ” Computer programmers are often claimed to be on the autistic spectrum or have Asperger’s syndrome [Atwood] . I suspect much of the claimed evidence is inaccurate; being absorbed in something you find interesting is not the same as having autism, yet some ways of measuring autism do hint at slight differences between different groups, for example the autism-spectrum quotient [Baron-Cohen et al] . If you can’t tell your left from right, never remember which is bottom up or top down, find ambiguous instructions confusing, you are not alone. If it all gets too much, step away from the keyboard and get some exercise. Or practise scales. Loudly. Or overload some operators in unconventional ways and write it up for Overload . And don’t forget, as Tony Hoare once said,

You cannot teach beginners top-down programming, because they don’t know which end is up.

## References

[Baron-Cohen et al] The Autism-Spectrum Quotient (AQ): Evidence from Asperger Syndrome/High-Functioning Autism, Males and Females, Scientists and Mathematicians, Journal of Autism and Developmental Disorders , February 2001, Volume 31, Issue 1, pp 5-17 https://link.springer.com/article/10.1023/A:1005653411471

[Feynman] Six Not-so-easy Pieces: Einstein's Relativity, Symmetry and Space-time , first published in 1964 by Addison-Wesley but reissued in 1990s.

[Feynman online] http://www.feynmanlectures.caltech.edu/I_52.html

[Norbury] ‘Barking up the wrong tree? Lexical ambiguity resolution in children with language impairments and autistic spectrum disorders.’ J Exp Child Psychol . 2005 Feb;90(2):142-71. See https://www.ncbi.nlm.nih.gov/pubmed/15683860 or find online at http://www.pc.rhul.ac.uk/sites/lilac/new_site/wp-content/uploads/2010/04/metaphor.pdf

[Object Calisthenics] https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf

[Python operator] https://docs.python.org/2/reference/expressions.html#comparisons

[Q operators] http://code.kx.com/q4m3/4_Operators/

[Rowland] Understanding Child Language Acquisition by Caroline Rowland via https://books.google.co.uk/books?id=cVizAQAAQBAJ

[Thoughtworks] https://pragprog.com/book/twa/thoughtworks-anthology