Is the code style of the Python indentation really good?

Source: Internet
Author: User

Like this ... I do not think Python style is very good, reading and writing are not convenient, now the editor is so convenient, the semicolon can be completed automatically. Does everyone think Python is a good style?

(Image source: https:// twitter.com/thedirtycod er/status/569339014085517312

Reply content:

Post a learning Python, 5th edition-o ' Reilly Media All right:

Why Indentation Syntax?

The indentation rule may seem unusual at first glance to programmers accustomed toc-like languages, but it's a deliberate feature of Python, and it's one of the main waysthat Python almost forces programmers to produce uniform, regular, and re Adable code. It essentially means that's must line up your code vertically, in columns, ac-cording to its logical structure. The net effect is to do your code more consistent andreadable (unlike much of the code written in C-like languages).


To put the more strongly, aligning your code according to its logical structure are amajor part of making it readable, and Thus reusable and maintainable, by yourself andothers. In fact, even if-never use Python after reading this book, you should get intothe habit of aligning your code for read Ability in any block-structured language. Pythonunderscores the issue by making this a part of its syntax, but it's an important thing Todo in any programming Langu Age, and it had a huge impact on the usefulness of Yourcode.

Your experience may vary, if I am still doing development on a full-time basis,i is mostly paid to work on large O LD C + + programs that had been worked on Bymany programmers over the years. Almost invariably, each programmer had he or Herown style for indenting code.

Forcing indentation is actually a mechanism for Python to keep the code in a uniform and readable manner.
At the same time do not sincerely wish those code style written as the same as the bullshit also feel that their dick and witty and personality of the students will not be co-operative colleagues to fly. The map is Java ... You java with what Python-type indentation ah ...
I use the Pure PythonRewrite your code:

class Permuter:    def Permute( Self, N, a):        if N==0:            Print a        Else:             for I inch Range(N+1):                Permute(N-1, a)                 Self.Swap(a, 0 if N%2 Else I, N)    def Swap( Self, a, I, J):        a[I], a[J] = a[J], a[I]
In fact, any language at the time of writing will be indented as a specification. Even though indentation has no practical meaning for the compiler, it increases readability. So since there is no use to indent, there is no python so good bad problem.

The main IDE has auto-typesetting function, you can try to know. To add, I mean automatic typesetting of other languages. The automatic layout of Python does not handle automatic indentation of the beginning of a statement. You can only change the distance between characters. Python is a thing that forces you to indent normalization. If you follow the specification, Python is a direct skip to the curly brace semicolon, and there is no other customary change. If you ignore the indentation specification at all ... I'm sorry, I really don't want to see the code without indentation, and I believe I'm not alone.

As for the said writing when not indented to write and then automatically shrink into what ... Write a complex point of things are estimated to be crazy to check the wrong ...


Say stick a Java diagram has been a lot of spit, but still can not help spit groove ... You have to put a little grammar like a bit of ah ... You... Paste ... A ... java ... Do... Well ... Indentation solves an issue where curly braces are not wrapped in a newline.
Now that the editor is so handy, semicolons can be done automatically.
Even if you don't want to write a semicolon, you don't need Python? Just don't write it. :-D's not very good. The gods have been using the "crappy" language, and you're still talking about this? Anyway, we're going to wrap the indentation in parentheses,
Do not press the keyboard once, and the auto alignment is not very good
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.