Today I learned something in Python that genuinely surprised me… In languages like Java or C++, if you mark a variable as private, it’s strictly enforced. You simply can’t access it from outside the class. But in Python? -- 𝗡𝗼𝘁𝗵𝗶𝗻𝗴 𝗶𝘀 𝘁𝗿𝘂𝗹𝘆 𝗽𝗿𝗶𝘃𝗮𝘁𝗲. Even if you use __variable, you can still access it using name mangling if you know the class name. At first, I’ll be honest — this felt wrong. I thought: “Why would a language not let me fully protect my data?” But then I came across a simple line that completely changed my perspective: “𝗣𝘆𝘁𝗵𝗼𝗻 𝗶𝘀 𝗺𝗮𝗱𝗲 𝗳𝗼𝗿 𝗮𝗱𝘂𝗹𝘁𝘀.” And suddenly… it made sense. Python doesn’t enforce strict access control because it follows a different philosophy: • We are all responsible developers • We respect conventions • We don’t break things just because we can In Python: _variable → means “this is internal, please don’t touch” __variable → adds name mangling (stronger hint, not a lock) But ultimately… • It’s based on trust, not restriction • And honestly, that’s kind of powerful. Instead of forcing rules, Python assumes: “You know what you’re doing.” 𝗠𝘆 𝘁𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Good code isn’t just about what a language allows or restricts… It’s about discipline, readability, and intent. #Python #Programming #SoftwareEngineering #Coding #Developers #Learning #CleanCode
Adults: I want a lock Python: Here it is. But if you try a little harder with a twisted key, it will open. Adults: that's not a good lock. Python: But I made it for you. Adults (amongst themselves): Do you think we should check that Rust or Java shop?
Well put 🫡
I mean its the same reason with const. if something you want const just make the variable capital letters and you know you arent supposed to change it