Repairing a Minolta XG-9 camera

This is the story of how I repaired, broke, and repaired again a Minolta XG-9 35mm SLR film camera.

It will be long, and of niche appeal, but I’m writing it up in case anyone else finds it as useful as I would have done before I started. Here’s the plot summary:

  • The camera’s shutter was sometimes sticking open when fired in Auto mode
  • I set out to fix this by cleaning the electrical contacts of the film-speed selection switch, beneath the camera’s top plate
  • That appears to have been the correct fix, but when reassembling the camera, I broke a fragile plastic part which holds the power switch in place, rendering the camera useless
  • I modelled a replacement part using 3D modelling software, had it 3D printed, and replaced the part in the camera
  • The replacement part is good enough to use, but could probably have been better; I’ve published the model for it, and would appreciate any ideas

If that sounds in any way interesting, read on. This was my first attempt at repairing a camera and my first experience of 3D modelling and printing, so it was certainly interesting to me.

The original problem: a sticking shutter

OLYMPUS DIGITAL CAMERA

The camera is one that I wrote a happy post about last year (“A film camera“). It was made in 1980 or so, but I bought it in 2018.

It worked well, except that the shutter would sometimes stick open when fired in Auto mode, and the only way to close it was to switch out of Auto. When stuck open, it often let in enough light to ruin both the previous and following photos as well as the current one. I was keen to fix it, especially as these cameras are designed so that the light meter only works when in Auto mode.

The first hint I found online was here, in a photo.net post from 2003 by “rokkor fan” who writes: “I had this once on a XG-1, and it was as a result of the mirror slap jarring the circuitry under the shutter release. I had a friend clean the circuits and it worked a treat after that.” No more details there, but a poor electrical contact sounds promising.

There’s a 238-page service manual available for these cameras (thank you Benoît Suaudeau) and it has an electrical troubleshooting section starting at page 174 that says:

Annotation 2019-07-04 204232“AUTO… curtain is kept open” looks like our problem, and “ASA contact defective” seems worth checking. ASA refers to the film-speed selection switch, which is on the top of the camera. It makes sense that a lost contact from that switch would only affect Auto mode, since Auto needs to know the film speed to decide how long to leave the shutter open.

There’s a YouTube video here, by Florian Buschmann, which shows how to take the lid off. The top cover has three axes poking out of it, one for the rewind knob and power switch, one for the shutter button and film speed knob, and one for the winding lever. The components attached to the tops of these can all be unscrewed from their axes and removed, leaving a plastic top-plate attached via four small screws, two at front and two at the back towards the middle of the camera. Here’s the camera with the top off:

Minolta XG-9 with top plate removed

The film-speed switch is beneath the large black nubbin poking out of the top about 3/4 of the way across from the left. The smaller nubbin at the left side is the power switch mechanism and rewind axis, which is the part I was just about to break while reassembling the camera.OLYMPUS DIGITAL CAMERA

Unscrewing the parts atop the film-speed switch reveals a brush mechanism with a flat contact plate. I cleaned the plate with switch cleaner (it was quite grubby) and made sure the brushes were sticking out enough on the switch side, then reassembled the top of the camera.

After reassembly I tested the shutter in Auto mode a few times, and it didn’t stick. Flushed with success, I set out to load a film — and that’s when the power switch came loose. While screwing on the metal collar that keeps the power switch in place, I had managed to shear off the entire threaded top of the plastic part that holds it down. A problem.

The broken part

Minolta part 2006-3309-2, Rewinding axis receiverThe picture on the right shows the part I had broken. It’s intact in this photo, because this was taken during one of my initial attempts to glue it back together again — which always failed when force was applied to screw the threaded collar back on the top.

The 40-year-old plastic is quite brittle, and as you can see, I also broke one of its little lugs just unscrewing it from the body. And I am a reasonably delicate person.

Without this part, it’s impossible to use the power switch: it is left floating, switching between on, off, and self-timer modes at random. Having failed to glue it, my options seemed to be:

  1. Write off the camera. I wasn’t going to do that yet.
  2. Figure out some ingenious bodge to keep using the power switch even though the official mechanism didn’t work. Well, I did sort of do this using a piece of thread attached to the switch mechanism, but I didn’t like that very much.
  3. Find a replacement part. For an easily-broken part in a relatively inexpensive 40-year-old camera from a company that stopped making cameras over a decade ago, that seemed unlikely, and my first searches came up with nothing.
  4. Buy a non-working camera, sold for parts, and plunder it for this part. Yes, but what if it just broke in the same way again? That would be unbearable. Or if this part was already broken in the other camera?
  5. Make a new part. This takes time and money and might not work, but it puts the outcome in my own hands and hopefully teaches me something new.

