4 ms·
How does significant whitespace save you from bugs? if expr: doA() doB() Is doB at the correct level? Having text that's invisible change
by secondcoming 5y ago
How does significant whitespace save you from bugs?
if expr:
doA()
doB()
Is doB at the correct level?
Having text that's invisible change the flow of your program is crazy IMO.
- feffe 5y agoI don't care that much in my own side projects but when working with others and resolving merge conflicts your example is my nightmare. It's so much easier to have brackets denote scope as you don't have to get the indentation right when actually resolving merge conflicts. It's easy to fix it up afterwards by automatic indentation in the editor. Significant white space is a mistake IMHO :-)
- akubera 5y agoThe bugs being referred to are from optional brackets in C: void foo() { ... if (expr) doA(); doB(); ... } which is unambiguous to the compiler, but could (and I expect would, especially when glancing through a lot of code) cause misinterpretation by a human reader. We can more easily hallucinate the brackets than the indentation. I disagree with the idea that indentation spaces are invisible; rather they are much more visible than a pair of brackets. This actually becomes a problem when you embed/indent too much and 70% of the line is spaces. It's all you see!
- secondcoming 5y agoYes, but pretty much every coding standard I've seen mandates the use of braces always. You do it without even thinking. Your example wouldn't pass code review.
- xigoi 5y agoif (expr) { doA() doB() } Is doB at the correct level? It's the same thing.