fewerBraces: allow partial function arguments without :
#17732
Replies: 6 comments
-
I's a difficult tradeoff between conciseness and consistency. I would leave it out of the first version of fewerBraces. We can always add it later. |
Beta Was this translation helpful? Give feedback.
-
If you care for a random personal anecdote … I'm teaching my son and my nephew Python, both teens, and the syntax has been a big roadblock. I also don't have teaching experience, so it caught me off guard, especially since I thought Python was easy to understand for beginners. A point of confusion, besides the perennial misunderstanding of the evaluation model, is the syntax for code blocks. They have been confused about where blocks of code should be. And having a consistent rule like “a block of code must follow a I think that consistency helps when learning languages, I think that's because it helps us to recognize patterns that we can later reuse in other instances, which is why exceptions to rules are bad for the learning process. And the ideal would be to see how students struggle to learn a syntax before adopting it. YMMV. |
Beta Was this translation helpful? Give feedback.
-
@alexandru It's not that this has not been studied. See for instance http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html. But yes, YMMV, I don't think it's possible to get consensus on this. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the link by Chris Okasaki. Here I was thinking about the issue at hand: having cases in which Similar cases already exist. For example, in a Based on this example, one could also make the case that the syntax for anonymous partial function is similar. Each of the cases introduces a scope, and this is different from a block of code passed as a parameter to a normal function. However, one can also make the case that partial functions are confusing as a concept, and that missing the // (1)
list.map: x =>
x match:
case Odd => 1
case Even => 0
// (2) can be refactored to
list.map:
case Odd => 1
case Even => 0
// (3) versus
list.map
case Odd => 1
case Even => 0 Requiring sample no. 3 and banning sample 2 would be confusing. So, this issue talks about having |
Beta Was this translation helpful? Give feedback.
-
Yes, that's a good point. I also think we should avoid making |
Beta Was this translation helpful? Give feedback.
-
I agree that making colon optional would introduce an unnecessary variation. When teaching the rules of single-parameter arguments, this would even be viewed as an irregularity, in the eyes of students I think. So I'd vote against this. |
Beta Was this translation helpful? Give feedback.
-
It is quite common to pass anonymous partial function to higher-order functions (whether they take a
PartialFunction
or a regularFunction1
). In that case, there is no explicit parameter to the lambda, which requires the use of:
for thefewerBraces
mechanism to kick in:I suggest that we infer the
:
in that situation, so that we could write instead:Currently, the above fails to parse:
Beta Was this translation helpful? Give feedback.
All reactions