Are there any pitfalls with using whitespace in Python?

后端 未结 17 1180
时光取名叫无心
时光取名叫无心 2021-01-06 17:36

At the moment I have never had a problem with whitespace in Python (although I\'ve only used it in two projects and I was the only programmer). What are some potential pitf

相关标签:
17条回答
  • 2021-01-06 18:21

    When I look at C and Java code, it's always nicely indented.

    Always. Nicely. Indented.

    Clearly, C and Java folks spend a lot of time getting their whitespace right.

    So do Python programmers.

    0 讨论(0)
  • 2021-01-06 18:21

    The problem is that in Python, if you use spaces to indent basic blocks in one area of a file, and tabs to indent in another, you get a run-time error. This is quite different from semicolons in C.

    This isn't really a programming question, though, is it?

    0 讨论(0)
  • 2021-01-06 18:23

    One drawback I experienced as a beginner whith python was forgetting to set softtabs in my editors gave me lots of trouble.

    But after a year of serious use of the language I'm not able to write poorly indented code anymore in any other language.

    0 讨论(0)
  • 2021-01-06 18:23

    No, I would say that is one thing to which I can find no downfalls. Yes, it is no doubt irritating to some, but that is just because they have a different habit about their style of formatting. Learn it early, and it's gonna stick. Just look how many discussions we have over a style matter in languages like C, Cpp, Java and such. You don't see those (useless, no doubt) discussions about languages like Python, F77, and some others mentioned here which have a "fixed" formatting style.

    The only thing which is variable is spaces vs. tabs (can be changed with a little trouble with any good editor), and amount of spaces tab accounts for (can be changed with no trouble with any good editor). Voila ! Style discussion complete.

    Now I can do something useful :)

    0 讨论(0)
  • 2021-01-06 18:24

    Whitespace block delimiters force a certain amount of code formatting, which seems to irritate some programmers. Some in our shop seem to be of the attitude that they are too busy, or can't be bothered to pay attention to formatting standards, and a language that forces it rubs them raw. Sometimes the same folks gripe when others do not follow the same patterns of putting curly braces on a new line ;)

    I find that Python code from the web is more commonly "readable", since this minor formatting requirement is in place. IMO, this requirement is a very useful feature.

    IIRC, does not Haskell, OCaml (#light), and F# also use whitespace in the same fashion? For some reason, I have not seen any complaints about these languages.

    0 讨论(0)
提交回复
热议问题