10 ms·
Anyone who can't see past Python's indentation-based syntax is a person who doesn't understand Python. (Both literally and figuratively!) When "significant wh
by driggs 2y ago
Anyone who can't see past Python's indentation-based syntax is a person who doesn't understand Python.
(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.
- ahartmetz 2y agoYeah. It avoids the problem of indentation disagreeing with code structure and reduces visual clutter and... that's it.
- tacticus 2y agoyou can solve that with a formatter. and then you'd get consistent outputs that work reliably as you move code.
- Sohcahtoa82 2y agoWhen I hear someone complain about the whitespace thing, it sends a message to me that they do not format their code well and just go willy-nilly on their indentation. 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.
- HexDecOctBin 2y agoI just translated all my build scripts written in Python to straight C due to indentation issues. Not because I don't format my code properly, but because any time I refactored my code, I ended up with dozens of subtle indentation related bugs that took hours to find and fix. If your language requires an IDE, then you have become Java.
- simonw 2y agoWhat text editor do you use?
- gunian 2y agowhy? black automatically formats code
- kstrauser 2y agoPython doesn't require an IDE, but you'll definitely want to use a programmer's editor with it. I don't know what you're using that doesn't handle its indentation correctly because I haven't seen anything like that in at least a decade, but you may wish to upgrade to at least a newer vim or emacs.
- sanderjd 2y agoI don't relate to this at all. I don't understand how you refactor, in either python or C or anything else, without fixing indentation after you move code around. Yes, in C you don't have to fix the indentation in order to get it to compile and run, but that doesn't mean you don't have to fix the indentation! You can't just leave it inconsistent, that's insanity.
- wakamoleguy 2y agoOf course you can leave it inconsistent! If whitespace is insignificant, you can move things around however you want and use (frequent) runs of a code formatter to clean things up for you. If whitespace is significant, it must be fixed manually line by line.
- sanderjd 2y agoCode formatters work just fine in python. If you're running a code formatter frequently, that is not "leaving it inconsistent".
- wakamoleguy 2y agoIf we’re talking about pasted code not having the proper indentation, that’s a major difference between languages with and without significant whitespace. A formatter can fix that in C, but not in Python. Additionally, manual fixing of the indentation is required first.
- cma 2y agoNot being able to nest multiline lambdas into function arguments where they are called makes you have to read a lot of code backwards.
- kstrauser 2y agoI do wish it had lambdas. That's largely mitigated by the fact you can define functions pretty much anywhere. Instead of: 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.
- sanderjd 2y agoYep, I find python's lambda syntax to be probably its worst conceived feature. But just defining a named inner function works great for all the same use cases.
- cma 2y agoThat's what I meant by backwards though. Especially in UI OnClick code etc., I'd rather know the context that this happens on click of whichever object it is, but instead I have to write the clicked code before the code that registers it with the object, whose name has more relevant info, and then I end up having to name an extra thing too and keep the name in sync
- kstrauser 2y agoBut you can use a named function anywhere you'd use a lambda, in exactly the same way, just literally one line above where you'd pass the lambda to another function. It's not like you have to write the named function up at the top of the file. You can define it right there where it's going to be called. Truly, it's so easy and cheap to make a named function that I've never really missed having lambdas.
- cma 2y ago
- tbrownaw 2y ago> When I hear someone complain about the whitespace thing, it sends a message to me that they do not format their code well and just go willy-nilly on their indentation. That's quite the assumption.
- tom_ 2y agoPython forces you to properly indent your code because the language is designed in a way that means the computer can't do it for you. 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.
- xigoi 2y agoYou have to press return instead of a semicolon, which is the same amount of keystrokes, and tab instead of a curly brace, which is fewer keystrokes. What problem do you have with that? Also, Python has a great auto-formatter, Black.
- mkl 2y agoAgreed. I find such complaints very strange, as most people already follow Python-like indentation rules quite strictly in most other languages, but need to add delimiters as well. Indentation is the clearest indication of code structure, so when it's not significant it still looks significant, leading to bugs like: if(condition) do_thing1(); do_thing2(); //not in the if! do_thing3();
- wwfn 2y agoLiterate programming tools that weave/tangle code and documentation don't play well with significant whitespace. Not a problem for me, but I think it's on a valid line of complaints.
- nomel 2y agoTechnically comments are considered blank lines, so indentation can be arbitrary. This is against PEP8/linters, but it's not a formatting error. 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.
- driggs 2y agoI very strongly disagree. The most successful implementation of literate programming is the Jupyter Notebook, formerly called iPython Notebook. Even when you write it as raw markdown, there's no issue mixing documentation with triple-backtick code blocks. 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.
- tommiegannert 2y ago> there's no issue mixing documentation with triple-backtick code blocks. Your argument became: By adding delimiters, even Python can play well with other languages. /s
- wwfn 2y agoI thought tools like jupyter and rmarkdown are better described as narratives[0] (lab notebooks and report generators) separate from and almost antagonistic to literate programming[1]. At least as I've been exposed to them, notebooks don't easily facilitate code reuse -- libraries aren't written in notebooks but could be written with literate programming tools. [0]: https://khinsen.wordpress.com/2015/09/03/beyond-jupyter-whats-in-a-notebook/ https://khinsen.wordpress.com/2015/09/03/beyond-jupyter-what... [1]: http://www.literateprogramming.com/ http://www.literateprogramming.com/
- jokoon 2y agoPersonally I started making a language that uses it
- dgfitz 2y agoI agree. I think it’s only an issue because we as a collective didn’t sort out a tabs-vs-spaces debate and new people to the language struggle with that bit.
- maleldil 2y agoPEP-8 says 4 spaces. No one should be using tabs.
- Yizahi 2y agoThe problem is that in the year 2024 there are no real technical arguments against tabs. I suspect very few people saw any tab mangling system ever in their lives or even at all. We are like monkeys from the anecdote about bananas and waterhose. All the population has been replaced multiple times and waterhosse is long dead, but we are still afraid to touch the forbidden fruit.
- diggan 2y ago> The problem is that in the year 2024 there are no real technical arguments against tabs. 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/ https://peps.python.org/pep-0008/) outlines 4 spaces as the one and only correct way of writing Python code.
- Yizahi 2y agoThe emphasis was on the word technical. The only technical argument I've ever heard against using tabs for indentation only, was that some software text editor a long time ago mangled tabs. In my anecdotal experience with computers plus working with some embedded telco hardware dating back to 2000 and some even earlier, some with rather old or non mainstream OS, I've never ever seen a text editor which mangled tabs. Nor I've never met anyone who seen that happen. Maybe it happened in the mainframe age, but I suspect even that software has been upgraded over time. 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.
- dariusj18 2y agoMy problem with indentation as significant is when I paste a chunk of code inside some chunk that is indented differently. Some may say that a good text editor will deal with that for you, but it's rarely been the case for me. The most is when the code is longer than my screen height and I have to scroll down and figure out where the pasted chunk ends and indentation it all who knows how many times without scrolling back up to the top of the chunk.
- smitelli 2y agoSpeaking only as myself, usually when I find myself having the scrolling problem the function/method is crying out to be broken down and refactored anyway.
- everyone 2y agoI dont think it's superficial. Having characters that are invisible affect your code is weird and bad. Which is a shame, cus otherwise Python is good imo.. I feel like its creator just had a weird whitespace fetish or something.