My first assumption, knowing very little about 3D printing, was that this component was too fiddly to be produced that way — especially the rather fine threaded bit at the top. But reading about different 3D processes, it seemed faintly possible that a nylon SLS printer, with 0.1mm resolution, might just be able to produce a viable part, especially as the thread was required to screw into a metal collar (which could perhaps do a bit of self-tapping) rather than a plastic one.

Modelling the part

Here’s this component in the service manual, identified as “Rewinding axis receiver”. It comes in two variations with codes 2006-3309-02 and 2006-3309-04. I think mine is a 2006-3309-02.Part in maintenance manual

First I needed a 3D model.

I measured it with a vernier caliper and some close-up photos. The thread seems to be 0.5mm x 7mm and the three screw-fixing lugs are spaced at 0°, 140°, and 220°. A hole through the middle admits a metal axle of 4mm diameter. There is a cutout in the collar at the bottom, into which the mechanism to release the film door when the axle is lifted fits. There’s also a slot in the midriff which a metal clip pokes into, to meet a notch in the axle that snaps it into its usual lowered position.

Knowing nothing about 3D modelling software, I asked my kids for advice first. Their suggestion was Blender, but I’m a bit afraid of Blender. I did try Wings3D, another free application (written in Erlang using wxWidgets — interesting!) but I got stuck on how to model a screw thread, and decided I should probably start with a trial version of something expensive with extensive documentation.

I came across Autodesk’s Fusion 360 while searching for screw thread tutorials, when I found a page that basically just said “use the thread tool”, which seemed about right. Fusion 360 is a very expensive subscription product with cloud-storage lock-in, but it has a one-year trial period for “hobbyist” use. That’s me!

Annotation 2019-07-05 203934.png

I really enjoyed using Fusion 360, and I waxed lyrical about it here on Twitter. Much the appeal has to do with good interactive feedback, but the core thing is that it’s built on a very nice 2D sketching program: the expectation seems to be that you sketch in 2D and then extrude into 3D, which I find a lot simpler than trying to design in 3D. But I don’t know how other software of this kind works. Anyway, I successfully built a nice-looking model, though with a thread that I suspected wasn’t really possible to print.

3D printing

I exported the model as an STL file and sent it for nylon/polyamide SLS printing at i.materialise. I have to admit that I picked this company because they had the most anonymous, automatic-looking order page, and I felt embarrassed about having a real person look over my impossible design. I didn’t notice at first that i.materialise are actually in Belgium, and it’s slightly crazy to send your model from London to Belgium for printing when there are companies in London (digits2widgets, 3DPRINTUK) doing the same thing, but by that point I was sort-of committed.

Because of the minimum order price, I ordered three different pieces. Two were from my best attempt at the model, which I asked for once in SLS (laser) process and once in MJF (HP’s ink-based) process. The third was an SLS print with slightly different dimensions for some things I wasn’t sure of. The pieces took about a week to arrive, and the price was quite high — the nominal charge for printing each item was £11.15, but that was quoted before VAT and shipping, and the eventual total was very close to £50.

Here are the results. The black part on the left is the broken original, the white one is the SLS of the variant model, and the grey one on the right is the MJF. (The colour doesn’t matter, as the part is not visible from outside the camera.)

3D printed Minolta parts

Receiving these was a really exciting moment: a true marvel that it was actually possible to design and build this neat little component with no worthwhile expertise on my part!

Of the two processes, the MJF version came out a bit fatter than the SLS — the holes are smaller, the walls are thicker. I think the SLS copy is more true to the design size. Although the texture of the printed nylon is unpolished (they both feel a bit like paper) and looks almost crumbly, both of them feel very solid, are harder and less flexible than I expected, and seem pretty tough.

The threads are indeed pretty sketchy. The SLS one is a little too narrow, without enough depth to the thread: the collar doesn’t tighten well and can easily jump a thread if pushed. The MJF has even less visible thread, but it is a bit too fat, and it is hard to fit the collar onto it at all. In this situation that would probably be a good thing, but the thicker walls of the MJF part interfered with the film-door release disc underneath the part, so it was an SLS copy that I ended up fitting. Here it is in the camera.

