9 ms·
One of the best things about Turbo Pascal was having to declare all variables upfront at the beginning of functions. I really don't know why languages like C,
by fzeindl 3y ago
One of the best things about Turbo Pascal was having to declare all variables upfront at the beginning of functions.
I really don't know why languages like C, Java or JavaScript started to allow variable definitions everywhere. Needing to declare variables first leads to much cleaner functions.
- blt 3y agoStrongly disagree. I want to have variables that only exist within an `if` block. That is something C99 got right. But Python's leaky scopes are even worse than up-front declarations.
- trealira 3y ago> I want to have variables that only exist within an `if` block. That is something C99 got right. C89 allowed you to declare variables at the top of any block, not just functions, so you could declare variables that only exist within in if block. For example: if (flag) { int c; while ((c = getchar()) != EOF) { /* code */ } }
- fzeindl 3y agoYes, those are useful, but I think the requirement to declare upfront in general prevents function that are too long. When you start to have a screen height full of variable-declaration, you start thinking: "Maybe I should refactor this." Inline variables conceal that a bit.