4 ms·
> Always 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
by cabalamat 5y ago
> Always 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 might be easier to explain, but it also makes the code look ugly. Consider the expressions:
a := b + c*d
if e > f-g then ...
Here the * and - are more tighly bound than the + or >, and I'm using the whitespace to make that obvious.
- scns 5y agoBeauty lies in the eye of the beholder, ie aesthetics are subjective. For me, using proximity instead of parentheses to signify grouping would raise an eyebrow. I'd make an exception for cases of base*exponent, i think Python has it?
- cabalamat 5y ago> Beauty lies in the eye of the beholder, ie aesthetics are subjective. Then allow everyone to do things according to their own aesthetics.
- verdagon 5y agoI personally appreciate when languages have a consistent style. I think on the whole it helps readability more than it hurts. We're enforcing whitespace around infix operators in Vale, and it's working pretty well. It's also enabling us to use <> for generics with no ambiguity =)
- scns 5y agoSure. In math education i learned to signify grouping with parens and in this case i would favour function/consistency over form/typing efficiency.
- scns 5y agoNeed to reply to myself for correction since it is to late to edit. It should say base*exponent. I think other languages use base^exponent, which would be fine with me too.
- skrishnamurthi 5y agoBut if you write instead a := b+c * d you aren't going to get an error. You're just going to get awfully surprising behavior, because you may think you were expressing one precedence with the spaces but the language has its own mind and doesn't care. In contrast, Pyret doesn't bind anything more tightly than anything else. You parenthesize to make your intent clear. If your expression gets too large, you should consider breaking it down with names for the intermediates. That will improve its readability by others anyway.
- psykotic 5y agoA space-aware syntax can allow optional spacing around operators but make it an error if it does not respect the precedence hierarchy or is deemed inconsistent by other rules.
- zem 5y agoI believe fortress did that.
- cabalamat 5y agoYour argument is that a language shouldn't have a feature, because that feature can be misused in order to make the program hard to understand. But this is a bad argument, as it could apply to any language feature. E.g. I could write a program: def add(a, b): return a - b Here I've called it "add" but it does subtraction. By your argument, we should ban functions having meaningful names, as people could use a misleading one. > Pyret doesn't bind anything more tightly than anything else So all dyadic operators have the same precedence, like in Smalltalk? How horrible. > You parenthesize to make your intent clear. More likely I write my code in something other than Pyret, to make my intent clear.