Live data from Hacker News

Why learn Racket? A student's perspective

micahcantor.com

21–30 of 55 posts

Re: Why learn Racket? A student's perspective

#21
post #5

It is interesting that recursion is still considered to be so novel on blogs and forums. From what I have seen of current CS curriculums, recursion is usually taught in the first year immediately after introductory CS. It is almost impossible not to use recursion when dealing with tree structures (using an explicit stack takes a lot more code, most coding interviews don't ask for an iterative solution unless absolute…

After 20 years of software development in a variety of languages and projects, I've come to the opinion that recursion really should be relegated to being a novelty. Few languages offer tail-call optimization. If we look at popularity of languages, then the likelihood any particular solution is going to end up in such a language is vanishingly small. For the remaining languages, fitting into the stack depth is easy t…

>it's not true that using an explicit stack takes "a lot more code" (it's like, three extra lines)

I don't know if you mean that literally or just as a rhetorical exaggeration, but it's absolutely false. The first example that came to mind is Quick Sort, search for the iterative version of the algorithm and compare it with the traditional recursive version, easily a 10x factor. The increase in complexity isn't linear in code size either, the code that replaces the simple recursive calls is full to the brim with loops, state and conditional mutations, i.e. Free Bugs, yummy yummy.

>Few languages offer tail-call optimization.

I was hacking on a (non-tail-) recursive solution to a problem a couple of days ago in a repl.it container, and a buggy solution exploded after consuming 15000 stack frames. The repl had 1024 MB RAM as a max limit. The point is, absence of tail cail optimization is rarely if ever a real problem in a language that has loops, its a big, big problem if the language doesn't have loops, but as long as the language has loops and relegates recursion to the "Side Role" its so good at, its just not that of a big deal.

This also fails to consider why recursion is such an attractive algorithmic construct, tail recursion is absolutely trivial, it can be transformed to loops mechanically, it rarely adds anything of value to the readability and expressiveness of code.

The vast majority of interesting and useful uses of recursion is the non-tail-recursive variety, where you have to use a stack anyway, at this point the whole argument reduces to whether you can maintain a stack more efficiently and readably than the machine, which in my view ends in you losing to the machine 9 times out of 10.

>And frankly, lots of programmers don't have a good handle on it, even the ones who studied CS in college, so asking them to maintain recursive code written by someone else usually ends pretty poorly.

If those programmers were asked to instead maintain the explicitly iterative version of the code, I bet it would end even more badly. Recursion, after the initial cost of watching a few tutorials, is less confusing than loops. It's about hiding state, how on earth is explicitly managing all that state yourself better? This is like saying that "2+46/(3+1)4" is best calculated as a long sequence of 2-argument assembly instructions because its more explicit that way, its more explicit, true, but - paradoxically - way more obscure.

>Many safety regulations covering vehicles from cars to spacecraft explicitly ban recursion because of these issues.

Embedded Systems safety regulations and conventions ban a lot of things, recursion is not special at all. One thing is dynamic allocation, another thing is multiple returns out of a subroutine. Are you ready to give up those 2 things?

It makes no sense to take the conventions of a very specific and idiosyncratic industry like that and try to derive from it universal rules that should govern all software.

Re: Why learn Racket? A student's perspective

#22
post #9

One aspect of Racket that I would expect to appeal to students, but which does not appear in this blog post, is its cross-platform (and widget-native!) GUI framework: https://docs.racket-lang.org/gui/ The first "side-project" I ever did was a tic-tac-toe program in Java AWT during my first year of programming in high school. AWT wasn't even part of the curriculum, it was just what I gravitated towards as a 13-year-ol…

I tried (not very hard) to see some screenshots but failed. Do you know of a gallery with example code?

Re: Why learn Racket? A student's perspective

#23
post #9

One aspect of Racket that I would expect to appeal to students, but which does not appear in this blog post, is its cross-platform (and widget-native!) GUI framework: https://docs.racket-lang.org/gui/ The first "side-project" I ever did was a tic-tac-toe program in Java AWT during my first year of programming in high school. AWT wasn't even part of the curriculum, it was just what I gravitated towards as a 13-year-ol…

I love racket/gui and recently shipped a product using it for a diagnostics tool! The killer features are as you said that it uses native widgets, but also that it doesn't require any sort of dynamic linking to heavyweight C libraries (other than the ones Racket itself comes with) and that you can easily compile it in a redistributable form with basically no dependencies for all platforms. I can't recommend it enough.

Re: Why learn Racket? A student's perspective

#24
Nice write up.

You mention SICP, but I’m wondering if you are using HTDP http://htdp.org/ ?

I’ve always been struck by the vision the authors state in the preface;

> everyone can design programs

>

> and

>

> everyone can experience the satisfaction that comes with creative design.

>

> Indeed, we go even further and argue that program design—but not programming—deserves the same role in a liberal-arts education as mathematics and language skills.

>

> A student of design who never touches a program again will still pick up universally useful problem-solving skills, experience a deeply creative activity, and learn to appreciate a new form of aesthetic.

