Thread: Forgotten

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    Forgotten

    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.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You could try the Snake Numbers Contest.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Can you detail taht a bit more please?

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    What do you mean by the whole getter and setter functions thing?

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Oh that! Well, some people will make a class like:
    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; }
    };
    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.

    What is okay though is to write functions that work with the data to do something specific instead of just changing members.

  9. #9
    The larch
    Join Date
    May 2006
    Posts
    3,573
    So, basically you are saying that the STL is evil, because for example with strings I can do this:
    Code:
    string a("Umm");
    string b;
    b = a;
    ... the last line being the same as b.set(a) ?

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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.
    Code:
        string a("hello world");
        a = "goodbye cruel world";
    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.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by anon
    So, basically you are saying that the STL is evil[...]?
    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.

    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.

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I seem to ave forgotten pretty much everything now...my mind is completely blank.

  14. #14
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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.

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I can't think what I would wan't to put in my class and what classes to have etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1st Assignment
    By Zeff in forum C Programming
    Replies: 29
    Last Post: 09-19-2006, 07:21 PM
  2. forgotten how to print values :(
    By darfader in forum C Programming
    Replies: 3
    Last Post: 08-12-2003, 09:47 AM
  3. Getting from function error!!!
    By frigga in forum C Programming
    Replies: 2
    Last Post: 11-19-2002, 03:37 PM
  4. Handwriting: soon to be forgotten?
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-26-2001, 06:43 PM