2 ms·
> The defining characteristic of a programming "statement" is that it can perform some action Given a declaration "statement" such as: int x; What is th
by 9rx 1y ago
> The defining characteristic of a programming "statement" is that it can perform some action
Given a declaration "statement" such as:
int x;
What is the expected action? Memory allocation... I guess? Does any compiler implementation actually do that? I believe, in the age of type systems being all the rage, one would simply see that as a type constraint, not as a command to act upon.
Expressing an idea (the values used henceforth should be integers) seems more applicable, no?
- lmm 1y ago> Given a declaration "statement" such as: > int x; > What is the expected action? In a language that requires you to declare variables before you use them, it clearly does something - you couldn't do "x = 5;" before, and now you can. If you're trying to understand the program operationally (and if you're not then why are you thinking about statements?) it means something like "create a variable called x", even if the implementation of that is a no-op at the machine code level. > I believe, in the age of type systems being all the rage, one would simply see that as a type constraint, not as a command to act upon. But in that case by definition one would not be seeing it as a statement! Honestly to me it doesn't really matter whether "int x;" is an expression, a statement, or some mysterious third thing (in the same way that e.g. forward declaring a function isn't a statement or an expression). When we're talking about the distinction between statements and expressions we're talking primarily about statements like "x = x + 1;", which really can't be understood as a statement in the everyday English sense. > Memory allocation... I guess? Does any compiler implementation actually do that? Toy/research or embedded compilers do yes.
- kragen 1y agoThat looks like C. In C, declarations aren't statements: https://en.cppreference.com/w/c/language/statements.html https://en.cppreference.com/w/c/language/statements.html
- 9rx 1y agoIt's Hnlang, where declarations are statements. But perhaps the earlier comment was about C specifically? I admittedly missed it, if so.
- kragen 1y agoIn most programming languages, declarations aren't statements, because they don't have any effect at runtime. Maybe you can find some exceptions. Like in BASIC the DIM statement is sort of a declaration, but it does have a runtime effect; it changes the dimensions of an array. (Though some would say that in BASIC no statement is bright.)
- 9rx 1y ago> Maybe you can find some exceptions. Including Ken Thompson's very own[1]. Fair enough that in the olden days there was a clearer distinction made, but even the man who (co-)created C changed his mind on that later because that is how the term has evolved. Now, in normal conversation, if you call `int x;` a statement, nobody is going to struggle to understand what you mean. Are you still living in the 1970s? If so, I admittedly missed that. My assumption was that this discussion is taking place in 2025 with the words of its time. [1] https://go.dev/ref/spec#Statements https://go.dev/ref/spec#Statements
- kragen 1y agoYour example isn't syntactically valid in Golang. Declarations are statements in Rust too, but not Python, TypeScript, or ECMAScript (which to my surprise does have a "Declaration" nonterminal in its grammar). C++, Java, and C# are half-and-half; in their grammars, some kinds of declarations (in particular, like `int x;`) can be statements, but others cannot. The distinction hasn't gotten any less clear, but it was already easy to find people in the 01970s who didn't know the difference. You're one of today's lucky ten thousand! I do frequently encounter people who are failing to solve their problems because they don't know things that were already known in the 01970s, so I think it's worthwhile to study 01970s informatics. Mostly, though, I think it's worth studying the zeitgeist of the 01970s in informatics: some people were making rapid progress on solving fundamental problems, partly because they didn't have certain self-defeating attitudes that are popular in informatics today, such as not caring whether what they say is true or false.