(Both literally and figuratively!)
When "significant whitespace" is at the top of someone's complaints about Python, I'm immediately done hearing about their superficial criticism of the language.
(Both literally and figuratively!)
When "significant whitespace" is at the top of someone's complaints about Python, I'm immediately done hearing about their superficial criticism of the language.
if(condition)
do_thing1();
do_thing2(); //not in the if!
do_thing3(); <<body>>=
if 1 == 1:
print('1 == 1, shocking!')
<<function>>=
def foo():
<<body>>
It will generate properly indented code when tangled as in: def foo():
if 1 == 1
print('1 == 1, shocking!')
Note that it puts in precisely two extra spaces for each line in the tangled `body`, which is the amount used in the block named `function` where it references `body`. If you used 4 spaces of indentation, it would use 4 in the tangled output. I've also used noweb and don't recall this being an issue, however that was not with Python so it's possible I just didn't notice a problem with it.Maybe you're thinking of mixing Python with HTML? Python based HTML templating can be ugly, and the significant indentation of Python is a very poor mix for replacing Javascript in whitespace-agnostic HTML.
[0]: https://khinsen.wordpress.com/2015/09/03/beyond-jupyter-what... [1]: http://www.literateprogramming.com/
Your argument became: By adding delimiters, even Python can play well with other languages. /s
Triple quoted docstrings just require that the initial marker (""" or ''') is indented properly (since they are not considered blank lines). All contained text, and the closing marker, can be at any indentation level. This is the cleanest way to include a page of free form documentation, mid anywhere.
Since you added "real" in there, no argument really matters. But regardless, it's funny you say that, as Python current style guide (https://peps.python.org/pep-0008/) outlines 4 spaces as the one and only correct way of writing Python code.
Sure, PEP8 an other standards prescribe spaces, and I of course always use industry standards myself too. I'm just saying that there is no technical merit for that demand. The water pipe in the monkey cage has long been shut down. The only reason to demand spaces for indent now is circular - that other standard is demanding them, therefore we need to do the same, and that other standard uses the same circular logic himself.
Which is a shame, cus otherwise Python is good imo.. I feel like its creator just had a weird whitespace fetish or something.
I always find this take funny, because I have lots of problems with python, but this one has always struck me as the most superficial of the common criticisms.
If you're properly indenting code, then it always works as intended. Proper indentation doesn't come from a desire to make the code work, it comes from a desire to make it readable. It just happens that readable means correct in Python's case.
It literally takes me zero thought to get indentation right. If you can't tell when to start or end indentation level, then I'd question if you know when you need to use an open/close brace in other languages.
I mean, yeah, sometimes copy/pasting code doesn't work precisely as intended, but all you have to do is select the code, hit Tab or Shift-Tab, and any sane editor will add/subtract an indentation level to the code.
If your language requires an IDE, then you have become Java.
I’ll give you the benefit of the doubt, this sounds very curious.
That's quite the assumption.
def my_func():
another_func(lambda: ...)
you can write def my_func():
def inner(): ...
another_func(inner)
Sure, it's creating a function, naming it, then immediately throwing it away, but gets the job done with minimal extra boilerplate. def do_on_click(): # What's being clicked?
foo()
bar()
backup_system_panel.reset_button.bind(on_click=do_on_click())
Oh it's the backup system, maybe I should have named it that. Now I have to worry about reading backwards or keeping names in sync. Having to give it a descriptive name is like uneccessary comments. Giving it a temp name is ok but then you are reading bottom to top to know what is going on like you are programming in reverse polish notation or something. It can be multiple lines and scrolled off the screen before you know the context it is used in, instead of just being able to read top to bottom and get everything. Most other languages let you just stick it in line where it is used. It's error prone like C variables when they had to be declared up top.Sometimes in other contexts it does make sense to do, but with other languages you can choose to pre-declare and name it or not. In python often you see code with all the error handling lambdas up top before you even know what is going on, when exceptions aren't a good fit.
@foo.on_click
def foo_clicked(): ...
Of course, for this, foo.on_click needs to be a callable function rather than a property.Once I'd become accustomed to languages where automatic formatting is feasible, having to do any of this sort of thing by hand started to feel like a real imposition. I didn't object to this aspect of Python when I first learned it, because it didn't feel much different from writing my C code, but now, after years of clang-format (and Visual Studio's auto format, and gofmt on the occasions I've been forced to use Google Go...) I just can't be bothered. How dare it make me press return. How dare it make me press tab. I have better things to do with my life than what I can only describe as this. fucking. shit.
Also, Python has a great auto-formatter, Black.