Hello world [Archive] - C Board

PDA

View Full Version : Hello world


zen
11-01-2001, 09:44 AM
using System;

namespace ConsoleApplication
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{

Console.WriteLine("Hello World");

}
}
}

Troll_King
11-01-2001, 10:26 AM
.

Troll_King
11-01-2001, 10:34 AM
.

Java
11-01-2001, 10:47 AM
public class ripoff{

public static void main(string[] args){

System.out.println("Does this look familiar?");
}


}

no-one
11-01-2001, 11:07 AM
the HORROR!!

oskilian
11-01-2001, 08:03 PM
you have to do ALL THAT to make a simple hw app?

do you have to make it all into classes? like Java?

I like the old-fashioned C/C++ better

Oskilian

nvoigt
11-02-2001, 01:54 AM
lol... Java, I'm sorry, but get your stuff together first and learn how to hide your data in classes... It does indeed look the same... a shame that C# manages to be the better implemented language, isn't it :p

quzah
11-02-2001, 08:09 PM
> lol... Java, I'm sorry, but get your stuff together first and learn
> how to hide your data in classes...

How is their Java example 'not hiding data'? There is no data. It
is only a function call.

> It does indeed look the same... a shame that C# manages to
> be the better implemented language, isn't it

How is that better implemented?

using System;

class HelloWorld
{ public static void Main()
{ Console.WriteLine("Hello World!");
}
}


Versus:


class HelloWorld
{ public static void main( String [] args )
{ System.out.println( "Hello World" );

}
}


They're exactly the same except we didn't have a 'using' (ie: 'import').

Quzah.

nvoigt
11-03-2001, 03:04 AM
I'm not talking about "Hello World".

Create class a;
Create class b, containing a private member of class a;

Grant public reading access ( a getA() function ) that
does not allow modifying private data, allows reading
it, and does not create a copy of the data, as that is
not an appropriate solution.

Try and cry.


I did implement examples in the last Java vs C++ thread...
Look them up if you don't want to do this yourself.

Oh, and an easy one: Create a constant object of class a.
( constant means only functions that do not modify class
data may be called )

Xterria
11-03-2001, 12:54 PM
C# is stupid. Why do this when there's java? How the heck do you even pronounce this language anyway?

quzah
11-03-2001, 02:30 PM
It's pronounced "C sharp".

> Grant public reading access ( a getA() function ) that
> does not allow modifying private data, allows reading
> it, and does not create a copy of the data, as that is
> not an appropriate solution.

I hate to rain on your parade, but...

class ClassA
{ private int x;
int getX( ) { return x; }
}

class ClassB extends ClassA
{
}

public class MyProggie
{ public static void main( String[] args )
{ ClassB B = new ClassB( );
System.out.println( "X = "+ B.getX( ) );
}
}


but, um... "What seems to be the problem officer?"

Where's the problem? Please show me what it is I'm not upposed to be able to do here. I seem to be missing what you're saying I can't do. This is Java. This seems to do exactly what you're saying I can't do.

Quzah.

zen
11-03-2001, 04:36 PM
This seems to do exactly what you're saying I can't do.

I don't know java that well, but I assume B.getX( ) in your println() call will create a temporary (a copy of private int x).

quzah
11-03-2001, 04:43 PM
I'm pretty sure that any time, in any language, when you use a "get" function, it returns the value, and thus, always makes a copy of it. The only way around that, would be to return a pointer to the actual variable. If you return a pointer to the actual variable, which I'd be surprised if it let you do, since it is protected, then that's the only way I can think it'd work.

In Java, pretty much everything is a pointer. If you could return a pointer to a protected or private variable, then it really isn't private any more. The whole point of something being private, is so that outside interference doesn't directly access the variable.

I imagine that if you were actually returning a pointer to the variable, then there would be some required additional overhead to limit access to the variable based on what class is using the variable and what not. In which case, that overhead would probably be (guessing) close to the same "overhead" you'd have by just creating a "copy".

A lot of speculation on my part, but it seems resonable.

Quzah.

zen
11-03-2001, 05:03 PM
I imagine that if you were actually returning a pointer to the variable, then there would be some required additional overhead to limit access to the variable based on what class is using the variable and what not. In which case, that overhead would probably be (guessing) close to the same "overhead" you'd have by just creating a "copy".

Yes if you were returning a primitive, but if you were returning a user defined object then returning a pointer would be much more efficient (due to the size of object and the unnecessary copy constructor calls). C++ allows you to return a const reference (or const pointer) and I presume, as this discussion is taking place, that C# can do something similar -

