I have discussed this some with @julien-truffaut on Twitter, but it is probably worth mentioning on this thread so it can be seen by those who care and I can explain more clearly than is possible in Tweets.
TL;DR - This change is bad for teaching novice programmers, but might be acceptable in Scala 3 if students are also using @main
.
I believe that this change causes problems for teaching Scala to novice programmers, especially under Scala 2. In my CS1 course, I generally cover recursion for iteration early. By early I mean about 4 weeks into the semester and before loops or other forms of iteration. (Sample schedule for a CS1 course for anyone interested: https://sites.google.com/a/trinity.edu/csci1320-f19/.) This course can involve students who have never programmed before. All they know is types, basic expressions, conditionals, and functions. That’s enough to start doing recursion, which is why I place it there. They don’t know annotations and in Scala 2 there is no reason to introduce annotations that early. Every language feature introduced has an additional cognitive load and the goal is understanding the logic, not knowing every language feature. Any extra syntax is a detrimental overhead that I want to avoid until it is really needed. I will note that little things like taking readInt and readLine out of Predef have already added to the syntactic cognitive load early on because they force a discussion on imports or using long, fully-specific names.
If this change were made, I’d either have to introduce annotations early or tell students to simply ignore the warning. Given that I work to get students to pay attention to warnings and not ignore them, the latter is clearly not ideal.
Even describing why they need to add the annotation is problematic. Students first learning about recursion after having only been programming a few weeks are not mentally equipped to try to take on what makes a function tail-recursive or not at the same time. So this is just going to make recursion even scarier than it normally is.
Scala 3 will likely change one aspect of this. In Scala 2, we use the scripting environment to allow students to write very simple programs with no overhead. It is quite possible that the introduction of top-level declarations and @main
will change how we do a lot of our coding in CS1. If we make the switch from scripts, which isn’t a given if Ammonite is integrated into the default tooling, then we might introduce annotations for that purpose and they wouldn’t be completely new when we hit recursion. In that situation, the idea of a short annotation like @rec
to suppress this warning seems like a reasonable solution. There is still the challenge that they aren’t equipped to understand tail-recursion, so to start off we’d probably have them put @rec on every recursive function.
As I mentioned on Twitter, my observation is that language evolution rarely favors the education of novices. Indeed, most changes to languages over time make things more complex in a way that is detrimental to teaching novices. It makes sense that the primary target of language changes is the developers who use the language daily to create things. However, I don’t think the impact on education should be ignored. As we have seen with both Java and Python, the truly broad adoption of a programming language is fueled by adoption in colleges. If every college taught Scala in some required course, the commonly heard argument that a project can’t use Scala because they can’t find developers who know it would go away.