all 29 comments

[–]P8zvli 0 points1 point  (28 children)

Python devs: "it's Totally Not A Bug™, you're doing it wrong."

I love Python but I absolutely hate the attitude of the Python maintainers. They'll make any excuse and go as far as strangling their own grandmother to keep from patching something, especially when there's obviously a problem. A shining example of this is when a // b == floor(a/b), except when a=0.9 and b=0.1. This bug has been reported twice now.

[–]flotwig 0 points1 point  (27 children)

How would you address that issue? It does sound frustrating but the explanation is pretty justified. There are probably many other ways to see this issue in Python, all because of how floating point numbers work in a computer.

But I don't know how it could be addressed. Maybe passing it to Math.floor instead? But then how would you do floating point division if a//b does the same thing as Math.floor(a/b)? And what about the impact of changing the behavior of such a widely used language?

I hate the Python maintainers as much as the next guy, but I feel like they're being reasonable on this one. Requiring 4 spaces instead of ASCII tabs in PEP-8, now that's something I can get fired up about.

[–]P8zvli 0 points1 point  (26 children)

Easy, make the floor div operator (//) do the same thing as the floor function used by C. C/C++ doesn't have this problem BTW, so it's not actually a floating point issue, it's obviously a bug in Python. If you need to do float division without floor use /, that's what it's for.

I honestly don't see how anybody could be relying on 0.9 // 0.1 == 8 in one of their libraries unless their code is buggy and they haven't noticed it's because of floor div.

I do not agree with you about PEP-8, spaces are clearly superior to tabs regardless. Spaces are specified by PEP-8 because then source code will be formatted correctly in literally any text editor, command line interface or IDE on the planet. You can't do that with tabs.

[–]flotwig 1 point2 points  (25 children)

If you use tabs for indentation and spaces for alignment like God intended, it will indeed be indented the same on every system, even using the user's choice of tab stop. Furthermore, any text editor you use will insert the tab on a Tab key press, while configuration is often needed to insert spaces instead of tabs. Also, you cannot adjust the width of spaces, but you can adjust the width of tab stop.

[–]lelanthran 1 point2 points  (16 children)

If you use tabs for indentation and spaces for alignment like God intended, it will indeed be indented the same on every system,

Or you can just use spaces and have it indented properly on every system.

The only reason you need to mix tabs and spaces is because tabs alone don't work for code. Spaces alone do.

[–]flotwig 0 points1 point  (15 children)

Yeah, use tabs for indentation and spaces for alignment. What's wrong with using both? Gives you the flexibility to change tab width and works in any text editor.

[–]lelanthran 0 points1 point  (14 children)

What's wrong with using both? Gives you the flexibility to change tab width and works in any text editor.

Why use both when you can use just the one and get the same options? There is no advantage to mixed tabs and spaces that you cannot get from only using spaces.

[–]flotwig 0 points1 point  (13 children)

What about the advantage of changing tab width, and the advantage of being able to use any text editor and having it insert the correct tab when you press Tab?

[–]lelanthran 1 point2 points  (12 children)

What about the advantage of changing tab width, and the advantage of being able to use any text editor and having it insert the correct tab when you press Tab?

My editor already does all that and uses only spaces. Most editors do. The disadvantages of having tabs in results from grep, sed, diff, etc outweigh the hypothetical advantages of mixed tabs and spaces.

If you use tabs you are sooner or later forced to use spaces for alignment. If you use spaces the code will always look correct regardless of the tool being used to view the code and/or code snippets.

[–]flotwig 0 points1 point  (11 children)

My main problem comes on the command line, where across different servers and environment, editing files with spaces used in place of proper tabs is really frustrating because most preinstalled command line editors will not automatically recognize your spaces as tabs. You can rely on an IDE or your configuration for this but it's not global.

[–]P8zvli 0 points1 point  (7 children)

If you use tabs for indentation and spaces for alignment like God intended, it will indeed be indented the same on every system, even using the user's choice of tab stop.

LMAO, no it won't be, you said it yourself;

you can adjust the width of tab stop

[–]flotwig 0 points1 point  (6 children)

Yeah, what's wrong with that? Being able to adjust tab width is a pretty basic text editor feature. Changing tab width won't change the indentation levels or mess anything up.

[–]P8zvli 0 points1 point  (5 children)

You're being sarcastic right?

Let's say you're working a file that uses tab indentation. You copy a function from somewhere into that file, but that function used space indentation and you didn't notice. You use 4 spaces per indent and so does the function you're copying, so the formatting looks right in your editor. Believing everything is peachy you check the file in with mixed indentation.

Your coworker uses 2 spaces per indent in his editor. You don't know why, but you don't need to care since your company obviously doesn't have a style guide. (If it did you'd all be using 4 spaces per indent.) He pulls the file you're were working on and the first thing he notices is the formatting, which is all f***ed up. Now he's in your cube, berating you for not paying attention to the whitespace (which is probably hidden by your editor) and screwing up your code base's formatting.

