Are there any pitfalls with using whitespace in Python?

后端 未结 17 1187
时光取名叫无心
时光取名叫无心 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:02

    Pitfalls

    • It can be annoying posting code snippets on web sites that ignore your indentation.

    • Its hard to see how multi-line anonymous functions (lambdas) can fit in with the syntax of the language.

    • It makes it hard to embed Python in HTML files to make templates in the way that PHP or C# can be embedded in PHP or ASP.NET pages. But that's not necessarily the best way to design templates anyway.

    • If your editor does not have sensible commands for block indent and outdent it will be tedious to realign code.

    Advantages

    • Forces even lazy programmers to produce legible code. I've seen examples of brace-language code that I had to spend hours reformatting to be able to read it...

    • Python programmers do not need to spend hours discussing whether braces should go at the ends of lines K&R style or on lines on their own in the Microsoft style.

    • Frees the brace characters for use for dictionary and set expressions.

    • Is automatically pretty legible

提交回复
热议问题