4 ms·
I too have tried it many times mainly because of all the great ML libs for python but each time I dreaded using it for Reason #3 (Syntax). Using indents for bl
by superasn 8y ago
I too have tried it many times mainly because of all the great ML libs for python but each time I dreaded using it for Reason #3 (Syntax).
Using indents for blocks just seemed unintuitive and error prone to me. But I dismissed it because all the programming languages I've worked with have had curly braces so maybe
the reason for my discomfort was that it was unfamiliar.
- jdblair 8y agoOnly in Python can I commit a whitespace-only change that results in a 10x speed improvement.
- b_tterc_p 8y agoCare to explain? I’m not sure where this would work without fundamentally changing the meaning of the code
- notacoward 8y agoI'm guessing it refers to moving something out of a loop, which in Python often requires only an indentation change. In most other languages, it requires moving the code to the other side of a brace, or perhaps adding a brace. If braces were considered whitespace, which is not entirely unreasonable when talking about Python vs. other languages, it would be much harder to come up with examples. Drawing a blank right now. Anyone else want to try?
- jdblair 8y agoThat correct. It was a case of nested loops and some code that was in the wrong loop. Braces are most definitely not whitespace, even if they serve the same function as whitespace in Python.
- Symmetry 8y agoMost languages that use braces also encourage you to indent the things enclosed by the braces to make it easier to read. However, people sometimes make mistakes. For instance I've seen this quite a number of times if (a) somestatement; someotherstatement; athirdstatement; Which is of course horribly misleading unless you're careful because the second statement isn't actually conditional on a. Python forces the indent to match the semantics.
- newen 8y agoDoes no one have auto indentation in their editors? Every so often I just select the block of code I'm editing and auto indent it, which matches indentation with semantics without me having to think about it. Annoyingly impossible to do this with python since indentation is semantics. It also results in copy pasting of code being 100 times harder in python than other languages.
- acdha 8y agoThat doesn't help with the problem you're replying to – in fact it would contribute to it. More generally, yes, many people use auto-indenting and it works in Python in most editors. It's possible that you're using one where it doesn't work correctly but that doesn't mean that's true for everyone else.
- newen 8y agoIt does help with the problem I replied to, which was code written in C. Auto indenting that code block would indent the `someotherstatement;` line correctly and I would notice that mistake. Anyway, single line if statement is a flaw in C's design. What I said was that in Python's case, if I indent some code block wrong, I can't just fix the indentation using auto indenting in python, because the indentation is the semantics. There would be "nothing" to fix and the code would just run wrong. This problem comes up always when I copy paste python code. Of course I should notice that it's indented wrongly but that doesn't always happen. (And please don't advise me to never copy paste code. Life doesn't work that way.)
- silon42 8y agoYou could use 'pass' to denote end of block... Someone just needs to write a validator.
- xtracto 8y agoAt some point in my Uni I thought of writing a "curly braces to python" translator that will take code in "pseudo python" which allowed curly braces and would convert/indent it the correct way.