Archive

Archive for November, 2005

BBC Computer 32K

November 27th, 2005 3 comments

BBC Computer 32K
The BBC Model B computer. The computer was bought by my father in 1984 using some money which he received from the death of his father. I was nine years old. This was our grandfather’s legacy for us. That single purchase for £400 in Beatties department store in Wolverhampton 21 years ago changed my life greater than any other single purchase made before or since. It wholly responsible for my career since that time.

In terms of the hardware of the time, the BBC Microcomputer was something special. It had 32 kB of RAM for programs and the display and 32 kB of ROM containing the operating system and BBC BASIC, occupying the 64 kB address space of the 6502 CPU. We had a somewhat unreliable cassette deck for storing programs.

I probably spent thousands of hours over the next four years learning to program, mostly in the fantastic BBC BASIC (real prodecures with parameters, REPEAT..UNTIL loops and no real need to use GOTO, and of course integrated 6502 assembler) which gave me an excellent grounding in structured, procedural programming. I had a good line in writing software for my father to help in his land and engineering surveying work, which was my first introduction to writing mathematical and engineering software – all in BBC BASIC.

I also spent time fiddling with the hardware side of things, very much encouraged by the massive expandability of the BBC Micro. Usuually this would involve connecting home-made devices, motor controllers and the like, to the User Port (pretty raw access to a 6522 VIA chip) or to the Analogue Port. All of this was inspired by a series of articles by Mike Cook in The Micro User (later Acorn Computing) Magazine called The Beeb Body Building Course.

So why the nostalgia?

Well, two reasons. The first is that this early exposure computing is largely responsible for my career path, and the fact today that I now work as a software developer. The second reason is that last week I downloaded an impressively good BBC Micro emulator for my PC called BeebEm.

Obviously, a BBC emulator isn’t much use to me these days for software development, and all the interesting hardware aspects of the Beeb are of course not relevant. Nonetheless, it did give me the opportunity to indulge in some serious nostalgia playing old games such as Thrust, Elite and Exile.

Categories: 8 bit, computing Tags:

Personal Moore’s Law

November 26th, 2005 No comments

1984: BBC Model B Computer 2 MHz 8-bit 6502 CPU, 32 KiB RAM. OS 1.2
1988: Acorn A3000 8 MHz 32-bit ARM2 CPU, 1 MiB RAM. RISCOS 2
1990: Acorn Archimedes A420/1 8 MHz 32-bit ARM2 CPU, 2 MiB RAM, 20 MB hard disk. RISC OS 2
1992: Acorn A4000 12 MHz 32-bit ARM250 CPU, 2 MiB RAM, 80 MB hard disk. RISCOS 3
1994: Generic PC. 66 MHz 486 DX2 32-bit CPU, 4 MiB RAM, MS-DOS and Windows 3.1
1997: Generic PC. 333 MHz Pentium II 32-bit CPU, 64 MB RAM. 6.4 GB disk. Windows 95.
2000: Generic PC 500 MHz AMD Athlon 32-bit CPU, 128 MB RAM. 18 GB disk. Windows 2000.
2001: Generic PC 2 x 533 MHz Celeron 32-bit CPUs, 128 MB RAM. 18 GB disk. Windows 2000.
2003: Generic PC 1 GHz AMD Athlon 32-bit CPU, 256 MB RAM. 18 GB disk. Windows 2000.
2003: Toshiba Portege R100. 900 MHz Pentium M 32-bit CPU, 768 MB RAM. 30 GB disk. Windows XP
2004: Sun Microsystems Sunblade 100. 500 MHz UltraSPARC IIi 64-bit CPU, 768 MB RAM. 80 GB disk. Solaris 10.
2006: Apple Mac Mini. 1.66 GHz Core Duo. 32-bit CPU. 512 MB RAM. 80 GB disk. Mac OS X Tiger

Categories: Uncategorized Tags:

A sub-orbital trajectory from the C++ productivity black-hole

November 25th, 2005 4 comments

There’s an awful lot of C++ out there. As a industry we’ve been pumping out C++ code since we collectively jumped on the object orientation bandwagon in the early 1990s. There are large systems, each with millions of lines of code created entirely in C++. Every day thousands of hours are spent, at fantastic expense, finding memory leaks, wondering why pointers are dangling and waiting hours for our code to compile. And these are the major contibutory factors to the big C++ problem.

Productivity.

Or lack of it. You see, writing C++ is easy. Writing good C++ is hard. Of course it is possible to write solid C++ but the unfortunate truth is that the huge existing body of code is unlikely to be rebuilt around the good programming techniques facilitated by libraries such as Boost or Qt. We will continue on the long death-march down the road of ongoing mainentance.

So why do programmers continue to subject themselved to working in C++, and why do our managers not only think this is acceptable, but activly encourage it? Of course, there are many reasons, but two stand out. First of all, many developers value the performance of their code, over their personal productivity. The second is the perceived difficulty of learning a different programming language in which to create better code.

My experience is that developers display an almost unnatural obsession with the performance of their code. This need for high performance has become some sort of pseudo-requirement for new code in the mind of many developers. Performance is commonly cited as a reason for using C++ over and above some other language such as Java or Python. But rarely is it necessary; many developers are not aware of exactly how fast their code needs to be, or conversely how slow it can afford to be. In spite of the claim that performance is important, the overwhelming majority have never used profiling tools in order to truly improve performance in the few lines where it counts. Why is performance valued more highly than rapid producing something that works?

This attachment to performace presents a serious problem, since for most programming tasks it is possible to write faster solutions in C++ than is most other programming languages. Any other language is then almost always a notch down in performance, even though this in itself is usually irrelevant for the task at hand. Perl hackers have recognised this for years with ‘You can sometimes write faster code in C, but you can always write code faster in Perl’ – although I fully agree with the spirit of their statement I actually think Perl introduces its own set of syntactic productivity barriers.

So given these topsy-turvy circumstances we should expect managers to be challenging their developers. Our managers should be asking why we are using tools such as C++ which make it unnecessarily awkward and time-consuming to write reliable code, and which do nothing to prevent common categories of errors. They should be encouraging us to write in Python, Ruby or even C# which allow us to much more rapidly create something which works, and which will liekly require much less cumulative maintenance over the life of the software. Furthermore, developers should be volunteering to use these tools in droves since their own productivity will increase massively, which is surely good for their careers and employers, and they will spend less time with mind-numbing debugging.

Although there is certainly biodiversity in the programming language jungle, most developers choose only to sample one or two programming language fruits and usually these are usually very similar – more a case of oranges and lemons than apples and oranges. For example many developers may know C++ (from work) and Java (from college). This citric experience provides a limited perspective on programming solutions. I don’t believe that the best programmers ‘think in C++’ or ‘think in Python’, in spite of some excellent books with that moniker. The best developers – the superstars our teams depend on – ‘think in software’, some sort of well defined, but difficult to expess, higher-level concept of how software should be designed and implemented. These great hackers know several languages which exploit different paradigms – C++ (imperative, strong, static typing), Python (imperative, strong, dynamic typing), Haskell (functional, strong typing) – and they are comfortable with applying techniques from one language in another, for example, by writing reliable code in C++ by avoiding functions with side-effects. Learning languages is relatively easy within a given paradigm – for example a C++ programmer learning Python. Crossing paradigm boundaries can be more challenging I’m a C++ developer by trade and I still struggle with functional Haskell – largely through lack of practical experience. However, the majority or programmers know only one language well enough to apply it commercially, and more remarkably show little curiosity about what other programming languages could offer them.

So why all the fuss about multiple languages and the corporate obsession with C++ ?

I recently had the dubious honour of being asked to review some C++ code which both transformed XML recieved from a socket into standardized SOAP requests. I was asked for comments on how the code could be improved, or refactored. The original was unreliable, leaked memory, and hogged the CPU due to some dubious socket handling. I hacked around in the code for 15 minutes looking for easy opportunities for improvement; hoping to make an impression, or spot some neat refactoring that could be applied. I was struggling – the code was almost unreadable, with five different string representations (don’t ask) and multitudinous conversions between them. It was clear that this particular problem was indeed the proverbial nail being pounded by the proverbial C++ hammer. Nobody volunteers to do XML processing in C++ do they? When I encountered inhumane C++ SOAP bindings statically generated from WSDL files I knew I had seen enough. I wanted to recommend that the code be rewritten in something more suited to the problem at hand- in this case I though Python would be a much better fit to the problem with its nice XML processing and SOAP libraries.

I spend a few evenings trying to understand the intent of the original code and re-implementing it in Python – not line-by-line as that would have achieved nothing – but from a higher level perspective. The result? I had reduced 8000 lines of C++ down to around 800 lines of Python, and I had enjoyed myself to boot. This was the first time I had experienced the fabled 10:1 code reduction of working in Python in a non-trivial example. I was amazed. Surely I had missed some critical piece of functionality? But no, it was all there – and what’s more it nearly worked.

I presented my late-night efforts back to my colleague who had introduced me to the problematic C++ code initially. He responded enthusiastically. We spend a few days with him debugging, and me helping and hinting – a kind of pair programming separated by communicating only through Jabber and source control over the 300 kilometres of mountain and glacier that separated us. Within 36 hours and with some help from tcpdump, he had something that worked. We had slain the leaking, intransigent, C++ beast, and replaced it with a svelt Pythonic beauty.

And then he talked to his manager.

I wasn’t present, but I imagine the conversation went something like this:

Developer: “You know the SOAP agent we’ve been having trouble with?”

Manager: “Yeah – the one we need to fix and deploy by the end of next week?”

Developer: “Well, most of the problems are sorted, its no longer leaking memory and the socket communication is now far more reliable. In fact – I’m confident its now a quality product.”

Manager: “So what was the problem?”

Developer: “Well, we didn’t want to waste more time tracing leaks in the C++ version, so we recoded it in Python; now its 90% smaller, and far more robust. By the way, you know how the older version only worked on Windows? Well now it also works on our Linux, Solaris and Irix too!”

Manager: “We can’t use it.”

Developer: “The only catch is that we don’t have experience of deploying Python applications, so there might be some work to do on the installer, but this program is usually installed by sys-admins anyway, and we’re sure its solvable in the …”

Manager: “We can’t …”

Developer: “… Excuse me?”

Manager: “We don’t use Python here. We use C++. We can’t afford the overhead of developers needing to know more than one language.”

Ouch! So now the Python solution, which is a much better technical fit to the problem than the C++ behemoth is rejected because it is feared the cognitive load of learning a second language may be too high for some developers. Worse still, the hopes for our enthusiastic colleague becoming a topline developer are diminished, because rather than valuing diversity of programming language knowledge, the application of such abilities is frowned upon as ‘too costly’.

There is hope for Python, Ruby and other productive languages though to overturn the C++ monopoly in the realm of proprietary software, non web-based sofware. (Remember real applications?) But with developers on the one hand needlessly obsessing about which functions they should inline, or avoiding dynamic_cast completely because its slow, and on the other hand managers encouraging a language monoculture to protect their developers from having to learn something new, I think change will take an order of magnitude longer to achieve than we have seen in the FOSS world. Achieving escape velocity from the black hole of C++ productivity cannot be achieved without both main engine developer thrust and management boosters. Developers on the ground must accept that using a language slower than C++ can be a good thing, and managers need to permit a degree of linguistic diversity in the interests of multiplying the productivity of their teams.

Categories: C++, computing, Python, software Tags: