I never understood the appeal of this, or SICP, or Scheme in general. I learned much more about computer science reading algorithms and data structures textbooks, especially Knuth.
There's a reason MIT uses Python for its intro courses now, after all.
SICP introduced a lot of fundamental concepts in CS to me as a junior, self-taught developer. Building everything up using immutable functions and then introducing mutable state was revelatory and still influences my design decisions 15+ years on. Scheme was somewhat beside the point.
SICP for me was the missing link between learning syntax and code to designing actual programs that solve real problems. It made me step back and look at a problem not as something that just needs a layer of code thrown at it, but as a task to complete, with requirements, constraints, etc. to consider before a single line of code is even written.
Let me say something that may reveal my ignorance, but which I'm very happy to be corrected on: for the purpose of writing moderately-sized, everyday programs, I've never needed to understand how computation works theoretically (more abstractly than introductory algorithms and data structures). And that's not because I'm not comfortable with abstraction, or because I don't know how it works theoretically, I just haven't.
Further, the obstacles I face when coding are mostly tightly coupled to the fact that I'm programming on physical hardware – again, nothing to do with the theory of computation. Even in a high-level language like Python, if you program the Sieve of Eratosthenes in a naive way without understanding what's going on under the hood with deleting an element from a list, you're going to have a bad time [0].
To caricature SICP-style instruction a bit, I'm imagining someone learning that recursion is useful (Scheme peeps seem to love it) without also being taught it generally has poor performance characteristics.
Perhaps a better criticism is the mostly useless emphasis on immutable data structures. The example I like to bring up is how Haskell for a long time didn't have a readily-available hash table implementation for completely ideological reasons. No, hash maps are strictly worse, thank you.
> To caricature SICP-style instruction a bit, I'm imagining someone learning that recursion is useful (Scheme peeps seem to love it) without also being taught it generally has poor performance characteristics.
SICP teaches that recursion can have bad performance and how to use it without blowing the stack or wasting time with unnecessary computations. Scheme, the language, requires tail call elimination so compilers will transform tail recursion into something as fast as a conventional loop.
Yes, I agree, that is a caricature. More seriously, I think leaning on this language-specific feature in a book that's supposedly teaching "general programming 101," or whatever, is in bad taste. As it says:
> One reason that the distinction between process and procedure may be confusing is that most implementations of common languages (including Ada, Pascal, and C) are designed in such a way that the interpretation of any recursive procedure consumes an amount of memory that grows with the number of procedure calls, even when the process described is, in principle, iterative. As a consequence, these languages can describe iterative processes only by resorting to special-purpose ``looping constructs'' such as do, repeat, until, for, and while. The implementation of Scheme we shall consider in chapter 5 does not share this defect. It will execute an iterative process in constant space, even if the iterative process is described by a recursive procedure. An implementation with this property is called tail-recursive. With a tail-recursive implementation, iteration can be expressed using the ordinary procedure call mechanism, so that special iteration constructs are useful only as syntactic sugar.
This is an example of a point where an algorithms book is helpful + clarifying and SICP is really not. (fake quote: "Be conceptually sloppy and let Scheme take care of it, kid.") It has a few pages on orders of growth, but the coverage is not amazing.
I wouldn’t really call tail-call elimination a feature, language-specific or otherwise. Instead, I would describe the lack of it as a bug. If you examine what’s actually going on in compilers that lack tail call elimination, what you witness is the saving of registers to the stack whose values are provably never going to be used.
Tail-call elimination / optimization is not a Scheme language-specific feature though.
Other popular languages have TCO to varying degrees, like C and C++ when using fairly standard compilers like MSVC, GCC, Clang, or ICC [1]. Destructors do get in the way though sometimes.
Java/JVM doesn't support TCO, but Kotlin and Clojure make do with special syntax to support tail-recursion (i.e. tailrec, recur).
Apparently JavaScriptCore supports TCO for JavaScript [2].
The book makes it sound like TCE is language-specific, but since that book was published, it's spread to many other mainstream languages too.
I don't think that's the point, as conversion in both directions is near trivial. It is a straightforward mechanical process, it may not always be easy or simple but it's more likely tedious than hard or complex.
More importantly, in the listed languages (excepting a handful of compiler optimization options) the semantics of procedure calls are different than Scheme's semantics for procedure calls. So if you, in C, convert a for loop into a tail recursive procedure you have changed the behavior of the program, not just its appearance (and same in reverse). In Scheme or another language with tail call elimination, then this conversion ought not actually change the behavior of your program (done in either direction). This also has the effect of removing the loop constructs as a necessity of the language. You can describe an efficient iterative process in Scheme with tail recursion, but you cannot describe it (in a general sense, same caveat for some optimization options) with tail recursion in the listed procedural languages and must use a special syntax element (their loop constructs) to achieve the same program semantics.
Transforming a program with tail calls to one without require to move all mutually recursive tail function to a common trampoline or something similar. Rewriting a single or a few tail functions into a loop/switch is easy, but it "impossible" to do for library API without global transformations.
(I could be wrong, I am not an expert in this, my basis are that an open set of function with a call in tail position can be used to describe arbitrary state machines (with the state being the arguments of the tail call and the rules the code of each function) that is open to new functions being added from anywhere. If you want to transform this in an iterative state machine all your functions need to be "registered" and "called" by the state machine.)
> Perhaps a better criticism is the mostly useless emphasis on immutable data structures. The example I like to bring up is how Haskell for a long time didn't have a readily-available hash table implementation for completely ideological reasons.
Can you link to some evidence that the reasons were completely ideological?
From Knuth’s The Art of Computer Programming. MIX is the earlier version, MMIX is the more recent (though now 20 or so years old) version. They are descriptions of a computer architecture and machine instructions used to explore algorithms in his books.
Knuth's TAOCP was originally written in an imaginary 60s-style CISC assembly called MIX (with some oddities like being decimal) but newer editions are in a RISC style one called MMIX (which Knuth claims is more practical but really isn't.)
Well, all I can say about that is that I read through the MMIX supplement and did a bunch of the exercises, and I know have enough knowledge to vaguely understand assembly.
It hasn't been massively useful to me in my professional life (I'm a data scientist), but it definitely has helped me to gain a deeper appreciation of how computing works.
> There's a reason MIT uses Python for its intro courses now, after all.
Yes, and IIRC, that reasons were, roughly: a) Python is more popular, b) Python has better robotics libraries, which is what kids coming to MIT care about these days. Notably, I don't recall the reasons they given having anything to do with giving students a good fundamental understanding.
But this is exactly my point. I think it's essentially a myth that Scheme/SICP are somehow more well-suited to providing a "good fundamental understanding." And Python is, as you point out, more practical and accessible.
While I have friends (and many colleagues) who graduated from MIT CS and are very competent engineers, I don't think MIT is the shining beacon of the best SE/CS graduates. Their program is certainly very good, but if someone asked me (for CS/SE specifically) about going to MIT or NU, I'd point them to NU. For almost everything else, it would, of course, be MIT.
Ah, thank you. I was thinking of Northwestern. To the point of comment you replied too. I do believe there is value in what can be more understood between learning via HTDP vs an easy to understand language, Data Structures, and Algorithms. From stand point of teaching CS to beginners maybe MIT is going for breath and Northeastern is going more for depth.
Then again what do I know, I didn’t go to university remotely in that realm of prestige.
There's a reason MIT uses Python for its intro courses now, after all.