I think you may have misstated the situation. Indentation is not optional, it is required if the block (suite) spans multiple lines. If you are willing to put each block on a single line, then indentation is not relevant.
Interesting observation. You could also use backslashes for line continuation to make it even more horrible:
def my_func(): \
print('hello', end=""); \
print(' world'); \
return 'successful!';
n = 0;
while n < 5: \
print(n) if n % 2 else None; \
n += 1;
my_func();
But you can’t have more than one level of structure, which is a bit limiting. So you can’t have if statements inside functions, for example, although you can use if expressions instead in some cases:
def fizzbuzz(n): \
print("fizzbuzz") if n % 15 == 0 \
else print("fizz") if n % 3 == 0 \
else print("buzz") if n % 5 == 0 \
else print(n)
i = 1
while i < 20: \
fizzbuzz(i); \
i += 1
There are limitations to this, and there are ways to work around the limitations. None of this should be particularly new or interesting to experienced Pythonistas (unless they’re so disciplined that they’ve never even thought about writing ugly, complex code).
Writing a Python program without indentation is like writing a novel without the letter “e”. It’s possible, but other than as a fun challenge, not particularly useful.
Like the novel, Gadsby, which is a lipogram that avoids words with the letter “e”, the primary value of a Python program that avoids indentation would be its status as a novelty.
Yes I’ve used the semi-colon to separate statements if I run a short Python program from the CLI.
But how do we know this semi-colon will work in this context in 10 years?
I just follow what the tutorials show and use indentation. The indentation also makes the code easier to read. I never liked the old 1980 BASIC language where we had to put multiple statements on one line to save memory. (Like the VIC-20.)
It is interesting though.
EDIT: I ended up using semi-colons in my .pdbrc file to make some debugger aliases.
# alias dir import glob; myfiles = glob.glob("%1"); for i in myfiles: print(i)
alias dir import glob; print(glob.glob("%1"))
alias dir1 import glob; _ = [print('-', x) for x in sorted(glob.glob("%1"))]
alias q quit()
So it does work there also. I wouldn’t now how to make an alias with multiple lines.
Actually, this genre of Python programming deserves even more credit than that. Like other forms of art that work with constraints, it has potential educational value. Working with imposed constraints or prescribed patterns encourages creativity and research. After all, many forms of poetry have a long cherished tradition.
For just a few of many examples of creativity in programming and writing that involve adhering to selected constraints and patterns, see the following Wikipedia articles:
Such a strategy extends to the visual arts, as well. For example, one can work with a minimal palette of colors, or resort to using only dots to create a picture.
All in all, from the first release of the first Python supporting the new way, until the last release of the last Python supporting the old way, was about 13 and a half years. And people still loudly complained the entire time (in one famous case, a well-known Python educator made some absolutely bizarre and unsound arguments that were then thoroughly refuted), missed their migration deadlines, and kept asking the community to help with unofficial support after that. Another 4 years beyond that, we’re finally at the point where I scarcely hear about the old version any more. That migration tool in the standard library still won’t be removed for a few months yet (and Python versions including it will, of course, be supported for up to another 4 years).
So, no, Python won’t drop support for semicolons any time soon. It would break huge amounts of existing code for a purely aesthetic principle. And everyone remembers far too well how difficult it is to get certain segments of developers on board with that.