5 ms·
Whitespace significance is awful. After some time questioning why I have fallen out of love with python, I realized that is part of the answer.
by unethical_ban 3y ago
Whitespace significance is awful. After some time questioning why I have fallen out of love with python, I realized that is part of the answer.
- pphysch 3y agoThis is more of a tooling problem than a language problem. I haven't thought about Python whitespace in ages (i.e. since I switched to modern code editing tools).
- kleene_op 3y agoThere's a huge difference in desirability for white space significance depending on whether or not it is used for code or data storage. Because the best practice is to decompose your code in functions and classes, space significance isn't so much a problem in Python. YAML on the other hand, is a visually atrocious way to store tree-like/multi-layered data.
- semi 3y agoI somewhat agree in that it does feel like more of a problem in YAML than code, and infinitely more of a problem when doing both (template code generating yaml) But I still don't think there's any desirability for whitespace significance in code. Is there any problem it solves that isn't better solved by having enough structure and standardized tooling for autoformatting like go fmt?
- ajsnigrutin 3y agoYep, whitespace should be used to make things "pretty", and some kind of 'tidy' program should be able to do it automatically. Counting the spaces and/or tabs and/or not even knowing which one it is, really sucks. Some editors help a bit with that, but it still sucks.
- teytra 3y agoTABs should be used for indentation, making it line up pretty. SPace is for separating words. Modern editors (and old ones too) should be able to show what is a TAB, so there is no reason to be confused. The problem is that people think of TABs as a certain number of spaces, as if an indentation must be a certain number of spaces. In Python or Yaml etc, the logical construct is to have "one indentation level" for things like the statemants that belong to an if, or whatever. Requiring people to put in a somewhat randomly chosen number of spaces is just silly. It is "one level", so the logical choise would have been to put in one symbol to designate this fact, then use the settings of the editor to show it as you want (how many "spaces" to move), and this can change depending on personal choice, the monitor you use, etc.
- teytra 3y agoThe problem is that people use spaces and not TABs here. The TABualator key was invented for this purpose, in the age of the typewriter, to make things visually stand out by grouping it in the same column of a table. So all the lines that belong together are listed with the same indent, (originally all items belonging in the same column being listed under the same heading). Example user: given_name: something family_name: somenting Using a somewhat randomly number of spaces is just silly, the two name lines is one hierarcical level below "user" so add one tab char to represent that fact. Then you can vary the visual representation in your editor to your liking. json is created to make it easy for machines to parse, not humans. Leave it to the machines. Actually: one of the reasons TABis misunderstood is that cheap typewriters didn't have adjustable tabulator positions, and when computers came along it was often implemented with fixed columns (typically every 8), so people think of TAB as 8 spaces, which often is not what you want.
- teytra 3y agoOne of the nice things with Python compared to, say C, is that what you see visually is what you get. I.e. if you use TAB and not spaces to indent lines or are very careful about how many spaces you put in, but then you lose the ability to quickly change the visual representation. In C you actually use indentation when you write code to make it readable for humans, but the machine doesn't care, so there is a disconnect between the visual and how it is parsed. You have to both use indentation add a lot of curly-braces to your code. In Pyhon you don't have this double-work.