Documentation is the master key of all codes to get back after a long time gap.

Spread to the Techies

Documentation is the master key of all codes to get back after a long time gap of your coding on that specific file.

Hello Readers!!!!!

Today I am going to share with you a silly but most important part of Coding on Documentation. The codes you are writing today is an asset for your future. If you can’t reuse the code after a while or you if can’t understand the code after a long time then that
resource will be useless for you and the efforts you gave is now waste of time and energy.

What is Documentation?

Documentation is nothing but some comments with the definition and descriptions of a block of codes.

It’s very important for programmer to write proper documentation of the codes. It’s a good practice to start any block of codes or algorithms by giving introductions and use of the code at the beginning.

How to write documentations?

Every programming or scripting language has their own type of commenting. I will try to give examples for some common and mostly used programming and scripting languages.

How to write documentation in C ,C++ and C#?

C and C++ are same in constructions Just C++ is the extended version of C language. So, the documentation method is also exactly same for C, C++, C#. Let’s see an example:

#include<stdio.h>
/*-----------------------------------------------
Author: Raju Meazi
Created: 31/8/2018

Short Description: This program will be used to get two integer number form the user. Then it will add them and then it will show the addition of them. 

Last modified: 31/8/2018
-----------------------------------------------*/

int main(){
       int result, input1, input2;  //three integer variable declared.
       
       printf("Enter First Number: "); //giving instruction to the user to give input for the First Number

       scanf("%d", &input1); // getting input from user for the Input1 variable.

       printf("Enter Second Number: "); //giving instruction to the user to give input for the First Number

       scanf("%d", &input2); // getting input from user for the Input1 variable.
       
       result = input1 + input2; //adding the input1 and input2 variable and storing in the result variable.
            
       printf("Addition of the First and Second Number is : %d", result); //showing the result after adding.
}

Okay friends, what you are thinking is alright. We are using comments to write documentation. Documentation is not a different file or anything. It’s a block of comments or a single line comment. Just use double Backslash

// single line

for single line documentation and

/* multiple lines */

backslash and a star sign for starting then start and backslash for ending the

How to write documentation in PHP?

Just use double Backslash ‘//’ for single line comment.

<?php

/*---------------------------------------------
Author: Raju Meazi
Created: 31/8/2018

Short Description: This php file will catch the POST data from the redirected page and then process them for the SQL injections and then create the filtered variable for giving entry to the database.

Last modified: 31/8/2018
-----------------------------------------------*/

if(isset($_POST['submit']) && $_POST['submit'] =="saveFile"):
    $firstName = $_POST['first_name']; //getting the POST variable in separate variables. 

    $lastName  = $_POST['last_name'];  //getting the POST variable in separate variables.
    
    $firstName = filter_var($firstName, FILTER_SANITIZE_STRING); //filtering the variable and assigning again to the same variable.

    $lastName = filter_var($lastName , FILTER_SANITIZE_STRING); //filtering the variable and assigning again to the same variable.

   $sql = "INSERT into `tableName` ('field1', 'field2', VALUES ('$first_name','$last_name')";
    
    mysqli_query($sql); //running the query

endif;

?>

How to write documentation in JavaScript?

<script>
/*-----------------------------------------------
Author: Raju Meazi
Created: 31/08/2018

Short Description: myFunction is a JavaScript function to return the product of two parameters.

Last Modified:
-------------------------------------------------*/
function myFunction(p1, p2) {
    return p1 * p2;    // The function returns the product of p1 and p2
}
</script>

How to write documentation in HTML?

This commenting is different from others. To write documentation or comment you will have to write ‘<!– ‘ Arrow bracket Start, then Exclamation and then, two minus signs  and to start the comment and double minus then Arrow bracket closed. See below: 

<!-- Comments or Documentation goes here.....    -->

Now look at the below example:

<html>
<head>
</head> 
<!--//////////////////////////////////////
Author: Raju Meazi
Created: 31/8/2018

Short Description: This is a simple HTML page with a header1 and a paragraph.

Last modified: 31/08/2018
/////////////////////////////////////////-->
<body>
     <!-- Heading of the page with welcome message---Start-->
     <h1>Welcome to my web page</h1> 
     <!-- Heading of the page with welcome message---- End-->
     <!-- Only paragraph of the page with welcome message--- Start-->
     <p>
        All Paragraphs and texts will be here............
     </p>
     <!-- Only paragraph of the page with welcome message---  End-->
</body>
</html>

How to write documentation in python?

The type of documentation is different from the other language. We will use a (#) to comment a line. There is no multiple line commenting in python. So, you will have to use the Single line commenting to create documentations in Python language.

#------------------------------------------------------
#    Author: Raju Meazi
#    Created: 31/08/2018
#    Short description: This is a python Documentation
#    Last modified: 31/08/2018
#------------------------------------------------------
import math
inputNumber = int(input("What is your mass in kilograms?"))
sqrtNumber = math.sqrt(inputNumber)
print("You Square root of your given number is", , "stone.")

How to write documentation in Java?

Java is also same as C and C++. Use double backslash ( // ) for single line comment and /* backslash star and star backslash */ for  multiple lines.

/*------------------------------------------

Author: Raju Meazi
Created: 31/08/2018
Short description: to read double numbers from a file named data.txt, then to sum them up and print the result to the standard output; 

Last modified: 31/08/2018

------------------------------------------*/
package chapter11;
 
import java.io.*;
import java.util.Scanner;

//Creating a test Class------------------------------------
public class Test {    
     
    public static void main (String [] args) throws FileNotFoundException{
         
        Scanner data;
        double result =0.0;       
         
//Reading a text file named data.txt-----------------------
        data = new Scanner(new File("data.txt"));        
                
//adding the whole data taken from the data.txt------------
        while (data.hasNextDouble()){
            Double d = data.nextDouble();
            result += d;
        }
        System.out.println("sum of all numbers is " + result);
    }        
}

That’s all readers for today. I wish you got my point of view for documentation on the codes. If you find this Article useful or you want to read it again later then share and store as a bookmark in your browser and social media links. To share in social media it has the social sharing options top of the post.

Thank you. Stay coming here. We are waiting with more valuable and interesting topics for you.

Leave a Reply

Your email address will not be published. Required fields are marked *