General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Anony Mousse
Low Level
comments
Comments by "Anony Mousse" (@anon_y_mousse) on "how Google writes gorgeous C++" video.
I should probably read that style guide because a lot of these things I already do in my own code. Two spaces for each indentation level and I've set my tab key to insert four. Plus, since vim has dedicated keys for it I can increase or decrease indentation levels with ease. Need to push right 3 levels, 3> and done. Anyone that thinks tabs are superior should read that guide.
5
Indentation is alignment. It's utterly stupid how many people don't seem to understand that, and that tabs being different per user is in fact a problem.
2
The biggest problem with tabs is that different people "require" different sizes for their tabs. Indentation is alignment and changing alignment causes problems. I don't buy the accessibility argument, especially since every editor can generate visual cues to indicate whitespace, but that you said "easily understand" makes me think it's not even a valid accessibility issue at all, but rather a laziness of reading issue. Although, truthfully if someone can't understand the code when they read it, I wouldn't want them on any team that I manage because they'd be a hindrance to development.
2
@freeasinbeer Because each indentation level will change the alignment. It might be fine for tables, but all other forms will skew.
1
@freeasinbeer If you're stacking spaces onto tabs, you're still doing it wrong. If you're not wrapping long lines you're doing it wrong and that's one of the points where you get into trouble using tabs. Not only should you not be using tabs, but you especially shouldn't be mixing them.
1
You're kind of both right and wrong. Consider that division by zero will cause an exception to be thrown no matter what language you're using because it's baked into pretty much every processor. For instance, C doesn't have exception handling, you need to account for such an error in a different way. So while you are stuck with exceptions, it's not because the standard library uses them, it's because you can't get away from them on modern computers. However, you don't have to "account" for them in your own code. You could just write code that never generates them or you could ignore that they exist. I'd strive for option 1, but that's more difficult in C++ when new can throw them. Although, I rarely see people wrap new in a try/catch block, so it looks like not many care.
1
Yep, C++ requires casting malloc, which is dumb. Generally you shouldn't even use malloc in C++, though.
1
@pauljarski7590 It's because of the "stronger" typing of C++. In C you don't need the cast and truthfully that makes more sense especially considering all of the implicit conversions that normally occur in C++.
1
The difference is that spaces maintain consistency whereas tabs do not. If I set my indentation at 8 and you at 4 things will not align correctly between our screens, but if I use spaces you will see my code the way I see it and there will be no confusion based on alignment.
1
@tylerkropp4380 No, because if your editor is set to something different the code will not align correctly. How is this a difficult concept for people to grasp? Spaces are the only logical choice for consistency.
1
@tylerkropp4380 Are you mentally handicapped? If you're reading someone else's code and working with it and they and you both use tabs and your tab-width is configured to display as 4 spaces wide and theirs 8, then the alignment will be distorted. If the one who writes the code uses spaces instead of tabs, the alignment will work regardless of how many spaces wide you set your tabs to be.
1
@rubenverg When you have to align your code across lines. If you've never had to do it then you must be new.
1
@rubenverg No, you're thinking of tables where the indentation will be the same from one line to the next. If you're not doing a table the alignment will vary, especially with wrapped lines unless you're wrapping them the wrong way, which let's be honest, if you're fighting this hard for tabs you are, and if you're not wrapping long lines then you're doing it wrong.
1
@rubenverg That's one of numerous possibilities, and yes, tabs would not work correctly for such a case.
1
@rubenverg And like I said, if you're stacking spaces on tabs you're doing it wrong. They should never touch because that's how misalignment will propagate between users.
1
@rubenverg So everyone uses the same tab width that you work with. Got it. In larger teams, especially if you work in a corporate environment, it won't always be that way.
1
@rubenverg In that single example, sure, until two people on the team have different tab widths and start modifying the code.
1
@rubenverg Let's say you've got three characters for a type name and you use three characters for your tab width, you might just decide to press tab to indent from the type name and not give it a second thought and not realize what you've done wrong because they're invisible characters. Then let's say someone with 8 character tabs comes in to edit it, it'll look wrong. But that's just one example. Of course, if you used spaces for indentation and set your editor to insert spaces when you press tab, it won't matter how many times you indent, it'll always be the same. And good editors, like vim, and probably emacs, will actually allow you to set format control strings in the file itself to handle the differences per user. So the visibility of a space versus a tab will be irrelevant if everyone just uses spaces and sets the standard for the project.
1
@rubenverg I use vim and spaces, and I have no problems with my code being used by others. And I'd like to know what editor recognizes tabs to indent then switches to spaces when you're no longer wanting to indent. I know the answer is none, which means you'll either use tab for internal alignment, which is wrong, or you'll be pressing space a ton to align, which is also wrong.
1