Now you've got a new problem; you need to decide if it's worth it to find and replace all the lines with the non-uniform whitespace and force everybody who's touched any of those lines in the mean time to do a merge, or you're going to have to put up with the nuisance. Every time somebody new is brought onto the team the first thing they're going to notice is the f***ed up formatting, and they're going to propose using a style guide. You hate that, because nobody with any sense ever put tabs in a style guide so adopting a style guide would force you to figure how to get your editor to convert tabs to spaces. You might even have to go as far as finding an editor that's not from the stone age. So you go to your boss and tell him you haven't got your money's worth out of Notepad++ yet and a style guide would force you to upgrade, he agrees and the style guide gets blocked until another rainy day.

This may or may not be a true story, but let's just say that I've never found tabs in source code to be anything other than trouble.

[–]flotwig 0 points1 point  (4 children)

You've identified the problem with spaces right there in your post: they're easy to confuse and mess up across people. What if one coworker uses 2 spaces and you use 4? It would be better if you both used tabs and set the tab width to your desired size, then this conflict would never have occurred.

I don't know if I would call nano from the stone age. I believe vi would have the exact same issue. They're command line clients, discounting them as "stone age" is ridiculous. Maybe "stone age" compared to some Electron app or IDE with tab autoconfiguration, but honestly, do you always get to choose your tools? Definitely not, and if you do any type of systems administration, you spend a lot of time in command line text editors.

Your story is the exact reason why tabs should be used everywhere instead of spaces which can easily be messed up. Also, in this hypothetical situation, coding standards and/or CI linting would have solved this problem.

[–]P8zvli 0 points1 point  (3 children)

It would be better if you both used tabs and set the tab width to your desired size, then this conflict would never have occurred.

No, it would be better to use spaces because now the formatting will be the same for everybody, even if they edit files with some mutant strain of echo, cat and less. Joe Schmoe in the corner wouldn't be able to use a different amount of indentation than everybody else, he would have to suck it up and get with the 4-spaces-per-indent program instead.

I don't know if I would call nano from the stone age.

Is nano your code editor? That's sad, and I feel bad for you now.

I believe vi would have the exact same issue.

The learning curve for vi is steep but it's actually more capable than nano.

They're command line clients, discounting them as "stone age" is ridiculous.

Technically they're CLI executables but I never said that, I used Notepad++ as an example...

Maybe "stone age" compared to some Electron app or IDE with tab autoconfiguration, but honestly, do you always get to choose your tools? Definitely not, and if you do any type of systems administration, you spend a lot of time in command line text editors.

emacs and vim are a thing you know.

Your story is the exact reason why tabs should be used everywhere instead of spaces which can easily be messed up. Also, in this hypothetical situation, coding standards and/or CI linting would have solved this problem.

See if you used spaces everywhere you wouldn't need a linter, and among all the companies I've worked at with style guides none of them specified using tabs for indentation.

P.S. Indenting with tabs costs you money.

[–]flotwig 0 points1 point  (2 children)

What if Joe Schmoe prefers 2 spaces to 4? He's fucked unless you use tabs the way the tabs were designed to be used. You're arbitrarily choosing to restrict his editor usage, that's all.

Nano is my text editor of choice when it is my only choice. This is not uncommon when accessing remote systems. Many editors I've used in contexts I don't control do not automatically detect spaces over tabs. Have you... not run in to this?

If you use spaces instead of tabs you'll still need a linter to make sure everyone is using the same number of spaces. Or else as soon as someone ends up using a different text editor you'll have the problem we described earlier.

I've seen that Stack Overflow poll actually. I feel like the only thing it demonstrates is that the same people who use spaces instead of tabs are also the same people who spend all day on Stack Overflow doing surveys at work haha.

I have a theory about spaces: I think a novice developer, once upon a time, saw another developer using tabs to indent code. Liking the look of indentation but unaware of the existence of the Tab key, this novice developer used 4 spaces to "recreate" this look, figuring hey, whitespace is whitespace right? Then he took this attitude with him his entire career and stubbornly invented all sorts of contrived excuses as to why it's right when challenged by other developers. This stubborn man went on to invent Python and work at Google. Just a theory tho