Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Valid Forth syntax:

    6 8 7 5 4 + * - + .
     -49 ok
 
Tell me that's easier to read than

    8+6-(4+5)*7
Parenthesis can make things harder to understand if poorly used. RPN can make things harder to understand if poorly used.

The reverse is also true for both. Forth does not prevent bad code.



Most people find uppercase text harder to read than lowercase. Research has shown this to be the case because people are more familiar with lowercase (people more exposed to more uppercase will eventually find it easier to read).

Because of this effect you cannot trust your own sense of what is inherently easier to read, it will be biased by experience.


>you cannot trust your own sense of what is inherently easier to read, it will be biased by experience.

Funny you should say that, when basically every person in the world going through a basic mathematics curriculum will be experienced with infix notation, and completely unfamiliar with RPN.

True, maybe you for some reason have more experience with RPN. So use Forth.

But there is a clearly superior notation when you're talking about "which one will most people understand." HP calculators notwithstanding.


I find it amusing that arithmetics is always invoked in any discussion about nested expressions syntax, despite being largely unimportant in most of the typical code scenarios.


I used an arithmetic example, but since everything in Forth is just "words", it all reads the same.


And it is much closer to plain English than all that too nested languages. And most of the code must be like English, not like arithmetic expressions.


Plain English is hardly succinct and precise either.

Repeat after me: "There is no silver bullet." There, that wasn't so hard.


> Plain English is hardly succinct and precise either.

But so far it's the best form of communication we've got.


Honestly, how often do you need any deeply nested arithmetic expressions in your code? I very rarely use anything beyond an increment by one. Any time you are invoking nested logic you are already summoning a complexity problem. Luckily, it can be avoided in most of the real world cases.


How often? Quite. "Take these two points and extrapolate." "Solve this quadratic equation."

Whether you need more complicated arithmetic expressions depends entirely on what field you are working in. I would not call `8+6-(4+5)*7` complicated by any means.


Is it really that often? More than 10% of lines of code containing nested arithmetic expressions? Sorry, I find it hard to believe.


If 10% is your threshold of "often", then no. Arithmetic expressions do show up often enough in code that I work on that they should be immediately readable.


Nobody is stopping you from keeping them as readable as you like. The question here is in readability of the remaining 90% of the code, and this is exactly where nested expressions are evil and must be flattened.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: