0

Recently, I get to know that writing code in the modular or components way is important. But I am not sure why is it so important.

Can someone explain why is it important if you know?

  • I'm afraid this is off topic, here (there are better fits among SE sites), but just think about reusability. – Bob__ Oct 16 '19 at 06:16
  • Hi, can you please let me know on which technology/programming language you are working? – Anurag Oct 16 '19 at 06:27
  • @Anurag - This is not a language/technology specific I think. – Rajesh Kumar Oct 16 '19 at 10:03
  • @Rajesh, yes this is not language/technology specific but for code modularity, there are some standards as well which you can follow, that is why asked you. – Anurag Oct 16 '19 at 12:07

1 Answers1

0

code modularity is important for code readability, maintainability and post production support.

If you write a function which has 500 lines of code, it will be very difficult to understand but if you break your 500 lines of code into 10 different functions, it will be easy to understand and debug.

Example: //without code modularity

public float performCalculation(float a, float b)
{
         float result;
         /** writing code calculation1**/
          -
          -

           /** writing code calculation2**/
          -
          -
          -

           /** writing code calculating result**/
          -
          -
          -
          -


}


// with code modularity
public float performCalculation(float a, float b)
{
        float calculation1 = performCalculation1(a,b); // call function performCalculation1
        float calculation2 = performCalculation2(a,b); // call function performCalculation2
        float result = findResult(calculation1 , calculation2 ); // call function findResult
return result; 

}

Decide yourself which code is more readable. Here I have provided a very simple example but just think how will you maintain your code when it becomes huge.

Also, you can go through some online material to learn by yourself on best practices of code modularity.

Anurag
  • 843
  • 1
  • 9
  • 16