3 ms·
It only makes more sense when you do look at the background, so thanks for the link. They're lisp folks. They use kebab-case. I completely get it. It may be the
by cormacrelf 5y ago
It only makes more sense when you do look at the background, so thanks for the link. They're lisp folks. They use kebab-case. I completely get it. It may be the product of decades of research, but it is also the product of default choices and comfort for the people who wrote it. ALL programs have an element of this: I write Rust and you can tell without looking when some tool is written in it -- TOML config? Apache-2.0/MIT dual-licensed? Few such decisions have no downsides, and yet exceptions are rare.
It takes a lot to make a choice for reasons other than your own familiarity. From the linked thread, they clearly agonized over this. Apparently they talked themselves down from the usual Lisp ultra-permissiveness on idents, so good on them -- but it was still explicitly a compromise between their comfort and the aims of the project.
There is an obvious and very good reason why the number of languages that do this can be counted on one hand. The authors know that. It is a problem they decided to accept because it was the default for them, and they "just couldn't give up on how pleasing hyphens in identifiers are to the eye and the shift-finger", and then mitigated it via other whitespace changes. They were content when "Anecdotally, no one in our courses ha[d] complained". I disagree with it. I find it really hard to read. I guess I am used to other languages, but so is everyone who has dabbled in python, likely writing primarily numeric code for their stats/bio/physics courses.
Consider me a student reporting it as a problem. Consider the 2013 thread a student reporting it as a problem as well. How about that?
I'll finish with a quote from Krishnamurthi himself: "Saying 'add spaces around binops' is easy to learn, recognize, and implement."
Does this not speak for itself?
fun subtract(a, b):
a-b
end
>>> The identifier a-b is unbound: definitions://:3:2-3:5
4 | a-b
It is used but not previously defined.
Edit: I dug up an old thread from the guy @estebank who makes all the amazing Rust error messages, responding to a paper of Krishnamurthi's that argues, true to form, that you shouldn't ever actually "Say 'add spaces around binops'" (https://twitter.com/ekuber/status/1140791186858266624 https://twitter.com/ekuber/status/1140791186858266624). The paper itself is an interesting read, particularly the interviews where beginners don't have the vocabulary to decipher error messages. But I think Esteban is right.
- scns 5y agoThat could be fixed by checking the identifier for valid operators and offer: "Did you mean a - b?"
- cormacrelf 5y agoIt seems obvious now, but that's not low hanging fruit, and even when you think to do it, it's not easy to do. It took and is still taking real ingenuity and hard work from Rust folks to do. Their syntax trees are insane, they carry so much information around to make these kinds of messages possible. Every source of ambiguity in intent adds to the problem. Making binops work only with whitespace is an easy change to the parser; telling people as you look over their shoulder is also easy. Producing this error message when it is valid syntax and means something else is a different beast entirely. For a general purpose language I just wouldn't recommend it when you have an easy choice available to avoid the ambiguity in intent. It will save so much work if you aspire to have better errors.
- skrishnamurthi 5y agoI understand where you're coming from. Feedback and engagement noted and appreciated. But I stand by my remarks from 2013 in 2021. I've now had well over 1000 students go through Pyret (in addition to tens of thousands elsewhere). We've also spent hours and hours literally watching new learners work with the language. I can assure you that of the many, many, many issues that have percolated up to us, spaces-around-binops has literally not a single time been one. If anything, when people write that and we say "just put spaces around the `-`", the response is, "Oh, okay", and people move on. So, we feel very good about this decision. And I, personally, actually really like how it makes code read.
- cormacrelf 5y agoHey, thanks for the reply. The discussion has been centred on explaining why you have to type the spaces, but I never really cared about that -- my problem was with reading. That's my fault, the usual complaint about whitespace sensitivity is about having to type it, and this is different. I'm talking mixed kebab-idents and really any math operators in the same expression. Unrealistic example but: `(n-1 + n-2) / (n-1 - n-2)`. We may naturally differ on that through familiarity, but it really does get my brain stuck. It doesn't surprise me at all that the mechanics of adding spaces were so easy to learn, but I'm not totally convinced you would have received explicit feedback on readability from students who don't have much to compare to. On the flipside, if you don't get feedback on reading tricky numeric expressions, then they don't care, it doesn't come up for beginners as they're not optimising sqrt routines, and it doesn't matter to a language made for them. I think that's the end of the road. On the binops, it may be that forcing whitespace around them is a good idea even for a language without kebab-idents, and perhaps the risk you took there was worth it to find that out. I could get around a world in which C's `a & b` and `&ptr` were completely incompatible. (I'm sure you could find a CVE or two for that one.) Heck, every code formatter out there does it. Compared to some suggestions around here and apparently back in 2013 as well to ditch BODMAS, the one bit of math that everyone on the planet learns in school, in favour of whitespace-sensitive precedence... goodness me. Give me forced spaces around binops any day.
- kazinator 5y ago> Does this not speak for itself? If not, this does: $ cp a-b c-d # copy a-b file to c-d $ expr 1-1 1-1 $ expr 1 - 1 0 You already know some language with whitespace delimiting such as, oh, the shell.