Python: Indentation vs Braces | Guido van Rossum and Lex Fridman

preview_player
Показать описание
Please support this podcast by checking out our sponsors:

GUEST BIO:
Guido van Rossum is the creator of Python programming language.

PODCAST INFO:

SOCIAL:
Рекомендации по теме
Комментарии
Автор

Guest bio: Guido van Rossum is the creator of Python programming language.

LexClips
Автор

I personally prefer curly braces and indent my code myself. I just find it easier to tell which block I'm in by finding the closed curly brace rather then white space. Although, for beginners, tabs is defiantly a lot more easier to use. I remember first learning JS and spending ages trying to figure out what curly brace belongs to what block. Also with modern IDE's and plugins, you can just write everything on one line with a curly brace language, press ctrl-s and your code is formatted perfectly.

liamwelsh
Автор

In case you didn't know, Guido's opinion on braces is coded in __future__ module, test it: from __future__ import braces

pejmanpakrooh
Автор

I like not having to write curly braces except:
1. copying unformatted code and I can rely on the formatter plugin to automatically clean everything
2. copying code and pasting into primitive editor, for whatever reason, indentation messes up and then I get an error
3. when it is hard to see where a function / loop / branch begins and ends
4. when I want to fit 2/3 short statements in one line

jahed
Автор

Forcing identation to affect code performance makes automatic indentation impossible.


Instead, I preffer braces to define function and auto-formatting to force indentation.

diogoantunes
Автор

Defining where the block ends by carriage return and white spaces is no problem for a parser but it is a problem for people reading the code chasing a bug.

EnginAtik
Автор

Guido’s brother Just van Rossum is a very accomplished typographic designer, so Guido’s concerns about layout and legibility of code may have been influenced by that relationship.

xouat
Автор

I like the braces as a safety feature for myself. Like without any further thinking and knowledge I can tell that something is restricted inside { }. Even if someone uses indentation wrong, they can't escape the { } restriction, the stuff inside those will stay there. Without them to me it's not always obvious if some lines are limited inside something else. It would probably be obvious to someone who knows the language's rules very well, they could just glance at it and say what has to be where and stay there. But for me the glance value of { } is huge. And when I first learned, I really liked them back then already. But I can accept that it removes a ton of typo related matching issues in the code. Especially in nordic keyboard the brackets are alt gr + 7 and 0. You never hit both correctly on the first try (thankful for editors that automatically create a matching bracket).

Yupppi
Автор

I was thinking of the semicolon right before guido mentioned them, but in another context: every programmer that has ever used a C-like language is aware of the dreaded missed semicolon, so much so that is a meme nowadays. For python it's the wrong indentation error that plays the same role, every python programmer has seen it at least once and it's definitely a meme. Basically, you can't escape wrong syntax memes.

bracco
Автор

I like curly braces, but on the other hand, indentation forces developers to use proper indentation.

noredine
Автор

I disagree fiercely with indentation because I like to put a lotta stuff on one line, looks super clean.
2 years later I read my own code and I disagree fiercely with myself back then

cat-.-
Автор

I agree indent is important but tabs and space characters should not stop your code from running

zursmith
Автор

Yes, and along with spaces, braces explicitly state where your code block begins and ends. Braces will always be an addition to readability of code.

HelloThere-xsss
Автор

2-space indentation is just stupid. I've worked with that, and found it often hard to tell what level I'm looking at. 3 minimum, 5 maximum, is my assessment of the boundaries of sanity. And just as stupid is camelCase. How the less readable and less writable conventions are the most widely adopted by "experts" is totally beyond me.

About braces or no braces, I'm not against no-braces, but after coding for a long time in both, I ended up preferring braces (or lua's then-end). The issue with no-braces is that it makes languages way too nitpicky about how you lay out the code. You can't mix space with tabs, or you can't even use tabs at all (Nim), you can't put more than a few things in the same line, etc. Nim is even picky about where exactly you can divide your code over several lines (after the _"and"_ and _"or", _ and not before, stuff like that).

Braces have the downside of taking a lot of vertical space, especially when people put the opening brace in its own line, which is completely unnecessary, but overall you feel a relief for not having to worry so much about the compiler/interpreter constantly nagging at you about stupid little things. You code as you have to, and you make it look pretty later.

skaruts
Автор

I do remember coding in COBOL for the mainframe and the indentations were generally 4 character starting at column 8 with a comment '*' in column 7. I seem to remember that being enforced to get a clean compile. I don't mind Python yelling at me to indent properly. Probably because I was trained to adjust with the earlier stricter code patterns.

NomadicBrian
Автор

Python always feels like a weird middle ground between ML-like and C-like syntax.

ketydsr
Автор

You know your dealing with 2 very smart individuals, when one uses the word "anal" to mean fundamental and neither he nor the other start laughing.

maltefiebig
Автор

why tabs/spaces is better than curly braces:

there's maniacs out there doing multiple expression/ assignment per line or goes tab > curly braces > tab > i++;j--;k=i+j;n=j*j
etc.

fltfathin
Автор

one of the vars in the thumbnail: "coversation"

neethology
Автор

Python is my go to language. It makes so many of the little things easier.

wqwwqwqqpoppopoo