Like Tree4Likes

Bad habits in C++!!!

This is a discussion on Bad habits in C++!!! within the C++ Programming forums, part of the General Programming Boards category; i want to know about all the bad habits in C++ programming like using 1)goto statement 2)calling main() function etc......

  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
    21,739
    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).
    Matticus and whiteflags like this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,739
    Borrow those books from your local library. They are written in a format that allows you to go directly to specific points.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,425
    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
    21,739
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    2,753
    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,425
    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,425
    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!!!'

Page 1 of 2 12 LastLast
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-23-2012, 11:50 PM
  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, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21