6 ms·
python fans are going like "what are braces?"
by alunchbox 9y ago
python fans are going like "what are braces?"
- kabdib 9y agoThat's fine -- the Python folks have their own share of religious wars (starting with: tabs, or spaces?) :-)
- TomMarius 9y agoTabs, everyone can configure them however they want. :-)
- RobertRoberts 9y agoI hate being able to configure stuff, I want other people to boss me around from anywhere in the world! Their opinion matters on my computer!
- tabbspace 9y agoUntil you need spacing that isn’t a multiple of your tab width then you’re screwed.
- YSFEJ4SWJUVU6 9y agoWhy would you ever half-indent a block? For alignment you should of course use spaces (for whole alignment, not just the end, to be very clear).
- tabbspace 9y agoLining up arguments across multiple lines sometimes involves non-multiples of tabs.
- gambiting 9y agoAs a C++ programmer I can assure you, I know plenty of individuals with very strong opinions on tabs vs spaces debate.
- drawkbox 9y agoAnd spaces sub factions/opinions on 2 vs 4 spaces. The correct answer is whatever the project is already using, unless it is new and then you luckily get to choose.
- tom_mellior 9y agoDo they? All the Python folks I've ever seen express an opinion on style have said "follow PEP 8". Unsurprisingly, PEP 8 does have a rule for tabs vs. spaces: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces (spaces, of course)
- jwilk 9y agoAs a data point, I don't follow (all of) PEP-8. But tabs vs. spaces is indeed a bad analogy, because of course it's 4 spaces. ;-P pycodestyle, the Python style checker, has a few checks disabled by default (because there's no consensus they're good ideas), and even some mutually exclusive ones: https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes https://pycodestyle.readthedocs.io/en/latest/intro.html#erro...
- sireat 9y agoI love Python but as a long time C programmer I can't understand the preference for spaces in PEP 8. Tabs are semantic and only take one key press for movement back and forth and to delete. If you see 1 tab you know it meant one indentation level. With spaces you have to think. Plus with spaces you are stuck with 2/4/8 spacing(unless you reformat), with tabs you can configure your editor to your preferences.
- slaman 9y ago> with tabs you can configure your editor to your preferences. Configure 1 tab to be 4 spaces. Sometimes it's easier to go with the flow. I like tabs for the reasons you mentioned, but fixed-width spaces are a bit better for some reasons too. IDE's can do the heavy lifting of re-formatting indentation levels and converting tabs to spaces for me, and it means if I cat a file on a remote server regardless of the bash tab width settings or if I'm in your code or the stdlib it will all make sense.
- e12e 9y agoTabs are semantic. But, when you start down that route, why not dictate record-separotor as replacement for closing brace/block etc?
- bunderbunder 9y agoThese religious wars can largely be swept away with one simple, practical question: What is going to result in less noise in pull requests and the commit history, given that nowadays everyone uses a different editor with different configuration defaults, and is going to result in less time in pull requests squabbling over these kinds of formatting issues, given that nowadays everyone uses a different editor with different configuration defaults? Tabs vs. Spaces has a fairly good answer that flows out of this way of looking at things. There is a counter-argument to that answer, but it is invalidated if you move toward conventions for argument lists and chained method calls that are also designed to limit noise in the source control system. IMO, the argument about bracing also has a practical, non-religious answer once you start looking at your coding conventions this way.
- jjgreen 9y agoBoth!
- kevin_thibedeau 9y agoThe war is over. Py3 doesn't allow mixed spaces and tabs in the same file. You choose your side and never get to skirmish with the other one.
- zerostar07 9y agobut biased fans of both would argue that opening and closing a block in the same indent level (allman-style) is closer to python.
- lisper 9y agoThe irony is that Python actually has open-braces, but they're spelled ":" instead of "{". And the syntax effectively enforces K&R style. When I write Python I end every block with a "pass" statement so that emacs can auto-indent my code properly. The "pass" statement thus effectively becomes a close-brace. It drives Pythonistas into conniptions, but I never have to worry about reverse-engineering a block of code to figure out how to restore the proper block boundaries after a cut-and-paste has screwed up the indentation.
- deleted 9y ago[deleted]
- kamaal 9y agoThat's the bad part of not having braces. If boundaries exist they need to be clear. One shouldn't have to count the tabs that make up the level of indentation. Its already a challenge reading code. Counting invisible tabs makes it even worse.
- lisper 9y agoWell, you don't have to literally count them, you use the spatial reasoning hardware built in to your retina and visual cortex to just see that this bit of code is further over to the right than that bit of code. But of course that only works for pieces of code that are small enough to fit in your field of view.
- dorgo 9y ago
- sethgecko 9y ago>>> from __future__ import braces SyntaxError: not a chance
- laythea 9y agoTell them braces are visual indicators of blocks of logic, enabling reasoning more easily on a multi-statement level.
- threatofrain 9y agoLambdas shouldn't be more than one line anyway.