I’m not a good programmer - I’m not even a average one, but the book and learning Racket has made me better.

Re: Why learn Racket? A student's perspective

#25
post #22
post #9

One aspect of Racket that I would expect to appeal to students, but which does not appear in this blog post, is its cross-platform (and widget-native!) GUI framework: https://docs.racket-lang.org/gui/ The first "side-project" I ever did was a tic-tac-toe program in Java AWT during my first year of programming in high school. AWT wasn't even part of the curriculum, it was just what I gravitated towards as a 13-year-ol…

I tried (not very hard) to see some screenshots but failed. Do you know of a gallery with example code?

https://alex-hhh.github.io/2021/09/screenshots.html is a nice gallery of one person's apps.

Re: Why learn Racket? A student's perspective

#26

Earlier quoted context omitted.

After 20 years of software development in a variety of languages and projects, I've come to the opinion that recursion really should be relegated to being a novelty. Few languages offer tail-call optimization. If we look at popularity of languages, then the likelihood any particular solution is going to end up in such a language is vanishingly small. For the remaining languages, fitting into the stack depth is easy t…

>it's not true that using an explicit stack takes "a lot more code" (it's like, three extra lines) I don't know if you mean that literally or just as a rhetorical exaggeration, but it's absolutely false. The first example that came to mind is Quick Sort, search for the iterative version of the algorithm and compare it with the traditional recursive version, easily a 10x factor. The increase in complexity isn't linear…

> Embedded Systems safety regulations and conventions ban a lot of things, recursion is not special at all. One thing is dynamic allocation, another thing is multiple returns out of a subroutine. Are you ready to give up those 2 things?

Indeed. On one automotive project, we could not use C++ strings, due to the hidden dynamic allocation.

Re: Why learn Racket? A student's perspective

#27
post #9

One aspect of Racket that I would expect to appeal to students, but which does not appear in this blog post, is its cross-platform (and widget-native!) GUI framework: https://docs.racket-lang.org/gui/ The first "side-project" I ever did was a tic-tac-toe program in Java AWT during my first year of programming in high school. AWT wasn't even part of the curriculum, it was just what I gravitated towards as a 13-year-ol…

Can confirm, I very quickly picked up Swing when I started Java programming just because I wanted to make little games and cellular automata. Before that, we'd had Haskell forced upon us and the GUI stuff had been very difficult for a beginner to pick up.

Re: Why learn Racket? A student's perspective

#28
post #5

It is interesting that recursion is still considered to be so novel on blogs and forums. From what I have seen of current CS curriculums, recursion is usually taught in the first year immediately after introductory CS. It is almost impossible not to use recursion when dealing with tree structures (using an explicit stack takes a lot more code, most coding interviews don't ask for an iterative solution unless absolute…

After 20 years of software development in a variety of languages and projects, I've come to the opinion that recursion really should be relegated to being a novelty. Few languages offer tail-call optimization. If we look at popularity of languages, then the likelihood any particular solution is going to end up in such a language is vanishingly small. For the remaining languages, fitting into the stack depth is easy t…

In web/gui programming it’s a good fit. Your data is a tree that you render on a screen, so it’s by default relatively shallow and not very big. It’s never going to blow the stack and the benefit of using recursion, closures and functional composition is you get clear, dense code and tend to make fatter data structures and more general code.

Re: Why learn Racket? A student's perspective

#29
I think it's important to show students how to think about languages as a set of tools. OP's post stabs at this quite well, with the "Languages are less important than you think" section, and as someone who has already jumped across 5 or 6 languages over the course of his just over 10 year pro career this definitely rings true.

I think it's fine to bag on languages like Racket, but a good engineer should be able to hop across any language and at least be able to read and understand what they're doing.

Re: Why learn Racket? A student's perspective

#30
post #28

Earlier quoted context omitted.

After 20 years of software development in a variety of languages and projects, I've come to the opinion that recursion really should be relegated to being a novelty. Few languages offer tail-call optimization. If we look at popularity of languages, then the likelihood any particular solution is going to end up in such a language is vanishingly small. For the remaining languages, fitting into the stack depth is easy t…

In web/gui programming it’s a good fit. Your data is a tree that you render on a screen, so it’s by default relatively shallow and not very big. It’s never going to blow the stack and the benefit of using recursion, closures and functional composition is you get clear, dense code and tend to make fatter data structures and more general code.

Yep. Same thing with filesystems. Since they're meant for humans to traverse, finding a directory structure with deep enough nesting to blow up the process stack or hit a runtime recursion limit is sufficiently rare that you shouldn't even worry about it. I'm sure there are plenty of other examples where the practical limit you'll see in much lower than what an address space stack can fit. We had a task at an old job to create dependency and build trees of every service in the overall project and then operate on them. Even assuming a language runtime with a very small limit, say Python with its 997 or so default maximum simultaneous stack frames, we didn't have 997 individual services, so even the maximally malicious dependency tree couldn't have exceeded that limit.
Post reply on HN