7 ms·
It seems pretty bad to have kebab-case identifiers in a language that also has an infix subtraction operator -. The only languages I know that allow kebab-case
by cormacrelf 5y ago
It seems pretty bad to have kebab-case identifiers in a language that also has an infix subtraction operator -. The only languages I know that allow kebab-case idents are lisps, where subtraction is (- prefix notation). From the examples:
lam(actual): num-abs(actual - target) < delta end
This is a new, even worse kind of "whitespace significance" than indentation. Is it a function called `num-abs` or a variable `num` minus `abs(actual - target)`? I can't tell if the language would allow `actual-target` as subtraction.
- deleted 5y ago[deleted]
- nostrademons 5y agoDylan had kebab-case idents and infix operators. It worked okay because you have to separate infix operators with a space anyway; omitting it is a syntax error. In practice I doubt this would trip me up because every coding standard I've worked with has mandated spaces around infix operators. I suppose it might be a lot more confusing if you're used to coding standards that allow you to omit them, but my understanding is that's a minority.
- cormacrelf 5y agoMaybe it would be okay with syntax highlighting and a careerful of code formatting muscle memory, but how would that fare in an educational context? > "Pyret is a programming language designed to serve as an outstanding choice for programming education"
- chowells 5y agoOnly having one correct way to do something with very simple rules (always put whitespace around operators) is easy for students. It's when the rules are complicated with exceptions and multiple correct ways that things get hard to learn.
- skrishnamurthi 5y agoIt's been working great, actually. https://news.ycombinator.com/item?id=28265117 https://news.ycombinator.com/item?id=28265117
- justinpombrio 5y agoSame thing in Pyret, it's a syntax error to not put a space around infix operators.
- DonaldPShimoda 5y agoAlways requiring whitespace around infix operators is, in my opinion, easier to explain to people than "you can do whatever you want with the whitespace." It's consistent and regular. I don't think it's as much of an issue as you're making it out. Pyret is the result of decades of research in computer science education, helmed by Shriram Krishnamurthi, who was one of the original members of the Racket project (itself a language designed for CS education in the '90s, a descendant of Scheme with kebab case and prefix notation). The full list of authors of Pyret is lengthy, but includes a number of well-established researchers in the PL and CSed communities. Knowing who they are, I would happily assume that they spent plenty of time debating this exact issue of mixing kebab case with infix subtraction, and either decided the benefits were worth the cost or else decided that the cost was practically nonexistent. In any case, I trust their decisions better than those of someone who glanced at the website only long enough to inform a condescending (and highly superficial) comment on Hacker News.
- Ericson2314 5y agoYes not requiring spaces around infix operators is terrible even when there is no ambiguity. Frankly, everything about programs-as-text is terrible for beginners, but this softens the blow.
- chakkepolja 5y agoI disagree that programs-as-text is bad idea for beginers. Anyone with a bit of abstract thinking can understand program as text just like how they can understand a multi step mathematical operation.
- Ericson2314 5y agoI'm no expert on education, but having been a TA and helped out a few people since, I repeatedly see text getting in the way of everything else. Beginners often find both the things you are saying some what hard. First, note that there is reading vs editing. Perhaps in grade school people learn to parse large expressions (though I find that people generally are not prepared well, because grade school expressions are too small). But editing code and keeping track of what changes you made --- essential to debug your first programs --- is much more new to people who are used to just rewriting a few short algebra expresions with pencils. It's then, when the beginner is most mentally taxed, that the syntax errors creep in --- and further interrupt their thinking process. Hopefully we can agree the second challenge is completely fundamental to the field, while the first however is just an artifact of the way things are implemented today. Well, based on the above scenario and others I repeated see the cognitive burden of the first interrupting the second, and so student waste effort and loose focus over "easy stupid text syntax", and therefore long delay mastery of trees, term rewriting and substitution in particular, etc.
- darrenf 5y agoRaku has kebab-case as well as infix subtraction. Sigils disambiguate when the operands are variables ($foo-$bar), and callables must be made explicit: sub foo-bar { 10 } sub bar-foo { 7 } say foo-bar-bar-foo; # Undeclared routine error say foo-bar()-bar-foo; # 3
- lizmat 5y agoOr just do: say foo-bar - bar-foo; which would improve readability as well!
- runarberg 5y agoIn mathup[1] I actually use whitespace around infix operators to group expressions. E.g. `1 + 2/3 + 4` is not the same as `1+2 / 3+4`. I find this leads to a much cleaner expressions. When you are designing your own language, you can make these choices. The author of Pyret obviously thought that clearly named identifiers were worth it. 1. https://runarberg.github.io/mathup/ https://runarberg.github.io/mathup/
- cabalamat 5y ago> It seems pretty bad to have kebab-case identifiers in a language that also has an infix subtraction operator -. Indeed. What's wrong with using _ in identifiers?
- scns 5y ago> Indeed. What's wrong with using _ in identifiers? Nothing wrong with it. It is usually easier to type '-' though. Use in when naming scripts and files for the same reason. Ergonomics matter IMHO.