class a
{
private:
int b;
public:
const int& get()const{return b;}
void set(int _b){b=_b;}
};


No copy of b will be made and you will not be able to change b without calling the set method (or cheating).

nvoigt
11-03-2001, 06:04 PM
>This is Java. This seems to do exactly what you're saying I can't do.

Um... please read my post again, it says EXACTLY what to do.
I was talking of class A and class B having a private member
of class A. In Java, you cannot return a reference to this
private ( NON-PRIMITIVE ) member, without giving write access
to your private parts ( ouch :p ). You can either return a reference,
which allows constructs like this:

MyVariable.GetMyPrivate().ChangeItsValue();

Which would change the private members value through a
read-only function. Or you can create a copy and return this,
so it can still be modified, but you don't have to care. But
creating a copy of an object ( imagine said object were
100 MB in size ! ) for each reading access to it is ridiculous.


Another, maybe easier thing: Create a class A. Create an instance of this class, that cannot be modified in the whole program. In C/C++/C# this is called a constant. In Java, you
have the final keyword, which is a joke, because only the
reference is final, not it's object. But then, how could the object
be final when you cannot define which methods change it and
which do not...

quzah
11-03-2001, 06:17 PM
Of course you can't return a private object. That's the whole poing of OO! You can't just expose your private parts to the world! It's illegal! ;)

Seriously, that breaks encapsulation. There is no reason to return private members/expose them to the rest of the program. This defeats the entire purpose of OO design.

Quzah.

nvoigt
11-04-2001, 02:56 AM
class Date
{
// insert usual datestuff here
public:
const char* AsText() const;
void Change( int, int, int );
};

class Person
{
private:
Date Birthdate;
public:
const Date& GetBirthdate() const
{ return Birthdate; }
void SetBirthdate( const Date& d )
{ Birthdate = d; }
};

int main()
{
Person p;
const Person cp;
Date d;

printf( p.GetBirthdate().AsString() ); // perfectly legal
p.GetBirthdate().Change(1,1,2001); // compiler error
d = cp.GetBirthdate(); // legal
cp.SetBirthdate( d ); // illegal, calling non-const function on const object
return 0;
}


This was what I'm talking about. Do this in Java. I don't think
it breaks data encapsulation in any way, it's a perfect little class.

quzah
11-04-2001, 07:33 PM
class Date
{
// insert usual datestuff here
public:
const char* AsText() const;
void Change( int, int, int );
};

class Person
{
private:
Date Birthdate;
public:
const Date& GetBirthdate() const
{ return Birthdate; }
void SetBirthdate( const Date& d )
{ Birthdate = d; }
};


There is a slight problem with your code. Since this is a birthday, you don't want it changing. Face it, people's birthday's never change. As such:


class Date
{ private int d,m,yr;
public void Date( int day, int month, int year )
{ d = day; m = month; y = year; }
}

class BirthDate extends Date
{ public Date GetBirthDate( )
{ return new Date( this.d, this.m, this.y );
}
public void ShowBirthDate( )
{ System.out.println( "" + this.d + "/" + this.m + "/" + this.y );
}
}

class Person
{ private BirthDate b;
//more personal information

public Person( int day, int month, int year )
{ b = new BirthDate( day, month, year );
}

public ShowBirthday( )
{ b.ShowBirthDate( ); }
}

class MyProggie
{ public static void main( String [] args )
{ Person p = new Person( 4, 11, 2001 );

p.ShowBirthDay( );
}
}


That is how the class should be designed. More like that anyway. Yours was poor class design, in that, you are extracting information from the class in a way you shouldn't. A class should be self contained. Anything that you need from the class, it should be able to provide you with access functions.

Yes, it is more work, more lines of code, and takes longer to write;
but, if you want your classes working the way they should, then that (above) is how you'd go about it.

Granted, I just threw that together, so there are probably ways it could be done better. (For example, I should have made the functions return a string, rather than have called println inside it. I was just hacking this together real quick, thus the result.)

Additionally, my Date class could have been done better. For example, I could have used a 'final' setDate class in Birthday, to prevent the date from being changed, something along that line.

Quzah.

nvoigt
11-05-2001, 01:03 AM
>There is a slight problem with your code. Since this is a birthday, you don't want it changing.

Jesus... than rename it to DateOfLastPayment. The problem still stands as I described it.


