Why does Python ditch cumbersome curly braces and use indentation to divide code blocks?

Hello everyone, this is the transcript of the "Why Python" series ( there is a viewing address at the end of the article ).

Topic in this issue: Why does Python use indentation to divide code blocks, instead of using curly braces {} or "end" like other languages?

Indentation in Python is an old-fashioned topic, and it is often mentioned. For example, the father of Python just forwarded an article last month:

Because of this article, Guido was also invited to record an episode on the Python Bytes podcast:

So, why does Python use indentation to divide code blocks?

I collected and sorted out a few materials, and then I will take you to reveal the design reasons why Python does this:

  1. Indented syntax, more elegant
  2. Indented syntax for clarity
  3. Use indentation for consistency and avoid misreading
  4. Using indentation, the code is more compact, easy to browse, no cumbersome
  5. Use indentation, enough for the interpreter to execute, no need to use extra symbols
  6. Forced indentation, from the ancient ABC language, of which Guido was one of the designers
  7. The idea may have come from Don Knuth (Knuth, famous computer scientist, author of the classic "The Art of Computer Programming"), who proposed it in 1974, which was a very fashionable and avant-garde idea at the time
  8. Using indentation, you can end the ultimate debate about whether to put curly braces after the function name or on a new line (a topic that is said to be a source of strife among programmers of different factions!)

The reasons listed above are mainly derived from the official Python documentation, official wiki, and early interviews with the father of Python.

All in all, Python uses an indented syntax, which reflects its very elegant, clear design aesthetic, and is extremely friendly to developers, readers, and interpreters.

To be honest, I like Python's indentation so much that I fell in love with it at first sight. If you use a syntax such as curly braces, then Python will be bleak and tasteless!

What do you think of Python's indentation syntax? Please express your opinion in the comment section!

References:

1. Twitter from Guido: https://twitter.com/gvanrossum/status/1249549091584892928

2. The article on indentation forwarded by Guido: https://web.archive.org/web/20070922223915/http://www.secnetix.de/~olli/Python/block_indentation.hawk

3. Guido is a guest on the Python Bytes podcast, talking about indentation: https://pythonbytes.fm/episodes/show/179/guido-van-rossum-drops-in-on-python-bytes

4. Video version of the podcast: https://www.youtube.com/watch?v=PlvvVXeU0yw&feature=youtu.be

5. Official documentation explains indentation: https://docs.python.org/3/faq/design.html#why-does-python-use-indentation-for-grouping-of-statements

6. Explanation of the official early wiki: https://wiki.python.org/moin/Why%20separate%20sections%20by%20indentation%20instead%20of%20by%20brackets%20or%20%27end%27

7. Mr. Chi Jianqiang's MacTalk article: https://mp.weixin.qq.com/s?__biz=MjM5ODQ2MDIyMA==&mid=2650715803&idx=1&sn=94cd823de3689f40d4ed4c541a1ee791

First address: https://mp.weixin.qq.com/s/byhJnKoKSDnhUNUE9WWopw

Video address:

1. Station B: https://www.bilibili.com/video/BV1UT4y137Yv/

2. Zhihu: https://www.zhihu.com/zvideo/1242823762849959936

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324214889&siteId=291194637