Thread: Bad habits in C++!!!

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    103

    Bad habits in C++!!!

    i want to know about all the bad habits in C++ programming
    like using 1)goto statement
    2)calling main() function etc...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It might be good to start with the good habits. Books like Scott Meyers' Effective C++ series and Stephen Dewhurst's C++ Common Knowledge can help (though some parts may be a little dated now that C++11 is around).
    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
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    i am a fast learner and i have v tight schedule all day so please mention some MAJOR points here i have to study rest 4 subjects too(maths, phy ,chem and english)

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Borrow those books from your local library. They are written in a format that allows you to go directly to specific points.
    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

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    So have you been set a question that requires you to discuss bad programming practices?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    103

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @rogster yeah i actually realized that i m having some bad practices in C++

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, if you learn good practices, then you will find that you will have less recourse to bad ones because the good alternatives come to mind more easily.
    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

  9. #9
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    okay now i would like to ask you that what is the use of 'cerr' in C++??? it just clicked in my mind right now

  10. #10
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    and another one....why i am not able to use graphics.h header file?
    is the code right ?
    Code:
    #include<graphics.h>
    #include<stdlib.h>
    void main()
    {
        system("cls");
        int a=DETECT,b;
        initgraph(&a,&b,"");
        circle(100,100,10);
        getch();
    }
    Last edited by Mukul Kumar; 04-18-2013 at 12:24 PM.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    okay now i would like to ask you that what is the use of 'cerr' in C++??? it just clicked in my mind right now
    C++ opens three streams when you start your program cin, cout, and cerr. The cerr stream is an unbuffered that is usually connected to the console and is usually used for error reporting.

    and another one....why i am not able to use graphics.h header file?
    It is not the use of the header file that you are actually having problems with, but the lack of the function implementations that this header defines. This graphics library only works with a Borland compiler. Are you using this ancient compiler? I hope not!

    is the code right ?
    No, not unless you're using that ancient compiler.

    Also main() must be defined to return an int, not void. This is one of those bad habits you're talking about!


    Jim

  12. #12
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    graphics.h - I knew that was coming - turbo C it had to be - why do programming students in India have to be so poorly served by thier tutors.

    It won't work because it is very old - modern hardware is very unlikely to support it. And that is only one part of the compiler suite you are using - so how relevant do you think the rest will be?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  13. #13
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    A good way to learn about bad practice is to visit these pages regularly and follow the threads and advice given, you will soon see what is agreed to be good, bad, and debated about
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  14. #14
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    thanks jim and i am using modern editor+compiler but i used borland C++ earlier when i started doing programming in C++
    then how will i be able to do some drawing in C++???

  15. #15
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @rogster i told my school teacher about the ancient version of C++ editor i.e. turbo C++ but she declined and said 'we used to do v.nice programming in it i hope you can also do!!!'

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Old habits die hard
    By Yarin in forum General Discussions
    Replies: 11
    Last Post: 01-24-2012, 12:50 AM
  2. Neurotic bodily habits when coding
    By Sharke in forum General Discussions
    Replies: 36
    Last Post: 06-22-2009, 10:53 AM
  3. Programming Habits
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 04-25-2009, 05:00 PM
  4. Bad coding habits
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-12-2005, 05:44 PM
  5. Professional Habits?
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 01-17-2003, 02:27 PM