15

When I started programming ~5 years ago.

Teacher: OK, C++ classes and structs have 3 access modifiers: private, public and protected.
Private fields can't be accessed out of the current class.
Me thinking: wow, that's cool, but how can it be? I have to research.

I went to home and wrote a class with one variable with its set and get functionality.
Then I opened Cheat engine) and tried to access and change the variable. When I succeeded, I started hating this world of programming.

After some time I understood that it's wonderful cause it's up to you.

Comments
  • 5
    I don't think the idea of access modifiers is to be "absolute rules" but more of a guideline in source code for "hidding" some complexity thus providing a cleaner interface.. Of course it is still data saved somewhere on the disk in it's raw, uncrypted format, it would be kind of pointless to crypt and hide private fields in eaxh program, don't you think?
  • 0
    I had a hard time grasping the whole private thing as well, my teacher kept saying that you hide certain parts from the programmer implementing your class yet the whole class is visible to everyone.
  • 0
    @Fulton Yeah been there. I hope my explanation makes more sense.

    Private is something not visible to the outside, because its needed for a core functionality for the class itself. You having direct control over that variable is either pointless or dangerous.

    Public is stuff you want to present when talking with other objects, you offer them your functionality and information. Keeping it real and only show stuff important to them.

    Protected is stuff you dont want anybody else to have access to really, so you only pass it on to your kids. If they access it it's totally fine but if other objects have access to that, it probably leads to confusion and it's probably very dirty code violating access rules.
  • 0
    It's actually pretty cool you used a CE in order to test it... Admirable
  • 0
    In order to protect your app you need to strip variable names. It will definitly help in cheat engine if you search for name of that var. It wont help if you are looking for changing value :(. You need to encrypt tgat variable then or split it in different memory locations.
Add Comment