I agree in thinking we should value consistency between
extension blocks. Extension blocks don’t define the same kind of scope as the others, but they are still scopey (in the broader intuitive sense of what a “scope” is):
- Declarations inside an
extension (x: T)block are put into the surrounding scope. This makes it not look like a new scope.
x: Tin such a declaration is accessible only inside the block, but not outside. This makes it look like a scope (in the same way as inline functions and method declarations scope their parameters).
It seems the status quo is that these blocks are scopey enough to need indentation (after all, something is needed to specify the scope of the
x: T), but not scopey enough to need extra markers, and indeed un-scopey enough to necessarily be differentiated from the other more true scopes.
I’m not sure if I see the need for that. It seems to introduce more complexity than the alternative of just expanding the intuitive notion of a scope.
(I feel like I read people suggesting this a long time ago, but maybe this problem would be avoided if it were disallowed to call extension methods directly by name. I personally find this idea appealing, though I’m sure it has downsides (but it’s off-topic and I don’t remember the other discussions on this). Anyway then it would behave a lot like an
class declaration, in that you’d need to reach into the (apparent) scope of an instance before you can access a method declared in the block. If this were true, I think there’d be a stronger case for regarding collective extensions as creating something which can be intuitively regarded as a “new scope.”)
Regardless, I’m pretty on board with the idea of having no markers at all (which has the benefit of being uniform) — it seems to have the most ergonomic benefits (esp. what was just pointed out by @bjornregnell). Unless people have tried this in practice and found that the “stray space” issue is frequent or causes insidious problems. I’m not sure I buy that it would be an issue unless people have had it happening in practice; I’ve rarely had these kinds of issues in languages where indentation is significant (and I’ve almost certainly spent more time wrangling braces and parens than indentation levels… though I do more Scala than Python). In such a language you don’t just leave stray spaces hanging around (and neither would you get away with it for long), precisely because they are significant.