Do you think giving read access to your privates is wrong ?
If so, have fun programming, you will have a hard time.

class a;

class b
{
private :
a A;
public:
const a& GetA();
};

class c
{
public:
int CalculateResultForAnyA( a SomeA );
};


Get a result from the private of b:

int r = aC.CalculateResultForAnyA( aB.GetA() );


However you do this in Java, you cannot guarantee
that the calculating function will not change the a-object
it gets. The best you can do is create a copy of it, so
changing it has no effect.

mix0matt
11-05-2001, 11:09 AM
quzah,
External objects should not be able to change an object's internal "private" attributes, but it is perfectly acceptable to pass these private and protected values to external objects who request them. That's what a get() method is for, remember? nvoigt's right; it would be nearly impossible to program using objects that do not interact...

>>However you do this in Java, you cannot guarantee
that the calculating function will not change the a-object
it gets. The best you can do is create a copy of it, so
changing it has no effect.<<

nvoigt, i have no experience with java so this might be obviouis, but is there no const keyword? Therefore the CaculateResultForAnyA() method cannot modify the parameters passed to it. basically can you give an example of what you're explaning here. I'm just curious...

nvoigt
11-05-2001, 12:53 PM
>i have no experience with java so this might be obviouis, but is there no const keyword?

*g* You mentioned the problem right head on ;)
Passing is by reference only for objects, and a
const keyword does not exist... now go and build
a get-function for a non-primitive...

quzah
11-06-2001, 01:58 PM
Actually, while they do not call it 'const', Java has 'final', which is the same thing.

class A { //class A
private int x; //some data here
public int getX( ) { return x; }
public void setX( int y ) { x = y; }
}

class B {
private A iA; //private instance clA
public B( ) { iA = new A( ); }
public final A getA( ) { return iA; }
}

class MyApp {
public static void main( String[] args ) {
B iB = new B( );
iB.getA( ).setX( 333 );
System.out.println( "A.x is " + iB.getA( ).getX( ) );
}
}


Now then, THIS does what you say Java cannot do. Keep in mind that I've only been tinkering with Java for a few weeks. (Little of which is actual coding.) Enjoy.

Additionally, you are both missing the concept of OOD. You do not want to have random objects and methods directly accessing your date. I'll admit I haven't done a lot of OOP, so I may be off in my assessment, but I believe the general idea behind OOD is keeping your objects self-contained so that no one who doesn't belong can get their hands on your data.

Quzah.

zen
11-06-2001, 04:11 PM
I don't think 'final' will work, for objects it means the reference can't be used to reference another object like -

char* const a;

would prevent 'a' from pointing elsewhere but wouldn't prevent modification of the value stored at 'a' in C.

nvoigt
11-06-2001, 04:33 PM
>You do not want to have random objects and methods directly accessing your date.

You don't have another chance. You have to grant interfaces to your privates, and a get-function is probably the most renowned way of granting read access to privates, which is fine. You are right saying that you don't want them to access the data for writing.

>iB.getA( ).setX( 333 );

I admitedly don't have a java compiler handy at home. A well implemented compiler should either scream and shout and wave every flag available, or silently step aside and commit sepuku when compiling this line. If it produces executable code from this line, it's crap.

And I assume it will, because the final keyword is not what you would expect from it. Easier question: Create a constant object.
Example:


class c
{
private int i;
public c() { i = 0; }
public int getI(){ return i; }
public void setI( int newi ){ i = newi; }
};

class MyApp
{
public static void main( String[] args )
{
final c C = new c();
C.setI( 555 );
return 0;
}
}


In what way is that C constant ?
You can change it any way you want.
The Reference is constant. The object is not.

quzah
11-06-2001, 06:04 PM
>> iB.getA( ).setX( 333 );
>
>I admitedly don't have a java compiler handy at home. A well
> implemented compiler should either scream and shout and
> wave every flag available, or silently step aside and commit
> sepuku when compiling this line. If it produces executable code
> from this line, it's crap.

Actually, I'm using the Sun Java compiler (1.3 i believe) and it
compiles without error or warning, and executes correctly. The
reason it works is that 'setX' is a public method.

I could have also just done:

iB.iA.setX( 333 );

In either case, the end result is the same. 'iA' calls 'setX'.

In your example using 'final', this means that instance of the class is final. How that exactly works, I am not entirely sure. Perhaps you cannot do:

final c myC = new C( ); //give C an instance
myC = new C( ); //give it a new one

