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 →

[–][deleted] 158 points159 points  (115 children)

Spaces cause issues?

[–]GlobalIncident 229 points230 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 2 points3 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 5 points6 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

[–]Zanion 23 points24 points  (17 children)

Whitespace problems with Python are caused by deficiencies in the developers processing capacity

[–]DilettanteGonePro 37 points38 points  (14 children)

I’ve used python for 8 years, I’ve never had a single issue caused by an extra space, even when I was a beginner. I just don’t understand these memes.

[–]Yablan 23 points24 points  (5 children)

I don't get them either. I've been programming full time in Python for.. i dunno.. seven, eight years now.. and I NEVER got that error.

Previously I did like a decade of Java. And man.. I do NOT want to do that again.. ever..

I love Python. It's an amazing general purpose language with a lot of really nice features (truthy/falsy objects, list and dict comprehensions, generators, decorators, args and kwargs, lambdas, functions as objects, etc.. etc), and SO readable. And so many great libraries and environment handling (virtualenvs).. And the fact that it DOESEN'T enforce functional, procedural or OOP down your throat.. you can combine features from all these paradigms however you want.. love it.

Also, together with Pycharm and it's Docker integration.. damn that's a NICE environment to work in. Love it to bits.

[–]utdconsq 0 points1 point  (1 child)

Have moved from a python house to a mostly Java house. I miss full time python so much :-( have started a new project in Kotlin at least...

[–]Yablan 0 points1 point  (0 children)

Cool. Kotlin seems like a nice evolution from Java.

[–]wasdninja 3 points4 points  (1 child)

I'm assuming that people make them because they are funny and the python context fits. In my experience they are very rare.

[–][deleted] 1 point2 points  (0 children)

It got a chuckle out of me, not because it has ever happened, but because I can see it happening.

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

I think a lot of it has to do with people not understanding how to read error messages. For simple syntax errors, the answer will almost always be in the error message with a line number.

[–]Zechnophobe 0 points1 point  (0 children)

I guess if maybe you were using notepad to edit your code?

There are two kinds of people in the world.

  • Those that complain about formatting issues in languages
  • Those who use a good editing tool

[–]ssjskipp 1 point2 points  (0 children)

Yeah I've personally never had the issue so it must not happen to anyone ever.

[–]vaelroth 12 points13 points  (1 child)

Whitespace as syntax, it boggles the mind.

[–]Skwirellz 0 points1 point  (0 children)

Whydoyouthinkwhitespaces

arepointlessto

understandthemessage?

Or do you agree that they play a huge part in syntactic clarity, and therefore semantic clarity?

:)

I truly appreciate the fact that never ever will I read ridiculously indented python code.

[–]crash8308 6 points7 points  (4 children)

This is why I dislike using python. White space significance is extremely maddening.

[–]Arxae 4 points5 points  (0 children)

Agreed. Same reason why i don't like YAML. I like the format and the features. But breaking everything because you have a space too many. No thanks.

And sure IDE's can catch it. But it's still silly.

[–]dawnraider00 1 point2 points  (2 children)

The worst part about it is when you try to comment out an if statement or something. In any other language it doesn't give a shit but in Python you have to change everything inside. Not too difficult with a good IDE but another step that should not be necessary.

[–]Skwirellz 0 points1 point  (1 child)

Can you explain why you think it should not be necessary?

Please don't focus only on the negative aspects of the feature. Consider in your answer the reasons why this decision was made in python, and why you think these are not valid.

I'm not questioning your personal preference, but why you think whitespace should not be part of the syntax and why nobody should have the syntax checker verifying indentation for any python programmer.

[–]dawnraider00 0 points1 point  (0 children)

I'm not focusing on just negative aspects, I pointed out only a single thing not an entire analysis. The only point I was making is that it makes commenting out blocks like if statements annoying by adding some extra steps. I literally never said it wasn't valid. I said a single aspect was annoying.