SlideServe
Menu
Préférences
© SlideServe · v2026

Programming Style Guide: Comments & Function Headers

irenab avatar
7 diapositives · 107 Views · Jan 02, 2020

Learn how to properly comment your code with header comments for programs and function headers, along with other important commenting and programming style guidelines.

Programming Style Guide: Comments & Function Headers - slide 1
01 / 7Programming Style Guide: Comments & Function Headers
1 / 17

Télécharger la présentation

Programming Style Guide: Comments & Function Headers
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Style Notes on commenting and programming style

  2. Header Comments • Each program should start with a header comment • The header comment should: • Indicate the purpose for the program, • The date of completion, • The name of the programmer, • Any special notes about the use of the program or known bugs

  3. Example //////////////////////////////////////////////////// // Example Program: // This is the example for the header comment. This // is where the purpose for the program would go. // You want to write as much as you need to explain // what this program does; a paragraph or two might // be enough. // // Date: October 18, 2004 // Programmer: David McPherson // // Additional Notes: Here’s where you can put // any extra stuff that you need to say. //

  4. Function Headers • As we get into writing functions, each function needs a header. • The function header is similar to the program header. • The function header should • Give the name, • Give the purpose • List the parameters and the passing mechanism for the parameters • It can also list pre and post conditions.

  5. Example //////////////////////////////////////////////////// // Function: SampleFunction // // This is a sample of what a function header // might look like. A paragraph of text here explains // what this function does. // // Parameters: // int x – this is the parameter for x. It is used // giving x to the function. // double y – this is the parameter y. It is used // to pass y back to the calling function. //

  6. Other Comments • Headers are not the only location for comments. • Each block should start with a brief comment explaining what is going on. • Each variable should have a comment explaining its purpose in addition to a good choice for its name • Any time that the code is doing something that is not evident, you should comment.

  7. Other matters of style • CONSTANTS SHOULD BE IN ALL CAPS • Variables should be named so that its purpose might be gleaned. • Make go use of whitespace • Don’t jam all your code together