I believe that's what you're looking at there.

If you want an unchangable class, you declare the class as final:

final class C {
}

This means that you can't exctend that class. Thus:

class D extends C { //this is invalid
}

Anyway, going from the book I have, "Core Java 2", which is used for certification, they state that 'final' is basicly the same as 'const'. I'm at work now, and the book is at home so without going to http://java.sun.com and hunting around for it, that's the best I can do for now.

The best analogy I can guess at here (I don't know enough Java to say with100% certainty.) is that basicly, everything in Java is a pointer. This is why you have to use: 'x = new X( );' all the time.

If you try and give C a new value, once it's already been given one:

c C = new c( );
C = new c( ); //second value

It will fail. I tried:

C:\WINDOWS\Desktop>javac MyApp2.java
MyApp2.java:18: Can't assign a value to a final variable: C
C = new c( );
^
1 error


So basicly, it's like making the pointer constant, in that, you can give it a value once, and from then on, it cannot be changed.

And I believe that's how "Core Jave:Volume 1" describes it. "final" means (for instances, I suspect) that you can give it a value once, and from then on, you cannot change it. Thus, if you want your methods to be "constant", then you have to declare the method as final. If you want a data member constant, you have to declare it final.

A final method cannot be overridden either, at least I believe so.
I wish we had a Java board...

Quzah.

zen
11-06-2001, 06:24 PM
If your iB.getA( ) had returned a constant A object then you wouldn't have been able to call setX( 333 ) on it, so iB.getA( ).setX( 333 ); should be illegal. You are modifying an object that has been returned from a Get() method and this method doesn't protect it. If you wanted exclusive control of an 'A' object from within' B', and wanted to provide external read-only access to it, how would 'B' know when this 'A' is being modified?

quzah
11-06-2001, 06:48 PM
> If your iB.getA( ) had returned a constant A object then you
> wouldn't have been able to call setX( 333 ) on it, so iB.getA
> ( ).setX( 333 ); should be illegal.

Hm... Yup. It would seem so. However, it compiles and runs. I
really don't have the answer to why. Let's try...

class A { //class A
private int x; //some data here
public int getX( ) { return x; }
public void setX( int y ) { x = y; }
}

class B {
private A iA; //private instance clA
public B( ) { iA = new A( ); }
public final A getA( ) { return iA; }
}

class MyApp {
public static void main( String[] args ) {
B iB = new B( );
iB.getA( ).setX( 333 );
System.out.println( "A.x is " + iB.getA( ).getX( ) );
iB.getA( ).setX( 444 );
System.out.println( "A.x is " + iB.getA( ).getX( ) );
iB.iA.setX( 555 );
System.out.println( "A.x is " + iB.getA( ).getX( ) );
}
}

MyApp.java:22: Variable iA in class B not accessible from class MyApp.
iB.iA.setX( 555 );
^

Ok, so what exactly is this saying? We cannot access 'iA' because we're in another class while doing it? Got me. I thought this'd work. Hell, it should work, IMO. Examine:

iB = public
iA = private member of iB

Since it's private, 'iB' should be able to access it, but other classes cannot. But, when we do:

iB.getA( ).setX( ... );

This works because we're returning an iA object, and having it call it's own functions. Eeh.. I need a Java board.

> You are modifying an object that has been returned from a Get()
> method and this method doesn't protect it. If you wanted
> exclusive control of an 'A' object from within' B', and wanted to
> provide external read-only access to it, how would 'B' know
> when this 'A' is being modified?

I'm not sure. My lunch is over, so I'll mull this around abit, and see what I can come up with...

Quzah.

quzah
11-06-2001, 08:06 PM
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html

Well I've been tinkering with this, and I'm not sure I'm liking what I find. (What I find, is that it isn't working the way I thought it should be working.)

