Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think OP meant discarding public/private constructs entirely, no protection, like in python.



Except python started mangling double underscore in a futile attempt to implement private members/methods.


The underscore prefix is more about communication. It's not a bad convention as it makes you feel a bit dirty when you are using them outside a class, but, do what you want, we are consenting adults.

Whenever I say "I'm no longer attached to all that private stuff", people always reply, "wait until you work on a large code base". I work on a million line+ code base. Whatever.

This argument aside, I'm not a total philistine. RAII is awesome but C++ is full to the boot with crusty stuff to keep the compatibility. I always feel there is a language better than anything trying to come out.


Python will literally mangle the names of double underscore members by prefixing them with the class name, to make it harder to access from the outside, so it is not just about communication.

These days I'm for minimalism, most of my structs are aggregates of public members, but sometimes you really want to make sure to maintain the invariant that your array pointer and your size field are in sync.


Using double underscore is advised against, and the name mangling is largely considered a mis-feature these days. Most style guides will tell you to use a single underscore to mark something as not for public consumption.

Of course neither double nor single underscore will stop anyone who wants to touch your privates badly enough. Which is big part of the python philosophy: You're not stopped from doing inadvisable things. Instead there's a strong culture around writing "pythonic" code, which largely avoids these pitfalls.


And neither does C++'s 'private' stop any other code from messing with your data, either, if they want to do that badly enough.


I'm not super familiar with C++, but I imagine you'd need some chicanery to access privates, while in python you can just use them by name.


Well, you can always cast and access stuff by memory address.


I can't rally upvote this without breaking the rules about obscenities. But I'll give it a :)

In python, if any of this gives you an trouble you can just replace the stuff in the class dict with your own functions. You don't even need to cast.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: