allow compound expressions to be obvious
We tried various approaches to making clear how nested expressions are organized, however none of them are currently shipped. We tried colors and shading in an old version, but it was very unclear. I think those might come back though at a later date when we have better onboarding.
For now the agreed upon solution is to use parens. There's a design somewhere, and lots of code already written.
The existing code:
- https://github.com/darklang/dark/tree/julian/arrow-key-selection
- https://github.com/darklang/dark/compare/main...julian/visual-precedence
- https://github.com/darklang/dark/compare/main...julian/visual-precedence2
- https://github.com/darklang/dark/compare/main...julian/visual-precedence3
I think this adds parens everywhere. We would actually like to only add parens where strictly necessary. We also want keystrokes to move parens as users can't actually add and delete parens specifically.
From https://github.com/darklang/dark/issues/2806:
Say I want to do multiple calculations or some sort of compound statement like:
if List::length records_found > 1 ... This won't work, because it's resolving it to records_found > 1 (true | false) -> List::length
.
This can rectified by using the pipe operator in the right place in the right way, but overall I'd say some compound expressions one would trivially write in most languages don't do the right thing on your first try and you need to rewrite them.
Not a blocker, but it adds friction, as it takes a bit of work to get what you want sometimes. Maybe this is a "won't fix" and users will do the right thing once they learn, but especially at the beginning is frustrating.
The trouble is that the learning path is long (feedback cycle isn't short in these cases). There's no syntax error so you need to dive into the functions to understand. If the editor gave hints as to the order of operations, that would help a lot.
IIUC the order of operations isn't supported?
i.e the code in the screenshot evaluates as 1+(2*(3+4)) rather than (1+(2*3))+4 as in most languages?
It would be helpful to have both for familiarity but also I think for ergonomics.
Not applicable to darklang-next.