class A {
private int x; //should be only available to this class's members
public int getX( ) { return x; } //should be available to everyone
protected void setX( int y ) { x = y; } //only this and subclasses
}
class B {
public A pubA = new A( ); //everyone can play with this
private A priA = new A( ); //only B's members?
protected A proA = new A( ); //only this and B's subclasses

public A getpubA( ) { return pubA; }
private A getpriA( ) { return priA; }
protected A getproA( ) { return proA; }
}
class MiApp {
public static void main( String [] args ) {
B iB = new B( );

// All is legal. We're strictly public here. Free for all.
iB.pubA.setX( 1 );
System.out.println( "iB.pubA.getX( ) == " + iB.pubA.getX( ) );

//error, iB does not have access to 'priA' in class 'MiApp'.
//error for these next two lines.
iB.priA.setX( 2 );
System.out.println( "iB.priA.getX( ) == " + iB.priA.getX( ) );

//This leads me to the following conclusion:
// 'MiApp' is the one that the compiler believes is accessing
// the inner workings of 'iB'. In other words, just because
// 'MiApp' __HAS A__ 'iB', does not mean that it can access
// the contents of 'iB'.

//This is also legal, because with 'protected', we extend access
//to those classes that 'have a' instance of said class. Actually,
//I believe it works because we're in the same 'package', (ie: in
//this case, the same file. An external file that had a 'B'
//instance would fail here? Haven't tried it.
iB.proA.setX( 3 );
System.out.println( "iB.proA.getX( ) == " + iB.proA.getX( ) );
}
}


How does that relate with us returning data and the 'final' keyword? I'll get to work on that now that I __think__ I understand how the access works. :)

Quzah.

mix0matt
11-06-2001, 08:35 PM
<< Ok, so what exactly is this saying? We cannot access 'iA' because we're in another class while doing it? Got me. I thought this'd work. Hell, it should work, IMO.>>

i've been following, lurking in the shadows. Remember that i have no knowledge of java...

i would guess that this is similar to C++. You can't get to object iA or any of its methods (setX) because it is a private object. You would have to define methods in class B to change the values in iA or define iB as public. iB's interal operations can access iA, but external classes (ie MyApp) have to get to iA through the defined interface: (question marks denote confusion over java syntax ;) )

class B {
private A iA; //private instance clA
public B( ) { iA = new A( ); }
public final A getA( ) { return iA; }
public void(?) setA (A obj) { iA = obj; } // assuming operator is overloaded
public void(?) setA (int x) { iA.setX (x); ]
}

this confuses me too:
iB.getA().setX(555). So, in java all objects returned from get() methods are returned by reference? That's crazy. Consider the following C++ example:

class A {
public:
A () { x = 0; }
void setX (int a) { x = a; }
int getX () { return x; }
private:
int x;
};

class B {
public:
B () : iA () {}
A getAvalue() const { return iA; }
A& getAref() { return iA; }
private:
A iA;
};

int main ()
{
B iB;
iB.getAvalue().setX(2); // value of iA.x is preserved

cout << iB.getAValue().getX() << endl; // 'see

iB.getAref().setX(3); // returning dangling ref allows corruption of data

cout << iB.getAvalue().getX() << endl; // 'see

return 0;
}
i'm, very surprised that java doesn't allow for the same protection. That can't be true. i thought one of the main ideas behind the super high level languages was to protect the programmer from mistakes like this? i must be missing something....

quzah
11-06-2001, 10:20 PM
> public void(?) setA (A obj) { iA = obj; } // assuming...

Yep, this is correct. Or would be rather. This, in Java, is just like this in C++:

class A {
public:
A( ) { obj = new Object( ); } //can't remember if you use () here

void setObj( Obj o ) { if( obj ) delete( obj ); obj = o; }
private:
Object *ob;
};


As far as passing by reference, pretty much. However, I'd be really really surprised if there wasn't a way to prevent changes when you didn't want them. (ie: const/final) I just am not sure how yet :P

Quzah.

Eber Kain
11-07-2001, 12:39 AM
I think we need to strap a 3 terrahertz cooling fan on everyones head, and mabey the electric shock it gives you from the sweat on your brow will zap all this OOP knit picking out of your head.

Here ill give you something good to argue over.

Ive never used a class in my codeing, I allways use structs. The logic behind this is that it dont matter if the members are public private or protected. Why make a member anything other than public anyhow?




It only gets used where you program it to be used.

nvoigt
11-07-2001, 01:34 AM
Eber Kain, have you ever coded in a team ? On anything larger than you own project ? You will see that if you don't protect your stuff, people will try the strangest things with your constructs.

Your classes have to work perfectly, even when used by total idiots. Which means that you will have to code them in a way that will make the compiler issue errors if used incorrectly. And in Java, without a functioning const keyword, that is next to impossible.

I wonder why. The const keyword is a compiler issue. A constant object and it's methods produce the same code as a normal one.


Have you ever thought about who coded the string class you use ? And how many mistakes you would have made if everything were possible with it ? If you could modify every single attribute ?

