this post was submitted on 21 Mar 2024
621 points (94.9% liked)

Programmer Humor

19698 readers
103 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 38 points 8 months ago (1 children)
[–] [email protected] 2 points 8 months ago* (last edited 8 months ago) (1 children)

Huh, do Java and other oop languages have them too and what are some good reasons to use them?

[–] [email protected] 3 points 8 months ago (1 children)

It allows for more fine grained access control and to implement afterthoughts.

Think having some private function that can break things if called improperly, but also allow you to avoid significant overhead when calling it the correct way. For example you could be avoiding input validation in a public wrapper for that function. If your friendly class already does it, or cannot produce invalid inputs, there is no need for that.

You could also implement logging after the fact, because your friendly logger object to read private members.

Arguably it's a questionable design decision tho, as you could do all of this in other ways and it basically breaks any guarantees private would usually give you.

[–] [email protected] 1 points 8 months ago

That was a problem I saw with it but I guess it's useful too. I like structs.