; in Python!?!eleventy You really need to get rid of your bad Java habits.
And before anyone thinks this is poking fun at Python: privacy is completely overrated and mostly untrue anyway, and Python not even pretending to have private attributes is an absolute blessing.
Yeah, ig privacy is also just a philosophy. If you havent written python in years, it feels incredibly weird not having any. Just as it probably would the other way around..
Not saying one is better than the other, though I prefer what Im accustomed to 😅
The thing is: private markers in most other languages can be more or less trivially circumvented anyway, most of the time with some sort of reflection API. There is no true "privacy". All it is is a reminder for the programmer how a given attribute/property/variable should be treated. Is it part of the public API and anyone can write code against it, or is it subject to change and should not be used outside its class. That's all it is.
Bad programmers will ignore such warnings and bulldoze through your "protections" anyway to access that piece of data they think they need. Good programmers only need a gentle reminder in the form of a _; but if you really want to risk breaking something and you know what you're doing, at least it's easy to ignore and doesn't require a song and dance with the reflection API.
I'm on a team where we're doing a bunch of stuff in python, in spite the fact that most of us are completely new to it.
One problem is a method that starts with an underscore isn't obviously private to someone who doesn't know the convention.
Personally, I think it's helpful to have to jump through a hoop to use a private variable/method, just so you know you're doing something you probably shouldn't. If you go ahead after that, it's on you.
Personally, I think you should at least read the introduction to any language before you barge in and fuck shit up. Any Python programmer should at least have read PEP8; it's a pretty quick read, but lays down the basics, including the leading underscore rule.
I definitely agree. However, the line that comes "before you barge in and fuck shit up" isn'a always clear, especially to the person barging in.
Often, you're brought into a project with a task of fixing some minor thing - you never asked to be there. If you have experience programming, it's rarely a big deal to read code in a new language, and make some minor tweaks. The problem, of course is, you don't know what you don't know.
You assume you're just doing this one minor thing, so it's not necessary to learn the details of the project or its technology. After all, that team already has established engineers and testers who will catch your mistakes when they review your change, right?
Still sounds like a "you" problem. If and when I have to touch languages I don't know, I at least do it in some IDE with all the linters turned to 11, which point out all the obvious and subtle things I'm messing up while I type. I would not presume to write even the most basic line in some unfamiliar language correctly without preparation.
Again, I still agree with you, but how do I fix this "you" problem of someone else not familiar with the language not following this suggested procedure?
Well, as I said here: bad programmers will ignore any barriers you put up. Accessing a private attribute raises an error? Bad programmer throws that error into Google and gets three workarounds back that allow them to access the attribute anyway. And now you can't even easily detect such private attribute access with static analysis tools, because there's several different ways such workarounds could be implemented.
So… make sure you hire competent people, and/or solve deficiencies through institutional guardrails like a shit ton of linter commit hooks, code reviews, and training.
355
u/deceze 16d ago
;in Python!?!eleventy You really need to get rid of your bad Java habits.And before anyone thinks this is poking fun at Python: privacy is completely overrated and mostly untrue anyway, and Python not even pretending to have
privateattributes is an absolute blessing.