Documenting code


 
Thread Tools Search this Thread
Top Forums Programming Documenting code
# 1  
Old 06-01-2011
Documenting code

I am programming using C++ and am wondering how to comment my project.

For example, when I declare a class I created a header with some description, then have the declaration stage, which I don't comment. Then when I define the actual functions I will put details about it, what it does, description of arguments etc.

Would be good to have people's opinion on this.

Code:
//  class Matrix
//
//    The Matrix class defines and implements manipulation functions
//    for matrices.
//
//  History:
//    V01 - DEC 1999 - Luca D'Auria
//          Initial release.
//    V02 - SEP 2008 - Luca Elia
//          Version fixed for g++ 4.3.0.
//    V03 - NOV 2008 - Christopher Dimech
//          Code restructuring.

#ifndef MATRIX_H
#define MATRIX_H

#include <assert.h>
#include "vector.h"

template <class Type>
class Matrix {

public:

  Matrix();

  Matrix(
    const int  m,
    const int  n );

  Matrix(
    const Matrix&  A );

  ~Matrix();

  void
  resize(
    const int  m,
    const int  n );

  void
  fill(
    const Type  val );

...

# 2  
Old 06-01-2011
Quote:
Originally Posted by kristinu
I am programming using C++ and am wondering how to comment my project.

For example, when I declare a class I created a header with some description, then have the declaration stage, which I don't comment. Then when I define the actual functions I will put details about it, what it does, description of arguments etc.

Would be good to have people's opinion on this.
You should put the description in the header because that's where everyone's going to look. It means they don't need to hunt through hundreds of lines of source to find the function implementation they're interested in.

Besides -- if you ever distribute this code in library form, your users won't even have the source files, just the header and some objects.
# 3  
Old 06-01-2011
I can put documentation for the interface (parameters, return value, what the function does) in the interface file (.h), and the documentation for the implementation (how the function does) in the implementation file (.c, .cpp, .m).

I can also document the interface (return values, argument, state changes, etc) before the member function implementation, and high-level architectural overviews in separate documents (to give a broader view of how everything is put together; it's hard to place this together with the code, since it usually references several classes at once).

I write an overview of the class just before its declaration, so the reader has immediate basic information.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Web Development

Documenting Installation Problem with vue-beautiful-chat

REF: https://github.com/mattmezza/vue-beautiful-chat $ git clone https://github.com/mattmezza/vue-beautiful-chat.git Cloning into 'vue-beautiful-chat'... remote: Enumerating objects: 534, done. remote: Total 534 (delta 0), reused 0 (delta 0), pack-reused 534 Receiving objects: 100%... (2 Replies)
Discussion started by: Neo
2 Replies

2. Shell Programming and Scripting

Documenting files with sed

All, I am looking for a way to improve this small one liner. one of the files has this kind of format public func <<<T>(array: , offset: Int) -> { return array.shiftedLeft(by: offset) } gsed -i '/public func/i /\/\/\public func \n/\/\==mark==public func' tresults in ///public func ... (5 Replies)
Discussion started by: f77hack
5 Replies

3. Shell Programming and Scripting

Script Help -- documenting specific users that log into server

Hello All, I am trying trying to write a shell script that will do a couple things: 1.) Identify any username that logs into the server. 2.) When the user logs out, send them an email detailing their log in/out times, duration logged in, and what processes they ran. Basically,... (3 Replies)
Discussion started by: SecureScript
3 Replies

4. UNIX for Dummies Questions & Answers

Any easy way of documenting cron entries?

I've been asked to do a high level summary of the cron jobs which run against a number of systems (to understand the potential scope for rewriting some of our core systems)...and was wondering how people have done this in the past. I've got approx 400 cron entries to go through. I will have... (2 Replies)
Discussion started by: GavP
2 Replies

5. UNIX for Dummies Questions & Answers

Documenting a Shell Script

I've been working on a very long shell script that's becoming a mini-application. It is my first script, and continues to grow each week, becoming more and more complex. I've been asked to document my script, beginning with basic information and then detailing any information about its... (1 Reply)
Discussion started by: yongho
1 Replies
Login or Register to Ask a Question