5 ms·
Python's indentation for blocks isn't holding up to the test of time. After suffering badly formatted code in my early career, Python's approach seemed refresh
by Steltek 8y ago
Python's indentation for blocks isn't holding up to the test of time.
After suffering badly formatted code in my early career, Python's approach seemed refreshing. But after suffering one too many bad merges where indentation is left mangled, we need braces. You can automatically reformat everything instantly without even thinking about it, eliminating merge ambiguity. gofmt is the better solution because it declares a strict representation that can be automatically enforced.
You could retort that better rebase/merge practices could alleviate some of these issues but if that discipline could be enforced on arbitrary groups of humans, we wouldn't have cheered Python's forced indentation in the first place.
- naasking 8y ago> But after suffering one too many bad merges where indentation is left mangled, we need braces. Or semantics-aware merging.
- AnimalMuppet 8y agoI'm not an expert on Python by any means, but if I understand correctly, the end of the indent level is the only way you know that the block ended. That seems to me to make it impossible to write semantics-aware merging (presuming I understood what you meant by the term).
- dooglius 8y agoWhy does this make it impossible? The merger just needs to understand where blocks begin and end, not sure I follow you
- AnimalMuppet 8y agoWhat I thought you meant is that you need something that will straighten out the mangled whitespace. I didn't think that was possible, because the only thing that marks where blocks begin and end is whitespace. If the whitespace gets mangled, there's no other syntax you can use to straighten it out. But I'm beginning to think you meant that you want a merge tool that doesn't mangle the whitespace in the first place. If the pre-merge whitespace is unmangled, and the merge tool understand Python whitespace, then at a minimum it should be able to flag ambiguous changes and ask for help.
- dooglius 8y agoRight, a merge tool that understands Python semantics at some level should be able to detect when a block's indentation has changed, and adjust the indentation of any changes to that block correspondingly.
- deleted 8y ago[deleted]
- aprdm 8y ago> Python's indentation for blocks isn't holding up to the test of time. Citation needed. Python popularity seems to be only growing up and in all kinds of industries. Hard to find somewhere where python hasn't touched yet. Also, as you mentioned, is pretty standard to have some sort of flake8 as part of your CI and it would certainly detect problems with bad identation that would cause code issues. If the basic flake8 tests pass then should certainly have some unit / integration tests as part of your merge request... Now a days there are even things like black [https://github.com/ambv/black https://github.com/ambv/black] that does auto formatting just like gofmt.
- Steltek 8y agoA quick tour through history will show that minor language defects have never been a showstopper for adoption. Python is popular in spite of it's minor irritations (and all languages have minor irritations in some form). Further, all the human conditions that resulted in bad code style before are still present and showing through in Python codebases. Namely organizations with loose standards or inadequate tooling where language problems get magnified. This is remarkably evident in companies that used to be 100% C/C++ or Java shops and never quite figured out unit tests.
- Sean1708 8y ago> does auto formatting just like gofmt It does auto formatting, but it doesn't do auto formatting just like gofmt. An auto formatter can't do anything with this block if check_based_on_value: if value < 0.3: # do something elif 0.3 <= value < 0.7: # do something else else: # do a third thing for example.
- Sean1708 8y agoAlso indentation-based syntax makes it (almost?) impossible to have an expression based language and IMO delimiters are definitely a price worth paying for that.
- the_why_of_y 8y agoThe expression based language Haskell has indentation-based syntax.