About collective extension methods, the situation is somewhat different.
collective extension methods do not define a local scope, where as with + <indent> means “local scope” everywhere else.
we certainly do want to allow a single extension method without needing with. I.e.
extension (x: T) def append (y: T): T = ...
extension (x: T)
def prepend (y: T): T = ...
should both be accepted. So then when we combine the two to a single collective extension, would we require a with or allow one? Requiring it is just as bad as braces in that I have to add something to the other scope if I have more than one thing in the inner scope. Allowing it just gives two ways to do the same thing.
That’s why I think it’s better not to use with. But there can be a nice error message that explains the matter if somebody writes it.
My impression was that opinions of .. were much more polarized than for the other alternatives. Some people liked it, but the people who didn’t like it really didn’t like it.
Yes. So in that analogy, with makes sense. Or rather, braces don’t really make sense here since they pretend to introduce a local scope where there is none. But it’s the only thing we have if we do not want to rely on indentation. I think it’s OK. Code using extension methods is always new code, so people will tend to rely on indentation, even if they don’t use braces elsewhere.
I guess that if you don’t allow ‘with’ now for collective extension statements, then it doesn’t close the door to allowing it in future if, after more experience and feedback, that was deemed to make the language more regular.
For what it’s worth, having followed this conversation for a long time, my personal preference is definitely with.
And, for consistency, I think it should be required for multi-line enstensions.
Keep in mind that IDEs can choose how to display keywords, so for those who find it cumbersome/distracting to watch, I think there’ll be ample opportunity for IDE configuration.
Is it possible to have the language be non-regular :, with, etc., while applying auto-fixes in IDEs for common mistakes (like text editors can automatically capitalize the first character after a period)?
For example, if someone writes while true: then it will be automatically converted to while true do. With such a feature I think the irregularity problems are mitigated significantly.
Stylistically, I think single-method extensions should be in one line (at least the definition and = operator, if not the actual implementation), and think that’s enough of a visual cue to warrant mandating with for collective extensions.
The use of the with keyword is a good visual cue that multiple methods are expected:
extension (x: T) with
def prepend (y: T): T = ...
Indeed, IDEs will probably reformat and delete with as a suggestion, if you use collective extensions with a single method; and certainly I would like such matters of syntactic consistency to be handled by scalafmt at some later date.
The purpose of : (and now with) in class/object/trait is to disambiguate in case of stray whitespaces. In extensions you don’t have the problem, so… against with in extensions.
People who liked : generally didn’t like ... But although I was an early proponent of it, I think other changes have made it unnecessary. I do like .. better than :, but I think the most important consideration is this one:
Hence, with wins, because it’s consistent with the pre-existing idea of with. .. could be self-consistent, but it’s an entirely new thing: a “begin significant indentation mark”, as opposed to “optional braces”. The logic is “add this new thing to get a new syntax” rather than merely “you can leave off braces when they’re superfluous”.
.. might make a comeback later. Remember one of the proposed extensions after 3.0 is to allow optional braces after operators, and to have an operator for function application. So far we have “left pipe” <| as the leading candidate for that apply operator, but .. could be an alternative.
Fair enough to select with over : if you prioritize regularity over ergonomics + esthetics in this case. I can live with that, and learners should be ok (even if with is wordy).
Now I need to get hold of M4 asap to re-program my fingers and learn how to love this new syntax .
Competing requirements need to be balanced and trade-offs are seldom perfect…
Thanks for your prestige-less attitude in the quest for finding good solutions to conflicting goals!