4 ms·
The distinction in ALGOL, Pascal etc. is useless. But if you change your definitions such that expressions always evaluate to a single value and do not have an
by programmer_dude 3y ago
The distinction in ALGOL, Pascal etc. is useless.
But if you change your definitions such that expressions always evaluate to a single value and do not have any side effects while statements produce some kind of side effect (and may or may not yield a value), the distinction becomes important.
Especially if you believe side-effects need special handling (i.e. you are a functional programmer).
- Joker_vD 3y agoIt's been done in some Pascal descendants: functions were required to be pure but procedures were allowed to mutate global state. Some even went as far as to remove functions altogether (with quite unpalatable results).
- colonwqbang 3y agoThe only popular language I can think of that requires side effects to be declared is Haskell. Which doesn't have a distinction between statements and expressions. Are there any good examples of languages that have it, where it isn't "useless"?
- epgui 3y agopython, javascript, pretty much any language that is popular. I believe everything in Haskell is an expression, even the do notation, no? But I think the argument being advanced is that the distinction between statements and expressions is fundamentally unnecessary. I don’t really know of any good argument in favour of them: I tend to think lisps have the perfect and simplest possible syntax.
- gumby 3y agoYes, that is indeed the point I was making. And yes, I’m a lisp programmer.
- colonwqbang 3y agoPython, Lisp and Javascript don't require functions with side effects to be declared in a particular way. Haskell does.
- epgui 3y agoThe question was about expressions vs statements, not about the IO type.
- colonwqbang 3y agoI was replying to the point programmer_dude made in his comment.