3D printed Minolta part fitted in XG-9 camera

I think that the thread, although weak, may hold well enough. It isn’t the last line of defence against the power switch falling off: the rewind knob on top of it, held on with a metal-on-metal screw fitting, is there to prevent that. This thread just needs to stop the power switch from lifting and losing its position while loading or rewinding film. But it would be nice to have done better, if it were possible to do so. I’d like to know if there is some technique for making threads more “printable” at this kind of scale.

Conclusion

This feels like a successful outcome, and at least the original problem is fixed. It would obviously be better not to have broken this part at all — and although it was my fault, I did spend some time mentally railing at Minolta for using a plastic thread here in the first place. Perhaps the main lesson is just that old plastic is fragile. But I enjoyed the process and am happy with the result, which is after all a camera that works better than it previously did.

I’ve published the 3D model, in a Github repository at cannam/minolta-2006-3309-2, in case it is of use to anyone else. If you’ve any suggestions for how this could have been done better, I’d like to hear! Of course this does show a big limitation of using Fusion 360 to do the modelling: the main file in that repo is in a proprietary format and probably useless to any other tool. I’ve included a couple of exports as well, including the STL file.

 

A film camera

I take a lot of photos and I share some of them online via the antique medium of Flickr. Not many people look at them, which I don’t mind, because I imagine my audience to be (a) family and (b) myself, later. Photos I take with people in them are usually visible only to my friends and family. I’m a person who takes photographs, not a photographer.

But I do take some joy in the practice of photography. That’s partly because I can: at my level, there is very little to it: somebody else has done all the hard work. There is massive, long-term, highly technically sophisticated labour behind every functional detail of image capture and reproduction, which all culminates, for routine takers-of-photos like me, in pressing a button or tapping the screen and deciding whether you like the resulting image or not. It’s a ritual that has delivered a spurious feeling of creativity to people for decades, prefiguring the internet age.

There are four categories of potential joy in a photo, and they go in this order:

  1. Looking at whatever it is you’re thinking of taking a photo of
  2. Solving technical problems, or just fiddling with the camera
  3. Enjoying the picture itself
  4. Finding the pic again later and reminiscing

Obviously, photos of your friends in the pub can skip categories 1 (except in a social sense) and 2. Very deliberate landscape photos might have a lot of categories 1, 2, and 3 but not a great deal of category 4. Please understand that I am vaguely blathering about this category thing because it seemed to make sense while I was typing this, not because I think it’s any kind of real system.

I started out taking photos on film, then moved to a digital camera in 2003. By then a digital camera already gave you more pleasure in the likely quality and serendipity of your pictures, good for categories 3 and 4 above. I did keep a film SLR — a Zenit EM, the cheapest second-hand SLR available when I bought it in 1991 — but it’s very clumsy to use, and the category-2 joy you would imagine getting from it never really materialised.

In search of that sort of joy, I recently bought a slightly fancier second-hand film camera from someone on eBay. I wanted something still mostly manual, but more like the kind of thing I never had access to when young. I decided to buy a Minolta, and I’m not ashamed to say that was mostly because I like the old Minolta logo, before they introduced the more familiar Saul Bass-designed all-caps logotype in 1981. The older logo is verging on Comic Sans in its friendliness, and gives the camera a sweet face:

Minolta XG-9

This manual-focus, manual-aperture, automatic exposure Minolta XG-9 dates from about 1980. It was the cheaper of Minolta’s two SLR ranges at the time; the body probably cost slightly more than a 48K ZX Spectrum home computer. It would have been a nice and very practical camera. It also embodies a mind-boggling amount of mechanical complexity compared with modern equipment. To the right is a schematic of the winder mechanism, one of dozens of such illustrations found in the service manual. Winder schematic for XG-9

It was sold to me with a lens at least a decade older than the camera, a splendid-looking chunk of metal with an impressive (and apparently rather 1960s) wide front glass element.

Anyway, I bought this for my category 2, the fiddling. But so far what I’ve appreciated most is the thing I gave as category 1: just looking at the real scene more closely. Without a screen to review photos on, you have to assume that your photo will fail and you will never get to see this again. If an image should appear again, days later when you get the film processed, it’s a fresh delight.

