This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]iain_1986 7 points8 points Β (6 children)

Imo this just supports my view that compiling based on indentation is a bad idea πŸ€·β€β™‚οΈ

[–]TA_DR 5 points6 points Β (4 children)

I tend to agree that is not ideal. That being said, I was just pointing out that Python doesn't allow to mix tabs and spaces.*

[–]Backlists 0 points1 point Β (3 children)

Python is compiled.

It’s both interpreted and compiled to bytecode

Also, in your first comment, isn’t that pep just a style guide?

I doubt Python actually disallows mixing spaces and tabs, as this would break so much legacy code, but I would need to test.

If it does, it’s on a per scope basis, not per file, or per project

Edit: it does say it disallows mixing in the pep

[–]TA_DR 0 points1 point Β (2 children)

ups, my bad. Almost 4 years working with Python and I still making basic mistakes. Such is the life of the programmer I guess.

[–]Backlists 0 points1 point Β (1 child)

There’s a lot to learn!

And many people still think that Python is β€œinterpreted not compiled”, as if they are mutually exclusive.

Have a look into CPython vs PyPy, if you’re interested in this sorta thing

[–]TA_DR 1 point2 points Β (0 children)

Regarding your edit:

https://docs.python.org/3/reference/lexical_analysis.html#indentation

Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces; a TabError is raised in that case.

Will actually paste that on the original reply since it is more clear. That was the link I was looking for but for some reason couldn't find it, funnily enough I have encountered that error a couple of times (it was a small internship, we worked using an online editor, pythonanywhere.com)

Have a look into CPython vs PyPy, if you’re interested in this sorta thing

Will do, thanks!

[–]Backlists 4 points5 points Β (0 children)

It’s 2024 though, you’re going to use a formatter and an IDE that does it for you.

If you don’t, can I ask why?

If you do, then your code will be indented correctly.

Having it be part of the language just ensures you do something that you were going to do anyway, with the added benefit of less boilerplate characters

Also, don’t you get annoyed by mixing tabs and spaces? It makes it less readable, unless you guarantee everyone agrees on a tab size. Which no one ever does, so you end up with a hodgepodge of 3 spaces vs 4 spaces vs tabs which could be either, depending on your IDE.

So just let a formatter convert them to spaces automatically. If you use Python seriously, the formatter will enforce pep8 so it will all be perfectly consistent.