Thread: Writing Code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    1. Is it best to define variables you will be using in your code at the begining of the code, or slightly before there use, or some other variation?
    I think you should define the variable as close to the spot the variable is used as possible. That way you don't have to go searching for the variable when you are reading the code.

    2. When declaring functions is it best to have a prototype at the begining of your code and the actual function at the bottom, or just write the function at the begining of the code?
    Neither. The best way is to have a function declaration in a .h file and a function definition in a .cpp file separate from main. The idea is that you can reuse your functions in other programs by inserting them into your project and including the .h file in the file containing main().
    3. When writing a class, is it required / good practice, to include a destructor?
    The compiler provides you with a default destructor, so unless you need to do more, don't define one--unless you really enjoy typing.

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Ok thank you for your replies, very good information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing Code but am having problems
    By Choppers in forum C Programming
    Replies: 20
    Last Post: 06-25-2009, 06:18 PM
  2. Writing code for a program in C
    By Sure in forum C Programming
    Replies: 7
    Last Post: 06-11-2005, 01:33 PM
  3. professional programmers, do you spend more time writing or modifying code
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 11-25-2002, 10:54 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM