Pages

Monday, July 3, 2017

The miracle of C




It is not fashionable to love the C language. Not like, but love. Time moves on and glorifying something from the seventies seems idiotic. But let us use a standard historian's trick: take C away and see what changes.

What would systems programmers use? FORTRAN? Assembly language? Pascal?

We would not have Java with the current syntax or semantics, no dotNet beyond Visual Basic, no browsers, no TCP/IP, no proliferation of language wars, and no C++.

LISP may have evolved to be more widely usable, and Pascal would have likely gained some practicality, at least proper initializers and scoping, and maybe modularity. FORTRAN would have remained dominant. We would still have APL, it was miraculously written in 360 assembler.

Oh yes, JavaScript would be LISP.  Git would be an unrealized dream, as would Lua and LabVIEW and probably MatLab.

Maybe evolution would have found a way, and maybe the down side of C's flexibility and power is fertility. It is an engine of change.

C is attributed to Dennis Ritchie, but its precursor, B, which has an almost identical syntax is pure Ken Thompson. It is this syntax that is so compelling. It is the closest thing to the thought process of a programmer. I would rather write in C than in anything else, and I am confused by those that thought that something like awk of sh were even necessary to make scripting easier. I can do most of it faster in C. And please do not bring up Perl.

C is compact, and it is complete and orthogonal and close to damn perfect. Arrays, pointers, and increments all mesh, probably thanks to Ritchie's semantics.

C is not a glorified assembly language, it is the centre of computer languages, instruction sets have evolved because of it. It distilled all that one needs or wants to do with a CPU.

Objects and user interaction are layers that can easily be added, and C has no trouble with these things, it can stretch.

Many say one can get hurt by its lack of constraint, but I find I get much more hurt by a lack of elegance and clarity in other languages, I sometimes feel like the ugliness of a language can hinder expression, or at least confuse it, and waste programmer's time.

I use C to develop algorithms that I sometimes need to implement in other languages, because it helps to reduce notational ambiguity. It is also universal. In that sense it is a kind of mathematics. Ken Thompson holds a very mathematical view of computing, in a good pragmatic sense, this is the guy who implemented regular expressions, who writes papers that are a joy to read, and who seems to think in a bottom-up clear way. Because of this, I think of him as a founding father of modern computer languages, he took Algol and its kin and made a definitive contribution.

C++ is not an improvement, it is a shameful opportunistic perversion. I use it because it has C in it, and luckily it remains compatible, and its flaws have inspired improvements, like Go. Even C# is a blessing compared to it. Bjarne's complaints and justifications around the preprocessor are noise. The preprocessor in C is a wonderful tool, and used well it can make the language do anything and work anywhere. It is brilliant meta hack. A leap of inventiveness, and rather than dismiss it as a source of bugs, it should be entrenched. C++'s templates are good things, but please do not claim they came to be as replacement for the preprocessor. Without it C++ would not have come into being so quickly. That same preprocessor was used by Bjarne to implement C with classes before it became C++.

Linus is right to dislike C++, it is easy to mess up in it, simply because it hides stuff, and I mean encapsulate is a bad word sometimes. So is overloading if misused, and programmers are a conflicted bunch, they sometimes favour cleverness over communication. I know, I do it and then regret it when I read my code later.

On the other hand, I do the OOP thing, and I think it can help code maintenance and force teams to adhere to design intentions, however it can all be done in C, if you are familiar with its philosophy. One architect I worked with a long time ago would write .h files and pass them around to developer to flesh out into .c or .cpp files. Objects take this a bit further, but not much. The biggest benefit is when doing UI's and other repetitive verbose coding, or when you want to get rid of switch statements all over the code.


And yes, no C, no Unix, no Linux, no Web as we know it.

I am not slamming other languages, just trying to put C where it belongs, at the top (because it is bottom up :-), for its expressiveness, rigour, elegance and efficiency. Did I forget anything?

Thursday, June 29, 2017

Callow journalism




I often read the Guardian, the ex-Manchester Guardian, the venerable trust-funded independent paper. It valiantly and explicitly attempts to clearly separate facts from opinion, and has a wide range of points of views, but is definitely to be categorized as left-leaning.

Recently, in the wake of the UK election, it has suffered from a kind of existential angst. Many of its columnists, Oxbridge graduates and smartypants, could not bring themselves to support Corbyn. His strong showing at the polls exposed a disconnect between the "smart left" and the populist left.

The Guardian must (rightly so to speak) show support for Corbyn, while swallowing its pride at the nasty things it said about him before, things like "un-electable", "weak", etc.

Some sectors of the UK obviously still suffer from class considerations. It appalled me to read about the jibes against the "non-toff" Corbyn, both in the Commons, by people like Cameron (the tie etc), Blair, sniping from the manure-infested sidelines, and May. I think the Guardian columnists could have done more to express outrage at this. I also believe that there is a smell of class bias in their attitude and sneering, a small whiff.

I still read the Guardian, but I do not trust it as much as I once did. To be fair, some columnists stood by Corbyn, courageous iconoclasts like Monbiot.

More and more, I invoke Hunter Thomson's warning about journalism, how it is a kind of storytelling, and how it has to stop pretending to be objective. The positivist mind-set of the Anglo-Saxon world needs to be reviewed, and merged with the Continent's existential views, not the salon existentialism that they sneer at, but the stance that sees human affairs as intrinsically engaged with their observers. Journalism is a form of history, and the teller matters there.