The downside is that the economics of successful photos still apply. That is, only one in ten shots is any good. With a smartphone or digital camera you can take a hundred photos and have ten you really like. With film you buy a 36-photo roll, get three or four decent photos, but have to visit the print shop twice and spend at least £15 buying and developing the film. (Though I was surprised to find that you can still get film processed at Snappy Snaps.)

And how are the photos? Well, it’s a bit like listening to vinyl records. It’s nice for things that benefit from a bit of roughness and vigour, like this kind of thing:

Westbourne Terrace

(That one wanted a lens hood to prevent the flares in the middle and right, but I didn’t have one at the time.)

Or for snaps of people:

41329457102_3b09963088_c

I like both of those a lot, but I’ve yet to get any really successful landscape or “still-life” pics from it and I suspect I never will, now that I’m used to a cleaner, higher resolution digital image.

Will I be using it much? Am I going to carry it around everywhere, but take far fewer and more selective photos than I otherwise might? Probably not, but it might not be up to me anyway. These are fairly solid cameras, but this one is nearly 40 years old and has a few electronic bits as well as sensitive mechanical parts. They do fail in various ways and I don’t entirely trust that it’s going to be still working the next time I want to use it. That primitive but sturdy Zenit will probably have the last laugh.

 

Learning to read Arabic writing: one of my better ideas

I live in London not far from Paddington, where Arabic writing is often seen:

road

I spent my first few years in the area a bit oblivious to this (shops are shops), but eventually I started to wonder about simple things like: are these all the same language and script, or do they just look similar? And of course: what do they say? Then two years ago I took a gamble on the notion that this might be Arabic, and signed up for Arabic evening classes.

On the first day of the class, we were all asked why we had chosen to study Arabic. Everyone else had a proper explanation – planning to study in an Arabic-speaking country, dispatched to an Arabic-speaking country for business, have a parent who speaks Arabic and want to catch up, etc. I’d like to report that I said “I want to be able to read the shop signs on Edgware Road”, but I wasn’t bold enough, so I just cited curiosity.

I kept up the classes (one evening a week) for a year. Arabic is a difficult language and I didn’t excel. I learned simple introductions, some directions, some colours, a bit of grammar, and that I can’t pronounce the letter ع any better than any other native English speaker can. I learned enough that I can now recognise the odd word when I hear people speaking Arabic, but not enough to join in, and anyway I’ve always been very self-conscious about speaking other languages. But I am now able to slowly read (and write) the alphabet.

Predictably enough, it turns out the signage in Arabic around here usually says the same thing as the Roman lettering next to it. That’s the case for most of the text in the street-view photo above, for example. That could be disappointing, but I find it rather liberating. When people put Arabic text on a sign in this country, they aren’t trying to make things weird for native-English-speaking locals, they’re trying to make it easier for everyone else.

Arabic, the language, has 400-odd million speakers worldwide. Arabic the alphabet serves up to a billion users. Besides the Arabic language, it’s used for Persian and Urdu¹, both of which are quite dissimilar to Arabic. As it turns out, most of the places near me that I was interested in are in fact Arabic-speaking, but there are quite a few Persian places as well and Urdu, being the primary language of Pakistan, is widely used in the UK too.

(I have since had it pointed out to me that, for an English speaker whose main aim is to learn to read the script, going to Persian classes would have been easier than Arabic. Persian is an Indo-European language, it’s grammatically simpler, and the language you learn in classes is a form that people actually speak, whereas the standard Arabic taught to learners here I gather is different from anything spoken on the street anywhere. I have since bought a Persian grammar book, just in case I feel inspired.)

Learning the basics of how to read Arabic gives me a feeling of delight and reassurance, as if I am poking a hole for my brain to look out and find that a previously unfamiliar slice of the world’s population is doing the same stuff as those of us who happen to be users of the Roman alphabet. I recommend it.

