Pages

Showing posts with label computer science. Show all posts
Showing posts with label computer science. Show all posts

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?

Monday, December 30, 2013

Open letter to Lakoff about his book on math


Dear Prof. Lakoff

A short note to say how much I am enjoying "Where Mathematics Comes From". It is providing closure for me.

In the 1980's, I fell in love with math during a college course based on the very foundations-conscious Calculus text by Spivak and although I enjoyed the rigor and beauty, I could not help but feel a bit uneasy at the hoops one had to jump through for the proofs to work, all this in the name of eliminating intuition.

I eventually ended up on the "applied" side, to the regret of my wonderful teachers, because I felt much more at ease with the way things seemed to work out intuitively. Successive approximations to non-linear functions using the university mainframe seem to do the trick of finding solutions to things I was curious about. Infinitesimal approaches, simplex algorithms and Fourier series implemented in WATFOR to solve hard differential equations numerically were simple but magical approaches to understanding. I was gratefully standing on Turing and Church's shoulders.

Anyhow, over the years I kept looking for insights as to why the pure math left me a bit uneasy since I still admired the beauty of it, (like pining for a high-school sweetheart) in all kinds of places including David Foster Wallace's overly baroque book on the math of infinities (yikes).

Your book reconciled the comfort of the applied and the beauty of the formal for me. There is a cognitive continuum after all, between the purists and us engineering/computing folk.

It connected the dots, clarifying the things that seemed like bridges by grounding them. By focusing on the metaphors for infinity it helped in categorizing things that were both computing and theory, but that could only exist because of computing: compiler theory, the Aho-Ullman stuff derived from Chomsky. I can now see why there was all this cognitive dissonance when I was learning Analysis.

For example, the space-as-points versus space-containing-points argument you and Nunez make is beautiful and could be applied to the philosophy of physics as well. The notion of particle comes to mind. I think Feynman the intuitionist in physics is a counterpart to Poincare in the world of math. His explanations of energy quanta and fields address the analogous notions of space and points in the world of physics, where it seems some still cling to the Platonic reality of math. The intuitionists, like Poincare, were very courageous and insightful as well as demonstrably able to make new discoveries as they sidestepped the Gottingen school's rejection of intuitive geometry and Cantor's objectification of infinities. Set theory is nice but infinity is just NaN.

I had read Kline's history of math some years ago and although I agreed with his view that a rift in math was created at the time when intuition was relegated to a sideline, there seemed to be something missing, much more to say. Your work with Nunez closed that loop for me.

I am now curious and encouraged to find out more about any research to make rationals (the real Reals :-)) the basis for discretization, as well as links between foundations work and Chomsky's formal grammars. I agree as the book infers that terminology in math is key to disambiguation - but technical terms like Real and continuous are too deeply entrenched of course. Maybe intro calculus courses should begin with a review of those specialized semantics. Like lawyers learning contract terms...

I am also curious about reactions to your work from the math community (rather than by the pedagogical folks) since I think the arguments are revolutionary and deeply original. I looked cursorily on the Web but found little of substance in reaction or support of the ideas in the book. Are mathematicians looking into closing the gaps you identify? Did you get much substantive opposition to your views? Finally, kudos for the other wonderful work on political discourse. Sorely needed. I wish I could be young enough again to enroll as a student of your faculty, but I will continue to follow your research with great interest nonetheless.