zen
11-07-2001, 08:55 AM
Also, if you find a way to make you code more efficient by changing the underlying implementation, allowing direct access to all your data will probably break all the code that relies on this data. If you wrap it in classes the only thing you have to change is the private implementation details and all your other code can remain as it is.

Eber Kain
11-07-2001, 10:46 AM
I have worked on projects over the net with other people, We have never had a problem, because i provide good documentation about how to use any code i write.

And if the person is to bumb to use it properly i dont waste my time working with them.

Thats still not a very strong answer in my eyes. But i might change my mind whenever i get hired somewhere.

nvoigt
11-07-2001, 11:32 AM
>And if the person is to bumb to use it properly i dont waste my time working with them.


Well... you know, if you do this professionally, you don't have the choice whom you work with. And you don't need to be dumb to make mistakes. Everyone makes mistakes, but with proper programming, finding them is much easier and costs less time. And time is money.

Unregistered
11-07-2001, 03:38 PM
> Why make a member anything other than public anyhow?

class LifeSupportSystem {
Medicine m;
Timer t;

LifeSupportSystem( Medicine med, int seconds )
{m = new Medicine( med ); t = new Timer( seconds ); }
DeliverDose( ) { System.out.toIV( Medicine.m, Medicine.dose }
Stop( ) { t.seconds = -1; }
}


Ok then. Tell me why all of this should be public? Assume we're writing for an embedded system that controls life support. Since everything is public, what prevents me from overriding the DeliverDose( ), or to override Medicine and change the dose?

myLifeSupporteInstance.m.dose *= 500; //oops

Or stopping their life support by overriding the DeliverDose()?

DeliverDose( ) { Stop( ); }

See, there are very very good reasons to have private members.

Quzah.

quzah
11-07-2001, 03:40 PM
>See, there are very very good reasons to have private
> members.

However, I would really really like to override the timer on the cookie for this site... I guess this site prefers "speed coding". Either that or they just like you to log in again after every post.

Quzah.

Eber Kain
11-07-2001, 05:17 PM
Im intrested in game programming, come up with a situation where a class member would need to be private?

No data gets changed unless you write code to change it, so unless the person is adding code to what you do, i dont see the need?

zen
11-07-2001, 05:50 PM
Like I said above, it can be useful to separate the implementation from the interface, as well as facilitating code reuse. However it's not necessary, there's nothing that you can do with OOP that you can't do procedurally, so if that's what you prefer stick with it. Although if you're interested in game development you'll probably encounter OOP as currently a substantial amount of games are written using it.

Troll_King
11-07-2001, 08:14 PM
.

quzah
11-07-2001, 08:54 PM
> Anyone going to write a C# program?

No. We've turned this into a Java board. Sorry.

Quzah.

nvoigt
11-08-2001, 12:57 AM
C# Program:

If you remember the thread on the game programming board some months back, I intended to write an Empire style game in C#. I still have some plans and might publish them here, but events in my life ( involving trouble with my gf and another loved one in hospital ) got this project postponed time and again. So yes, I will. Probably around christmas, when I have three weeks vacations without a single clue what to do :(

>Im intrested in game programming, come up with a situation
>where a class member would need to be private?
>No data gets changed unless you write code to change it, so
>unless the person is adding code to what you do, i dont see the
>need?

It doesn't matter what you program. If you do it alone, in your room, it's completely your choice. You can name your variables a1, a2, a3, a4, make them all global, use gotos, whatever. It will work. As soon as you work with a larger team, you will see that there are some things that need to be done to ensure good teamwork. That's nobodies fault. It's not because the others are dumb. You can't sneak in a tennis ball in a baseball game. Sure, when you are alone, you can do whatever you like. Even play with a tennis ball. But in a team, there are rules that define the game and make playing easier and more fun.

A public member is an error waiting to happen. Maybe nothing tragic, just an hour of debugging and it's gone. Someone wanted to set nTolerance to zero, but set nT instead, which is something unrelated. The whole program crashes. It's his fault he made a mistake. It's your fault you had to spend an hour finding it. You could have prevented it by making the members private and granting access by interfaces, in which case nT might not even habe been available for changing.

It's like you dig a hole in the ground and leave. Someone else isnn't careful and falls in. If all this happened on public territory, it's the diggers fault. He should have closed it properly.
In your own yard, you can do what your want. It's just that after a time, no one wants to visit you anymore.

Troll_King
11-08-2001, 02:05 AM
.