Notes for the clueless about the Arabic alphabet

  • It’s written and read right-to-left. This is probably the only thing I did know before I started actively learning about it.
  • It is an alphabet, not a syllabary like Japanese kana or a logographic system like Chinese writing.
  • It is very much structured as a script. Each letter could have up to four shapes (initial, middle, final, standalone) depending on how it joins to the letters around it, so that the whole word flows smoothly. I think this contributes a lot to the sense of mystery “we” have about Arabic. The Cyrillic, Hebrew, and Greek alphabets are not intrinsically any more mysterious, but they are a lot more obviously composed of letters that can be individually mapped to Roman ones.
  • Short vowel sounds are not written down at all. This is unfortunate for the learner, as it means you often can’t pronounce a word unless you already know it. There is a system for annotating them, but it’s not generally used except in the Koran and sometimes in textbooks or Wikipedia where avoiding ambiguity is paramount.
  • There are 28-odd letters, but the number depends on what you’re reading – Persian adds a few over Arabic, but I think it also has some duplicates.
  • Some letters are very distinctive; for example the only letter with two dots below it is the common ي “ya”, which generally maps to an “ee” sound. Others are quite hard to spot because you have to know the joining rules to distinguish them in the middle of a word.
  • You could transliterate any language to Arabic, just as you can transliterate anything to the Roman alphabet. The result might be awkward, but there’s no reason you can’t write English in Arabic letters and have it be just about comprensible. I imagine there must be people who routinely do this.

 

¹ I know no Urdu, but I understand it’s typically written in the Arabic alphabet but with a more flowing script (Nastaliq, نستعلیق) than is typically used for modern Arabic or Persian. An interesting calligraphic distinction between languages. I first heard of Nastaliq through a fascinating article by Ali Eteraz in 2013, The Death of the Urdu Script, which lamented that it was too hard to display it on current devices. The situation has apparently improved since then.

 

Why I will be voting “in” this Thursday

Although the public debate about this week’s EU referendum in the UK has become absurdly bitter on both sides, I have had some constructive talks about the subject with people around me, even where we have disagreed. There is, or was, a reasonable debate to be had and it’s a pity we haven’t seen a sensible national discussion about it.

In the spirit of trying to be positive: here are five reasons why I would like the UK to remain in the EU, without talking about the personalities or made-up economic projections coming from the campaigns on either side.

1. The EU has a useful role in the UK in terms of long-term oversight

This country has no written constitution and has an effectively two-party parliamentary system in which each new government starts by setting out to undo whatever its predecessor did. Institutions like the European Court of Human Rights give us both longer-term continuity and a moderating influence across the various ideologies of the European states. They’re a good thing.

I might feel differently on this if I thought the Leave campaign were keen to make up for exit with better constitutional protections in the UK. Unfortunately the impression I get is the opposite.

(I think this argument holds even for lower-level things like food labelling and sourcing regulations. After all, those are also the regulations that mean a Cornish pasty is a pasty from Cornwall wherever you buy it in the EU, not just a meat pie from a factory in Denmark with Cornish Pasty printed on the pack.)

2. Our position within the EU is a great one

We have full membership of the EU without the tricky bit (the Euro) and with a membership rebate that we could never negotiate again. It’s the best of both worlds already. Any country in the world would envy that.

3. Leaving won’t give us more independence

I understand the argument that a state should strive to be self-determining as far as possible. I just don’t think that leaving the EU would have a happy outcome in that respect.

It wouldn’t change anything about who runs this country or how they run it, and it wouldn’t send a message that anybody would be equipped to act on. Our government would continue to have the same pro-business pro-international-collaboration outlook, for good or bad. We would almost certainly end up leaning more than ever on the USA, a country we would no longer have much to offer in return, while scrabbling around for other partnerships and making poorer deals with other European states.

4. Immigration is a red herring, but freedom of movement is a good thing

Immigration is clearly a subject that people feel viscerally about. But the sort of mass migration being exploited for this argument, of refugees from Syria for example, has nothing to do with the subject we’re supposed to be deciding on — we already turn those people away (Calais, remember?). I obviously have views about that (who doesn’t) but it makes no sense for it to be a pivotal subject for this referendum.

What is relevant is freedom of movement for workers within the EU. I think this is a good thing, partly because it’s how we can have world-leading research labs like (ahem) the one I work in, and partly because it cuts both ways — Britons can and do move abroad as well (permanently or temporarily) and this openness is a great part of providing opportunities and prospects for future generations.

People of my age or older may remember the 80s TV series Auf Wiedersehen, Pet, a comedy about British builders working in Germany. A central prop of that programme was that there was something ramshackle about their arrangement and that they were at the mercy of exploitative employers and tax rules as migrant workers. We’ve become unused to thinking of British migrant workers as being exploited in this way.

I know that there is also a narrative about other EU citizens coming to the UK simply to claim benefits. The great majority of people who move here do so either to work or to study, or because they are married to British citizens. Many British citizens draw benefits abroad as well. The overall balance of numbers doesn’t in any way reflect the anxiety people have about it. That anxiety is serious, but it isn’t something that this referendum can properly address with either outcome.

The question of what would happen to EU workers who are already in the UK, if we left, seems like such a massive quagmire that I don’t want to think about it. I don’t think it could be very harmonious.

5. I’d like to see positivity prevail

There’s something very British about willingly engaging in an endeavour (after a referendum!) and then whingeing about it constantly for the next 40 years.

The tone from British media and politicians for decades now has been mostly about how onerous the EU is and “what can it do for us?”, very seldom about the power it gives us or what we can do together with the other countries within it. This negative guff is forced on us by media barons who genuinely have no reason to give a damn about us in the first place, and it ends up setting a very miserable tone. Let’s resist!

 

Naming conventions in Standard ML

Many programming languages have a standard document that describes how to write and capitalise the names of functions, variables, and source files. It’s especially useful to have a standard for writing names made up from more than one word, where there are various options for how to join the words: “camel case”, which looks likeThis (with a capital letter “hump” in the middle), or “snake case”, which is underscore_separated.

I think Java in the mid-90s was the first really mainstream language to standardise file and variable naming conventions. The Java package mechanism requires files to be laid out in a particular way, and Sun published Java coding conventions which quickly became an effective standard for class and variable naming. Other languages followed. Python has had a standard that covers naming (PEP8) since 2001. More recent examples include Go and Swift.

Older languages tend to be less consistent. C++ is a mess: the standard library and most official example material uses snake_case for most names, but a great many developers, including those on most of the projects I’ve worked on, prefer camelCase, with capital initials for class names. File names are even more various: C++ source files are seen with .cpp, .cxx, .cc, and .C extensions; C++ header files with .h, .hpp, or no extension at all.

Standard ML (SML) is also a mess, and an interesting one because the language itself was standardised in 1990 and has been completely unchanged since the standard was revised in 1997. So although it is super-standardised, it’s a bit too old to have caught the wider shift in sentiment toward prescribing things like naming and file structure.

The SML standard is formal and very focused. It says nothing about coding style or naming, contains almost no examples using compound names, says nothing about filenames or file organisation, and specifies no way for one file to refer to another — the standard is indifferent to whether your source code is held in a file at all.

In trying to establish what naming conventions to use for my own code, I decided to look around at some existing libraries in SML to see what they had settled on.

The Basis library

SML has a standard library, the Basis library, which is a bit more recent than the language itself. Although it isn’t prescriptive, the library does use certain conventions itself and the introductory notes explain what they are. These cover only names of things within a program — not filenames, which are left up to the implementor of the standard. I’ll refer to them in the table below.

The Cornell style guide

Top search result for “SML naming conventions” for me is this online style guide for the Cornell CS312 course. It doesn’t cover file naming. Given the limited industry uptake for SML, an academic guide may be proportionately more influential than for other languages. I’ll mention this guide below as well.

Other code I looked at

I took a look at the following code:

  • The source of the MLton, MLKit, and SMLSharp compilers (excluding accompanying utility libraries)
  • The Basis library implementations shipped with MLton and SMLSharp
  • The SML/NJ extended library
  • The source of the Ur/Web language
  • The Ponyo library, an interesting fledgling effort to produce a broader base library than the Basis

In total, about 444,500 lines of code across 1790 SML source files. Some (presumably automatically-generated) source files are very long; while the mean file length is 248 lines including comments and blanks, the median is only 47.

Names within the language

The SML language has at least seven categories of things that need names: variables, type names, datatype constructors, exceptions, structures, signatures, and functors.

(By “variables” I really mean bindings, i.e. the vast majority of ordinary things with names: things that in a procedural language might include function names, variable names, and constant declarations. I’m using the word “variable” because it’s such a familiar everyday programming term.)

Source Variable Type name Datatype constructor Exception Structure Signature Functor
mlton variableName (mixed) DatatypeCtor ExceptionName* StructureName SIGNATURE_NAME FunctorName
mlkit (mixed) (mixed) DatatypeCtor* ExceptionName* StructureName SIGNATURE_NAME FunctorName
smlsharp variableName typeName* DATATYPE_CTOR* ExceptionName StructureName SIGNATURE_NAME FunctorName
basis variableName type_name DATATYPE_CTOR ExceptionName StructureName SIGNATURE_NAME FunctorName
smlnj-lib variableName type_name DATATYPE_CTOR ExceptionName StructureName SIGNATURE_NAME FunctorNameFn
urweb variableName type_name* DatatypeCtor ExceptionName StructureName SIGNATURE_NAME FunctorNameFn
ponyo variableName typeName DatatypeCtor ExceptionName Structure_Name SIGNATURE_NAME Functor_Name
cornell variableName type_name DatatypeCtor ExceptionName StructureName SIGNATURE_NAME FunctorName

