Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Public vs Private (vs Protected)

Name: Anonymous 2011-05-19 20:39

Alright /prog/, do you prefer to default your class' members to public or private and why?

class dude : person {
public:
  int var1, var2;
};


or

class dude : person {
  int var1, var2;
};

Name: Anonymous 2011-05-19 20:40

public everything

Name: Anonymous 2011-05-19 20:42

Pig disgusting OOP in a pig disgusting language used by a pig disgusting imageboarder or outsider that can't understand the purpose of private, public and protected, and has never tried a real OOP language like Smalltalk or Io.

Name: Anonymous 2011-05-19 20:44

Your class should only be accessed by interfaces and only the members exposed said interfaces should be public.

Name: Anonymous 2011-05-19 20:46

>>3

Yes, public, private and protected all have their own uses. However, the question remains what one should use as a default for good practice when any in particular would work just as well.

Also, I've used Ruby. It's pure OOP and doesn't have the shit syntax of smalltalk.

Name: Anonymous 2011-05-19 20:48

>>5
Ruby is fucking Perl with classes.

By the way, there's no default, and having mutable state is bad anyway.

Name: Anonymous 2011-05-19 20:48

>>4
>only the members exposed said interfaces should be public

Can you fix that grammar a little?

Name: Anonymous 2011-05-19 20:50

>>7
Quote properly, a space after >.

Name: Anonymous 2011-05-19 20:51

>>6
>Perl with classes

No... No that would not be correct. The syntax (and speed) is much closer to python than perl. Also, applying "with classes" to ruby is a serious understatement, because everything is an object including lambdas.

Name: Anonymous 2011-05-19 20:51

>>7

My apologies, I got a little too excited.

>Your class should only be accessed by interfaces and only the members exposed by said interfaces should be public.

Name: Anonymous 2011-05-19 20:57

>>10

So what's wrong with making everything public except when needed?

Name: Anonymous 2011-05-19 21:09

>>11

The idea is to retain control over your classes. Consider the default to be private and you need a reason to go to higher availability. While using interfaces prevents users from using your implementation, it doesn't help if someone inherits your class.

Name: Anonymous 2011-05-19 21:23

I prefer to use Common Lisp's packages instead of classes. They much more simplier and more robust. Alas, CL's standard library does make-hash-table and make-array, instead of more elegant hash:new and array:new.

Name: Anonymous 2011-05-19 22:08

>>12

Okay, and what is your opinion on using getters/setters?

Name: Anonymous 2011-05-19 22:14

>>14

(car xs)
(rplaca xs x)

these are nice.

Name: Anonymous 2011-05-19 22:16

>>12
The idea is to retain control over your classes.
Just name your classes as CShitV1_0, CShitV1_1, CShitV1_2, etc.. Every new release can change everything without problem.

Name: Anonymous 2011-05-19 22:17

>>16
Microsoft does this with DirectX and other system dlls. Works like a charm.

Name: Anonymous 2011-05-19 22:27

>>15
Stop using Lisp as trolling device.

>>16-17
Don't forget the NULL, NULL, NULL, NULL, NULL, NULL, on method calls.

Name: Anonymous 2011-05-19 22:46

>>18
Don't forget the NULL, NULL, NULL, NULL, NULL, NULL, on method calls
C/C++ cannot into &key and &rest, so you must endure.

Name: sb 2011-05-19 22:51

Always use private and use getters and setters unless it is a private class. Trust me, things will change in the future and you will want to be able to change your implementation without having to change all the code that uses your class.

Name: Anonymous 2011-05-19 22:53

>>20
Functions delay binding; data structures induce binding. Moral: Structure data late in the programming process. -- Alan Perlis

Name: Anonymous 2011-05-19 23:35

I'll sometimes keep things public for the sake of convenience with debug statements. A better solution would be to just write a super debug printing function for each class. I try to keep as much as possible private though, just so I have less to think about.

Name: Anonymous 2011-05-20 1:36

I like struct.

struct dude : person
{
    int var1, var2;
};

struct is public from default.

Name: Anonymous 2011-05-20 1:42

>>23

Yes, but structs don't have methods and don't really exist outside of C, C++ and Objective C.

Name: VIPPER 2011-05-20 3:53

This thread is bad, please kill it.

Don't change these.
Name: Email:
Entire Thread Thread List