3 ms·
Strongly 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 tha
by blt 3y ago
Strongly 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.