Posts

What languages did you learn, in what order?

I once compiled the following list of programming languages and which year I started learning them: 1981: Sinclair BASIC (on a ZX81) 1983: BBC BASIC (on a BBC Micro) 1985: Pascal (installed via ROM) 1987: Logo 1987: 6502 Assembly (on a BBC Micro) 1989: ARM assembly (on an Acorn Archimedes) 1992: Casio fx-7700 BASIC 1992: C (using the excellent Norcroft compiler for Acorn computers) 1994: C++ (the awful Beebug Easy C++) 1995: UFI (on a VAX running OpenVMS) 1996: StrongARM assembly 1996: Standard ML 1997: Mathematica 1998: Quake C 2004: OCaml 2006: Java 2007: Common Lisp 2007: Scheme 2007: Scala 2007: Haskell 2007: F# 2009: Clojure 2010: HLVM 2017: Elm 2017: Javascript I was recently concerned to hear from  Socio-PLT: Quantitative and Social Theories for Programming Language Adoption that the number of languages a programmer knows stagnates after the age of just 20. The decade is nearing its end but I have only learned three languages. Now I'm wondering which languages I should lear...

Background reading on the reference counting vs tracing garbage collection debate

Image
Eight years ago I answered a question on Stack Overflow about the suitability of OCaml and Haskell for soft real-time work like visualization: " for real-time applications you will also want low pause times from the garbage collector. OCaml has a nice incremental collector that results in few pauses above 30ms but, IIRC, GHC has a stop-the-world collector that incurs arbitrarily-long pauses " My personal experience has always been that RAII in C++ incurs long pauses when using non-trivial data (i.e. nested, structured, collections of collections of collections, trees, graphs and so on), non-deferred reference counting has the same problem for the same reason, tracing garbage collectors like OCaml work beautifully but there are many notoriously bad tools like Java that have given tracing garbage collection a bad name. Now that I am revisiting this issue I am surprised to find many individuals and organisations repeating exactly the same experimental tests that I did and coming...

Does reference counting really use less memory than tracing garbage collection? Mathematica vs Swift vs OCaml vs F# on .NET and Mono

Image
Our previous post caused some controversy by questioning the validity of some commonly-held beliefs. Specifically, the beliefs that reference counting (RC) always requires less memory than tracing garbage collection (GC) and that tracing GCs require 3-4x more memory in order to perform adequately. We presented a benchmark written in Swift and OCaml and noted that the RC'd Swift implementation ran over 5x slower and required over 3x more memory than the tracing GC'd OCaml implementation. This observation disproves these beliefs in their strong form and even brings into question whether there is even any validity in the weak forms of those beliefs. After all, we have never seen any empirical evidence to support these beliefs in any form. We received a lot of criticism for that post. The vast majority of the criticism was not constructive but two valid points did arise. Firstly, although our result was anomalous it would be more compelling to see the benchmark repeated across a w...

Does reference counting really use less memory than tracing garbage collection? Swift vs OCaml

Image
The way software developers cling to folklore and avoid proper experimental testing of hypotheses really bothers me. I think perhaps the worst branch of computer science still riddled with myths and legends is memory management. Despite over half a century of research on garbage collection showing that reference counting is inferior to tracing garbage collections algorithms (even when almost all GC research restricts consideration to Java when much better algorithms have been known for years) there are still many people who claim otherwise. C++ developers obviously still believe that reference counted smart pointers are superior to tracing garbage collection but now other people are doing it too. People who should know better. This situation recently reared its ugly head again when Apple released a promising new programming language called Swift that shuns tracing garbage collection in favor of reference counting. Now, there are logical reasons for Apple to have chosen reference count...

Xavier Leroy's "standard lecture on threads"

Xavier Leroy’s standard lecture on threads post from the caml-list in 2002 seems to have disappeared from the INRIA archives so I am reproducing it here for anyone who is interested. This post is of historical interest because it explains why OCaml has no support for multicore parallelism to this day (twelve years after the release of the first consumer-level multicore CPUs). Date: 2002-11-25 (10:01) From: Xavier Leroy <xavier.leroy@i...> Subject: Re: [Caml-list] Why systhreads? It seems that the annual discussion on threads started again.  Allow me to deliver again my standard lecture on this topic. Threads have at least three different purposes: 1- Parallelism on shared-memory multiprocessors. 2- Overlapping I/O and computation (while a thread is blocked on a network    read, other threads may proceed). 3- Supporting the "coroutine" programming style    (e.g. if a program has a GUI but performs long computations,     using threads is a nicer wa...

Disadvantages of purely functional programming

I have been asked to elaborate on my answer on Quora so here goes:   1.        There is no efficient purely functional unsorted dictionary or set Since the 1990s the use of dictionaries in software has gone through the roof. Dictionaries are now a stock collection type that every programmer expects to find in their standard library. Purely functional or persistent data structures such as those found in Okasaki’s fabulous monograph on the subject can be a great tool. In particular, the persistence they offer means you can reuse old versions of collections without having to worry about mutation. In many cases (particularly for some kinds of problems such as logic programming and compiler writing) this can make solutions shorter and clearer, partly because it makes backtracking trivial. However, persistence comes at a great cost in terms of performance: purely functional dictionaries are typically 10x slower than a decent hash table and I have seen...

ARM code generation quality

I previously looked at x86 code generation quality and found that GCC does some interesting high-level optimisations but, in that case, any performance benefit was lost in poor quality code generation. In this article I’m going to look at ARM assembly instead.   Compiling the Fibonacci function in C from last time we obtain times ranging from 2.4s to 6.6s for fib(40) using –O2 to –O0. Interestingly, using –O3 actually worsens performance over –O2. As before, inspection of the generated assembly language shows that GCC employs nifty high-level optimisations when given the –O2 option.   The simplest implementation of our Fibonacci function in ARM assembly is perhaps:   fib:         cmp     r0, #2         movlt   pc, lr         stmfd   sp!, {r1, r2, lr}         s...