"Hi everyone,
Coming from a background in languages with explicit block structures (like GFA Basic or Ada), I’ve observed a recurring issue in Python when dealing with large modules (1000+ lines).
The Issue: Outdent Ambiguity
In Python, a backward tab (outdent) is functionally overloaded.
It can signify the end of the current block, or multiple blocks simultaneously.
While visually clean, this relies entirely on the programmer’s manual spacing.
In complex nested structures, a single accidental backspace can shift the logic of the entire program without triggering a syntax error. This is a silent killer of code integrity.
The Proposal
I would like to discuss the possibility of an (optional) strict mode or a linter standard where blocks must be terminated with a dedicated marker (e.g., an # end comment or a keyword).
The rule would be simple:
-
Every indentation level must remain constant until a formal ‘end’ instruction is met.
-
The ‘end’ instruction must match the opening statement (e.g.,
# end iffor anifblock). -
If an outdent occurs without the matching terminator, or the terminator doesn’t match the opening, the interpreter (or linter) raises a formal error.
Why?
We no longer have the memory constraints of the 80s. Modern development should prioritize readability and structural guarantees. Relying solely on whitespace for logic is a risk factor in large-scale software engineering that could be mitigated by making the ‘contract’ between the programmer and the structure explicit.
In the Python language self that is not an issue because of this is not influencing the interpreter:
indentation is correct
the grammar is correct
the end block statement can be ignored while running the code.
I’m curious to hear if the core team has ever considered a ‘strict-indent’ mode to prevent these silent logical errors.
Best regards,
Nicola