On 16/01/2020 18:14, Random832 wrote:
On Tue, Jan 14, 2020, at 18:15, David Mertz wrote:
For what it's worth, after 20+ years of using Python, forgetting the colon for blocks remains the most common error I make by a fairly wide margin. Of course, once I see the error message—even being not all that descriptive of the real issue—I immediately know what to fix too.
What if the colon were made optional, with an eye to perhaps eventually no longer using it as the preferred style for new code?
We had a post a while ago about the possibility of using the lack of a colon as an implicit line continuation (like with parentheses, e.g. "if a\nand b:", and this was (reasonably) rejected. But if a line beginning as a compound statement and ending without a colon is *never* going to have a valid meaning as something else... what's the point of the colon, otherwise? Seems like just grit on the screen.
It's useful for when you are reading the code later. You see the colon and think "oh yeah, there will be a suite next" even if the "if" or "while" or whatever that begins the compound statement is several lines up. Especially if you have a multi-line "if", since you won't have the visual cue from the left-hand side. if (first_of_many_tests() and second_of_many_tests() and and_so_on() and last_of_many_tests()): do_something_muttley() -- Rhodri James *-* Kynesim Ltd