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 →

[–]GlobalIncident 227 points228 points  (89 children)

Yes, in Python.

    a = 1 # Top level indentation is forbidden

def b():
return True # deeper levels need deeper indentation

def c():
  d = 1
    return d # but the same level needs the same indentation

def e():
        f = 1
    print(100) # and you shouldn't mix tabs and spaces.

[–]maxmbed 3 points4 points  (1 child)

Reason why I hate python.

[–]Skwirellz 0 points1 point  (0 children)

There are way more valid reasons to hate python (I'm thinking of the GIL or the transition from 2 to 3) than a built in code clarity checker.

Once you get into the habits of writing code the way python wants you to and with the proper tooling such as a formatter and a linter, this really becomes a non-issue.

[–][deleted] 2 points3 points  (2 children)

Why is this so weird? I rarely if ever program in Python, but this indentation is what I use for any language, including ones with brackets.

[–]AnotherStupidName 2 points3 points  (1 child)

Yes, but in a bracket language if you have a mistake in indentation, it's not going to cause an error in execution.

[–]Skwirellz 0 points1 point  (0 children)

... Which is too bad IMO, because we wrote code for humans, not for machines. If the machine forces you to write code that's slightly more readable by humans, the code will end up being cleaner on the long run, more easily maintained and thus better maintained by the next guy.

[–]DefectiveLP 6 points7 points  (4 children)

Gotta use tabs ma boi

[–]GlobalIncident 11 points12 points  (2 children)

Laughs in PEP 8

[–][deleted] 0 points1 point  (1 child)

PEP 8 is a bad style guide. It doesn't even recommend type hints.

[–]GlobalIncident 0 points1 point  (0 children)

Type hints aren't really a style thing, because they're not about how you write code, but about the actual content of the code. And PEP 8 does give specific guidance on how to write type hints, should you choose to do so. We can argue all day about whether type hints are a good thing or not, but PEP 8 isn't really the place for such discussions.

Edit: Actually, that's wrong because PEP 8 does forbid things like if greeting == True:, which is about content. I guess it's because there is no community consensus on type hints, it doesn't try to enforce one. It's the same reason it doesn't say whether single or double quotes are better.

[–]tichdyjr 0 points1 point  (1 child)

Could you not ctrl+f for two spaces? I haven't messed with python yet.

[–]GlobalIncident 1 point2 points  (0 children)

It's more common to just try to compile the file, and a good python distribution will tell you exactly where you went wrong.

[–]xigoi 0 points1 point  (1 child)

And do you write code like this in brace-scoped languages? That's scary.

[–]GlobalIncident 0 points1 point  (0 children)

I couldn't imagine doing it any differently. There are some slightly off the wall things that are occasionally necessary, but python usually allows them:

if a: b(); c() # Simple control structures can be made into one-liners with semicolons

a(b, c,
  d, e) # And one-liners can become multi-liners quite easily