19 ms·
Totally disagree with you.... it's funny though that I read LOC as "level of complexity" not "lines of code". I've been writing code for 30 years and I think i
by optimuspaul 9y ago
Totally disagree with you.... it's funny though that I read LOC as "level of complexity" not "lines of code". I've been writing code for 30 years and I think it's jarring when the braces are on the next line, so much easier for me to parse that when it's on the same line. But everyone is entitled to their own opinion.
- alunchbox 9y agopython 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.
- kstenerud 9y agoI've done a number of informal tests on friends and family over the years regarding brace placement, and it's always been the same: For someone with NO experience programming (i.e. looking at what to them seems like a bunch of gobbletygoop - and what's a "text editor"?), adjacent braces make it appear more readable than same-line braces. It's only people who cut their teeth on adjacent bracing that find it more readable.
- falcolas 9y agoWhy optimize for the lowest common denominator? I've seen both, and the reduction in vertical whitespace matters more to me than the readability to an untrained individual.
- RobertRoberts 9y ago>Why optimize for the lowest common denominator? You seem to be erroneously equating a coincidence with a preference.
- hailk 9y agoI'll be flipping the point around by saying that if you are concerned about vertical whitespace reduction, you should probably look at the granularity of your files (debatable based on programming environment). Also we could be catering to the lowest common denominator by worrying about people with untrained symmetric sensibility.
- z3t4 9y agoTip: Tilt your wide screen so you get more vertical real estate.
- ainiriand 9y ago'I've done a number of informal tests on friends and family' You should have a pretty cool family!
- psyc 9y agoI've also been coding 30 years. I have to use same line at work, and I use next line in my (very large) side projects. Honestly, I don't know what the difference is.
- JackFr 9y ago> (very large) side projects How big once you remove all the extra newlines?
- ccvannorman 9y agoLOL. This is the part of the Silicon Valley episode-bar-scene where the fight breaks out. Thank god OC didn't mention "Just like you move from tabs to spaces."
- YSFEJ4SWJUVU6 9y agoWell, he shouldn't have, considering it's the other way around.. :-)
- torstenvl 9y agoI never understood this part of the show. I'd think that the genius inventor of a breakthrough compression algorithm whose WHOLE POINT was high quality lossless compression would prefer spaces over tabs. After all, the compression algorithm can deal with it... without the issues that result from embedding hard tabs in a source file.
- ivanhoe 9y agoIn last 20+ years I've changed the coding style many times, usually to fit the current team style. And in my experience it takes a few weeks for the brain to rewire to the new style. First you hate it, and then you get used to it, and then you're like: wow it's great. Then you switch the standards for a new project and again, the same steps. It's just a matter of habit...
- josephv 9y agoPragmatic programming has lost. If you aren't a zealot about being pedantic, just move into the old-folks home.
- ravitation 9y agoI enjoy zealous pedantry. I have strong personal opinions about something that I do a lot (especially the pedantic parts), but most of it is relatively lighthearted.
- Zyst 9y agoNot at all, I'd argue this whole Tabs/Spaces, bracket placement, single/double quote discussion should be getting killed by code formatters. At the end of the day you can do whatever you want with the code you're writing, and some pre-commit hook can run go fmt/prettier/whatever and then it'll all get standardized. I've become a very heavy proponent of code formatters (I added prettier to the entire team) and I truly believe that talk about code formatting will never really die off, but at the end of the day you can do whatever you want on your side but still have a standardized looking codebase, and that feels extremely liberating to me. As a PS: If you are a diehard tab proponent/different bracket placement/whatever but your team formatter configuration uses spaces instead then you can also use code formatters to do spaces -> tabs locally, say, on file open. Once you commit your file your precommit falls back to the team configuration, which removes your tabs. Everyone is happy.
- cortesoft 9y agoI think the person you are responding to was being sarcastic...
- brann0 9y agoI always adapt to the style used in the project I land. I can understand people liking one over another but to reach holy wars levels of disagreement about this kind of subject is something I don't get. Same goes to spaces vs braces, editor wars, etc. Downside: my projects are usually a bit of a mess with mixed indentation styles :D
- DanHulton 9y agoI've actually evolved a hybrid style in my personal projects - next line for functions/classes, same line for blocks. To me, it looks weird when functions don't have that extra line of space to set off their definition, but if/while/whatever aren't special enough to need that call out. That said, the most important factor is simple consistency. In my person projects, I have the hybrid style. At work, I use same-line-only. If I'm on a project that has next-line, we all use next-line.
- nitrogen 9y agoI think the Linux kernel style is similar. That was the first coding standard I somewhat adopted, but naturally have adapted to many others on different teams over time.
- erik_seaberg 9y agoI think this style dates back to K&R C where you (maybe) declared argument types after the parens. int max(a, b) double a, b; { return a > b ? a : b; }
- Bombthecat 9y agoI remember in my programming classes at school my teacher was always like: guys!there is space on the right! Use it! PS: he coded at Hercules the graphic cards back in the day before he got into teaching.
- z3t4 9y agoWhat is "Hercules the graphic cards" (I only found GPU's when trying Google)
- mr_toad 9y agoThe Graphics Card (HGC) was essentially an MDA-compatible monochrome card with an added all-points-addressable graphics mode. https://en.wikipedia.org/wiki/Hercules_Graphics_Card https://en.wikipedia.org/wiki/Hercules_Graphics_Card
- deleted 9y ago[deleted]
- boomlinde 9y agoThe level of complexity obviously doesn't change with a line break