Ok, I have been doing my exams and gave up programming so that I could concentrate more...can someone give me a relatively easy task for me to set out to do and get me back into the swing of things as all my inspiration has gone.
Ok, I have been doing my exams and gave up programming so that I could concentrate more...can someone give me a relatively easy task for me to set out to do and get me back into the swing of things as all my inspiration has gone.
You could try the Snake Numbers Contest.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> can someone give me a relatively easy task for me to set out to do
Anybody's homework on this board - just to see if you can do it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Simulate a home alarm system or something fun like that. You'll be programming and setting fires. Plus it's a good OOP excercise.
I do have one rule though: no getter and setter functions for individual members of any class. As the class is supposed to work to keep "how it works" a secret, making the programmer able to change a specific member just by calling a setter function doesn't make much sense.
Can you detail taht a bit more please?
No. :P Figure out what you want it to do exactly; that's what makes it an exercise.
- Set up rooms
- Set up alarms, and what rooms have alarms
- Cause disasters and write a log file stating who you called about the emergency, when, and why.
- Make it even better if you can think of anything else.
What do you mean by the whole getter and setter functions thing?
Oh that! Well, some people will make a class like:Anything wrong with that? Well, what is so great about the functions that makes it better than a public data member? Nothing. No programmer is so uninspired that he won't figure out that if he needs to change a member he can call set()... you've not protected foo at all.Code:class Foo { int foo_data; public: const int getfoo(void) const { return foo_data; } void setfoo(const int foo_in) { foo_data = foo_in; } };
What is okay though is to write functions that work with the data to do something specific instead of just changing members.
So, basically you are saying that the STL is evil, because for example with strings I can do this:
... the last line being the same as b.set(a) ?Code:string a("Umm"); string b; b = a;
No I'm not saying that, and that is not what happened in your code. In your code, string b is a copy of string a. Both strings still exist. You did not overwrite string a.
Though I think you are talking about reinitialization.
Reinitialization is not as bad when you use it intelligently, but this is different from being able to set some variable to fail and breaking a class on purpose, like get/set functions do.Code:string a("hello world"); a = "goodbye cruel world";
No, citizen's point is that the use of setter/getter functions tightly associated with specific member variables may break encapsulation, and these member variable may as well be declared with public access.
For example, the length() member function of some string class might just return the value of a member variable, but it may not necessary be a getter function in this way, since it is concerned with a concept in the problem domain, i.e. that strings are of a certain length.
Of course, the STL isnt particularly object oriented to begin with, but has more a focus on generic programming.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I believe Citizen is commenting on the fact that many of us don't really follow the advice on data abstraction by separating implementation from the interface. When we code public set and get member functions we aren't really for the most part following this concept. And some cases are so obvious that a class defined this way becomes nothing more than code trick to hide the fact we are lazy.Originally Posted by anon
A class that offers no data abstraction and no encapsulation is not a type. It's a data structure. We can have it redefined as a struct. To define it as class and hide behind it get and set function members show that we either don't understand what classes are meant to be or are too lazy to think of the correct way to implement them. I have many, many, times fallen prey to both when coding in Visual Basic.
There are, of course, uses to get and set functions. Nothing is written in stone. However, citizen, I believe, was being more generic, offering the added challenge of thinking about a "true" class implementation. Just the alarms thing would be too easy.
As for the string... the little i've studied so far of C++ (i'm a newcommer to it), the STL string type is presented to us by a typedef of the template basic_string. This template, and the class it hides, i'm sure, doesn't treat a string assigment as a set member function
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
I seem to ave forgotten pretty much everything now...my mind is completely blank.
Ah, all this talking confused you. Just read over the tutorials on the site to kick your brain back in. You'll start remembering things, and then you can come back to this thread.
I can't think what I would wan't to put in my class and what classes to have etc.