* mostly

Here’s what I found, categorised into universal conventions, usual conventions, and “other”.

Universal

The following is the only universal convention:

Signature
SIGNATURE_NAME

The only code I found that doesn’t follow this convention is in the SML standard itself, which omits the underscore (like SIGNATURENAME).

Usual

The following conventions are not universal, but more popular than any other.

Variable Type name Exception Structure Functor
variableName type_name ExceptionName StructureName FunctorName

Camel case is clearly idiomatic for everything except type names. MLKit contains some snake-cased bindings as well, but none of the other libraries did. I like snake case in SML and I’ve written a fair bit of code using it myself; I hadn’t realised until now how uncommon it was. (It’s more common in SML’s sibling language OCaml. Ironic that, of the three very similar languages SML, OCaml, and F#, the only one not to use camel case is called OCaml.)

I spotted a handful of all-caps exception names and some camel case type names, but no library preferred those consistently.

The Ponyo library differs from the above for structures (Structure_Name) and functors (Functor_Name).

The SML/NJ library sort-of differs for functors, which are given a Fn suffix (FunctorNameFn). But you could think of this as part of the name, in which case the convention is the same.

Most type and datatype names used in public APIs are single words, or even single letters, so the convention often doesn’t matter for those.

Other

There seems to be no consensus about datatype constructors — I found DatatypeConstructor and DATATYPE_CONSTRUCTOR in roughly equal number.

Filenames

Nothing in the SML standard or Basis library cares about what source files are called, what file extension they use, or how you divide your code up among them. Some compilers might care, but most don’t. The business of telling the compiler which files a program consists of, or of expressing any relationships between files, is left up to external tools. SML has neither header files nor import directives.

This makes fertile ground for variety in naming schemes.

I’m going to consider only filenames that are associated with a primary structure, signature, or functor. Here’s the table.

Source Structure Signature Functor
mlton structure-name.sml signature-name.sig functor-name.fun
mlkit StructureName.sml SIGNATURE_NAME.sml* FunctorName.sml
smlsharp StructureName.sml SIGNATURE_NAME.sig* FunctorName.sml
mlton-basis structure-name.sml signature-name.sig functor-name.fun
smlsharp-basis StructureName.sml SIGNATURE_NAME.sig (none)
snlnj-lib structure-name.sml signature-name-sig.sml functor-name-fn.sml
urweb structure_name.sml signature_name.sig (n/a)
ponyo Structure_Name.sml SIGNATURE_NAME.ML Functor_Name.sml

* mostly

Clearly very inconsistent. There are no universal or usual conventions, only “other”.

Behind this there is a wider question about code organisation in files — should each signature live in its own file? Each structure? In many cases they do, but that is also far from universal.

If you use a scheme in which filenames are clearly derived from signature and structure names, does that mean you shouldn’t put more than one structure in the same file? What do you do with code that is not in any structure? Really it’s a pity to have to think about filenames at all, in a language that is so completely indifferent to file structure.

A Reasonable Recommendation

A plausible set of rules based on the above.

For names within the language:

Variable Type name Datatype constructor Exception Structure Signature Functor
variableName type_name DATATYPE_CTOR ExceptionName StructureName SIGNATURE_NAME FunctorName

This is the style used by the Basis library. Apart from datatype constructors, everything here was in the majority within the libraries I looked at.

For datatype constructors it seems reasonable to pick the most visible option and one that is consistent with the names in Basis. (This differs from the Cornell guide, however.) There is no confusion between these and signature names, because signature names never appear anywhere except in the declaration lines for those signatures and the structures that implement them.

For filenames:

Structure Signature Functor
structure-name.sml signature-name.sig functor-name.sml

The logic here is:

  • It’s still not a great idea to expect a case sensitive filesystem, so all-one-case is good
  • Generally use .sml extension for SML source
  • But the .sig extension for signatures seems very widely used, and it’s fair to make public signatures as easy to spot as possible
  • The .ml extension is not a great idea because it clashes with OCaml
  • The .fun extension used by MLton is a bit obscure, and you don’t always want to separate out functors (if you want to make functors more distinctive, give them names ending in Fn, as the SML/NJ library does).

 

Bowie

Here’s a playlist of good David Bowie songs that I had never heard until after he died last week.

Spotify playlist
YouTube links:
Dead Against It (1993)
Up The Hill Backwards (1980)
Move On (1979)
Dancing With The Big Boys (1984) (with Iggy Pop)
I Would Be Your Slave (2002)
Girl Loves Me (2016)
You’ve Been Around [Dangers 12″] (1993) (Jack Dangers remix)
Nite Flights (1993) (Scott Walker cover)
No Control (1995)
Bring Me The Disco King (2003)
I’m Deranged (1995)
5:15 The Angels Have Gone (2002)

Most of these came out after the peak of his popularity, but they aren’t obscure at all — I was just never a fan.

The first Bowie songs I remember hearing on the radio were Modern Love and Let’s Dance, both released in 1983 when I was eleven. I thought those two were fine, though they weren’t the sort of thing I liked to think I was into at the time. (I had a big Motörhead war-pig patch on my little denim jacket. Lemmy’s death was also the end of an era.)

A few years later, a cousin introduced me to some of the Spiders from Mars period songs like Rebel Rebel and Suffragette City. I was a bit puzzled because I thought I knew Bowie as a smooth, modern 80s-sounding chap. But I didn’t get the appeal either: too much like everything else from the early 70s. Rebel Rebel even sounded like the Stones, which was definitely my dad’s music.

Back in the real timeline of the 80s, Bowie was releasing Never Let Me Down, an album seen everywhere (one of several awful record covers) but seldom played, then launching the drearily adult Tin Machine.

His next album, Black Tie White Noise, didn’t come out until 1993, when I was briefly in Berlin as a student and mostly listening to industrial music and obscure things I read about in Usenet groups. If I had been aware that David Bowie had an album out, I would certainly have ignored it. By the time of 1997’s Earthling, a jungle-influenced album released a whole two years after peak jungle with a dreadful Cool Britannia cover, it felt socially impossible to admit to liking a Bowie song ever again. And that was pretty much the end of that.

There’s been a David Bowie album, collaboration, tour, or retrospective for almost every year of my life, and I’ve never taken more than a passing interest in any of them.

I was taken by surprise, then, by how emotional I felt about his death.

***

What did eventually make me notice David Bowie as a figure was the connection with Iggy Pop. I think Iggy is brilliant, and I’d been a bit of a fan for a while before I eventually twigged what it was that his most interesting stuff had in common. That made me aware of the famously dramatic and productive spell for those two in Berlin the late 70s (the only albums of Bowie’s that I ever actually bought are from this period) and also an opening to a bit of a web of interesting collaborations and influences.

(Going back during the past week and filling in a lot of the songs of Bowie’s that I’ve missed during the last few decades, it’s been particularly fun to hear Iggy Pop numbers, er, pop up all over the place. China Girl — always an Iggy song to me — is well known, but there are at least three other albums that recycle songs previously recorded by him, including a straight cover of the flop lead single from Iggy’s most foolish album. A sustained friendship.)

***

So something of the emotion for me has to do with all that Berlin stuff. There are two aspects to that. One is the grubbily romantic idea of “pressure-cooker” West Berlin, seen from a distance as a place of hideouts, drugs, spying, longing, separation, and any other melodrama that “we” could project onto it. I’m sure this version of the city was overstated for lyrical purposes, but it probably did exist to a degree. The Berlin that fascinated and frightened me in 1993 was already a very different city, and both versions are hardly visible in today’s shiny metropolis.

The other aspect is the notion that moving to a different town in a different country could give you a new life and make your past disappear, even for someone already so celebrated — that it could really be so simple. What makes that idea available here is that Bowie didn’t just go, but then produced such different work after going that it really could appear as if his past had not gone with him.

This impression of self-effacement alongside all the self-promotion, the ability to erase the past, is a very attractive one for a pop star, and it fits also with the amount of collaborative work Bowie did. From some of the videos you can imagine that he was never happier than when playing keyboards or doing tour production for Iggy, singing backing vocals in a one-off with Pink Floyd, or playing second fiddle to Freddie Mercury or Mick Jagger.