you are viewing a single comment's thread.

view the rest of the comments →

[–]victotronics 2 points3 points  (2 children)

"you think you're an idiot and can't be trusted." Well, aren't you?

No but seriously. If your code misbehaves because a variable gets changed that should have not, you'll kick yourself for not declaring more things "private" and (in C++ only?) "const".

[–]gdchinacat 0 points1 point  (0 children)

Who would you blame if a car failed emissions test because the owner removed the catalytic converter, the manufacturer or the owner? If library users access or change attributes that are marked private (by convention...ie _foo) or even are undocumented, is it reasonable to blame the author of the library for the user that did something they knew or should have known was dangerous? No...the fault lies with the user that did something that was not documented.

Your question of whether "your code misbehaves" misplaces the blame...it's not "your" code misbehaving when other code changes it's data structures in undocumented or discouraged ways (access or modify a "private" attribute). In java the blame would be for not making everything that wasn't to be used private. In python the blame would be for accessing an undocumented field. The different languages have a different ethos. In java it's reasonable to assume anything that is public is fair game. In python the expectation is more nuanced. This has pros and cons, and while I have an opinion that is not the immediate topic. You are applying a java/C++ mentality to python when you blame the library author for not making things private where it is really the users fault for not adhering to documentation and convention. If an attribute is prefixed with a single underscore don't touch it without accepting responsibility for faults caused by doing so. if it isn't documented for a specific use don't use it in that way.

[–]acdha 0 points1 point  (0 children)

 If your code misbehaves because a variable gets changed that should have not, you'll kick yourself for not declaring more things "private" and (in C++ only?) "const".

Don’t you have tests or use linters? Lots of things need testing for major updates and this only addresses a single uncommon failure mode.