Applying Halstead Software Science On Different Programming Languages For Analyzing Software Complexity

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Proceedings of the Fourth International Conference on Trends in Electronics and Informatics (ICOEI 2020)

IEEE Xplore Part Number: CFP20J32-ART; ISBN: 978-1-7281-5518-0

Applying Halstead Software Science on Different


Programming Languages for Analyzing Software
Complexity
Nikhil Govil
Assistant Professor, Department of CEA
IET, GLA University
Mathura, India
nikhil.govil@gla.ac.in

Abstract—In software development, it is crucial that each and parameters. The objective of this article is to analyze software
every unit of effort must be measurable. If it is not measurable, complexity in different programming languages by applying
S oftware engineers must try to make it measurable. S oftware Halstead software science. This article is structured as section 2
metrics are any unit of software product measurement. S oftware includes the introduction of Halstead Software Science. Section
metrics have emerged as an important mechanism to find a 3 comprises related work while Section 4 comprises programs
significant estimation of software products. This estimation to check whether a number is a Palindrome or not in five
usually includes complexity, effort, size of the code, time different programming languages as, C, C++, Java, PHP, and
consumption, etc. By applying Halstead software science, we can python. Section 5 includes software science calculations on
analyze the different complexity factors of a program. This
various parameters that collectively define software
software science can lead us to effective technical as well as
managerial decisions. In this paper, Halstead metrics of the
complexity. Section 6 comprises the results on the basis of the
program for checking for palindrome number in five different analysis performed in section 5. Section 7 & 8 comprise the
programming languages have been taken and analysis has been conclusion and future work of this article respectively.
presented.
II. HALST EAD SOFT WARE SCIENCE
Keywords—software metrics; Halstead metrics; complexity;
estimation Maurice Howard Halstead was the first-ever researcher
who wrote the mathematical formulation of software metrics
[1]. His incredible research is widely used as an alternative to
I. INT RODUCT ION
counting the Lines of Code (LOC) as a measurement for
A software development incorporates different phases program size and software complexity. Lines of Code is
during the software development life cycle. Throughout the purely programming language-dependent and may vary the
development processes, organizations tried to fulfill the moment that convert our code in any other programming
requirements of the client(s) as well as to provide specific and language. In such a case, Halstead software science provides a
numerous characteristics [6] [7]. These characteristics can be prudent approach to calculate software size and complexity
used to identify the overall complexity of any subsystem or
precisely [13] [14]. To calculate software metrics, Halstead
even a software product. Usually, software complexity can be
classified the source code as either operator &/or operands
construed in terms of execution time, the effort required to
execute program(s) along with memory required to execute the [15]. The tokens applied in this measurement are as below
computations [5].This complexity is one of the decisive [10] [11]:
components of the software metrics. It has been observed that
software metrics are correlated to the measurement of the The Halstead software science measures are-
software product. K1 = number of unique operators,
Software metrics is a measurement-based approach that is K2 = number of unique operands,
being applied essentially to improve the overall process and
efficiency of the software products [8]. Maurice Howard N1 = total number of operators &
Halstead in 1977 introduced s uch a software metric which is
N2 = total number of operands.
also known as Halstead Software Science [2] [3] [12], to
calculate the software complexity on the basis of the source Several measures can be further computed on the basis of
code of any subsystem or even integrated software product. these numbers as-
This article describes how to apply Halstead software science
to a program written in five different programming languages.
This paper also checks the program’s relative metrics and
produce an analysis on the basis of selective and crucial

978-1-7281-5518-0/20/$31.00 ©2020 IEEE 939

Authorized licensed use limited to: East Carolina University. Downloaded on July 27,2020 at 22:45:44 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Trends in Electronics and Informatics (ICOEI 2020)
IEEE Xplore Part Number: CFP20J32-ART; ISBN: 978-1-7281-5518-0

A. Program Vocabulary ( K) of complexity. It can be identified by performing calculations


It represents the sum of unique operators and operands & on different languages by inputting the same program.
can be calculated as: Abdul Rehman Shaikh [4] demonstrated how to collect
metrics to measure effort estimation. Abdul Rehman Shaikh
K = K1 + K2 (1) discussed difficulty, effort, volume and time required to
program parameters in the article. He compares software
B. Program Length (N) metrics on three different programs on sorting.
It represents the sum of total number of operators and Rashmi Popli and Naresh Chauhan [16] discussed people
operands & can be calculated as: and project-related factors that may affect the estimation of
N = N1 + N2 (2) any project development. They estimated the computed story
points, efforts, and duration required to complete the project in
C. Program Volume (V)
an agile environment.
It is well-proportioned to total size of the program. It is
memory space required for storing the program; so it is IV. SAMPLE SOURCE CODE
represented in bits. Program volume can be computed as: This section comprises a program to check whether a
V = N * log 2 K (3) number is a Palindrome or not in five different programming
languages as, C, C++, Java, PHP, and python. Further Halstead
D. Calculated estimated program length ( software science has been applied to identify various metrics
It is the length of well-structured program & is a function related to the programs.
only of the number of unique operators and operands. It can be
calculated as: A. Program to check Palindrome in C Progrmming Langua ge
( = K1 log 2 K1 +K2 log 2 K2 (4) #include <stdio.h>
E. Difficulty (D) int main ()
{
It is the difficulty level of the program which is
int n, reverse_num = 0, remainder, original_num;
proportional to the number of the unique operator in the
printf ("Enter an integer: ");
program. It can be calculated as:
scanf ("%d", &n);
D = (K1 /2) * (N2 /K2 ) (5) original_num = n;
F. Programming Effort (E)
It is the amount of logical and mental exercise required to while (n != 0)
implement the code from pseudocode. It can be calculated as: {
E=D*V (6) remainder = n % 10;
reverse_num=reverse_num*10 + remainder;
G. Time required to program (T) n /= 10;
It is represented as a reasonable time to produce the }
program. It can be calculated as: if (original_num == reverse_num)
T= (E/E) (7) printf ("%d is a palindrome.",
original_num);
Where E is the stroud number which ranges between 5 and 20. else
However E is usually taken as 18 because this give best results printf ("%d is not a palindrome.",
in Halstead’s earliest experiments. [9] original_num);
return 0;
H. Number of delivered bugs (B) }
It is number of errors in the implementation. The number
of delivered bugs correlates with the overall complexity of the B. Program to check Palindrome in C++
software product. It can be calculated as:
B = (V/3000) (8) #include <iostream.h>
int main ()
{
III. RELAT ED WORK int n, num, digit, reverse = 0;
This section of the article identifies some of the key cout << "Enter any number: ";
research work in the area of calculating software complexity. cin >> num;
Hariprasad T et al. [2] calculated and analyzed software n = num;
complexity measures on two different programming do
languages. But in today's scenario, many programming {
languages are being used in industries widely across the globe. digit = num % 10;
So there is a need to identify which language has less amount reverse = (reverse * 10) + digit;
num = num / 10;

978-1-7281-5518-0/20/$31.00 ©2020 IEEE 940

Authorized licensed use limited to: East Carolina University. Downloaded on July 27,2020 at 22:45:44 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Trends in Electronics and Informatics (ICOEI 2020)
IEEE Xplore Part Number: CFP20J32-ART; ISBN: 978-1-7281-5518-0

} if (Palindrome($orig inal))
while (num != 0); {
cout << " The reverse of the number is: " << reverse echo "It is a Palindrome number";
<< endl; }
if (n == reverse) else
cout << " The number is a palindrome."; {
else echo "It is not a Palindrome number";
cout << " The number is not a palindrome."; }
return 0; ?>
}
E. Program to check Palindrome in python
C. Program to check Palindrome in JAVA num=int (input(“Enter a number:”))
public class Palindrome temp=num
{ reverse=0
public static void main(String[] args) while temp !=0:
{ reverse = (reverse*10) + (temp%10)
int num = 171, reversedNum = 0, remainder, temp=temp//10
originalNum; if num==reverse:
originalNum = num; print (“It is a Palindrome number”)
while( num != 0 ) else:
{ print (“It is not a Palindrome number”)
remainder = num % 10;
reversedNum=reversedNum*10+remainder;
num /= 10; V. SOFT WARE SCIENCE CALCULAT IONS
} On the basis of source code written in different
if (originalNum == reversedNum) programming languages which are mentioned in section 3;
System.out.println(originalNum + " various Halstead metrics can be computed. These metrics
is a palindrome number."); collectively define the overall software complexity [4]. The
else Halstead software science for source codes mentioned in
System.out.println(originalNum + " section 3 are analyzed in Table 1.
is not a palindrome number.");
} TABLE I. HALSTEAD MTERICS ANALYSIS
}
S. Halstead Code Code Code Code Code
No. me trics in C in C++ in Java in PHP in
python
D. Program to check Palindrome in PHP 1 K1 21 23 27 17 16
<?php 2 K2 10 11 10 12 8
function Palindrome($number) 3 K 31 34 37 29 24
{ 4 N1 55 58 53 45 31
$temp = $number; 5 N2 27 29 26 27 20
6 N 82 87 79 72 51
$new = 0; 7 V 406.24 442.61 411.55 349.77 233.83
while (floor($temp)) 8 125.46 142.09 161.6 112.51 88
{ 9 D 28.35 30.32 35.1 19.12 20
$d = $temp % 10; 10 E 11516.9 13419.93 14445.4 6689.35 4676.6
$new = $new * 10 + $d; 11 T 639.83 745.55 802.52 371.63 259.81
12 B 0.135 0.147 0.137 0.116 0.078
$temp = $temp/10;
} VI. RESULT S
if ($new == $number)
{ All the above values mentioned in Table1, are based on
operators and operands that exists in the program(s). On the
return 1;
basis of the above analysis, it can graphically represent the
}
comparison of selective parameters such as difficulty, effort,
else time and bugs delivered. This comparison of parameters are
{ shown among all five experimented programming languages.
return 0;
} Following figure shows comparison of divergent values of
} difficulty among five different programming language. It can
be observed that the code written in Java language, has higher
$original = 171;

978-1-7281-5518-0/20/$31.00 ©2020 IEEE 941

Authorized licensed use limited to: East Carolina University. Downloaded on July 27,2020 at 22:45:44 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Trends in Electronics and Informatics (ICOEI 2020)
IEEE Xplore Part Number: CFP20J32-ART; ISBN: 978-1-7281-5518-0

degree of difficulty while code written in PHP has less degree Following figure shows comparison of divergent values of
of difficulty. bugs delivered among five different programming language. It
is observed that code written in C++ language has higher
degree of number of delivered bugs. While python has less
degree of number of delivered bugs.

Fig.1. Comparision chart of Difficulty (D)

Following figure shows comparison of divergent values of


effort among five different programming language. Through
this graph, it is clear that code written in Java requires more
degree of effort while code written in python language Fig.4. Comparision chart of Bugs Delivered (B)
requires less degree of effort.
VII. CONCLUSION
It has been observed that python programming language
has less difficulty, effort, the time required to program and a
number of delivered bugs as compared to the other
experimented programming languages like C, C++, Java, and
PHP. It is also observable that Java programming language
requires more effort, time as well as a higher degree of
difficulty as compared to the above mentioned experimented
programming languages. However, more number of bugs can
be delivered in case of C++ programming language while
considering the same program on different programming
languages.

VIII. FUT URE SCOPE


Fig.2. Comparision chart of Effort (E)
Our future work may incorporate the creation of a dataset
Following figure shows comparison of divergent values of including more sets of programs in different programming
time among five different programming language. The languages. These programs can be treated as inputs to the
following graphs shows that Java code requires more time to approach so that it can produce more analyzed results with
produce the program. On the other hand, python code requires precision.
less time to produce the program as compared to other
programming languages. REFERENCES

[1] Halstead, Maurice H. (1977), Elements of Software Science.


Amsterdam: Elsevier North-Holland, Inc. ISBN 0-444-00205-7.
[2] Hariprasad T , Seenu K, Vidhyagaran G and Chandrasegar T hirumalai,
“ Software Complexity Analysis Using Halstead Metrics”, International
Conference on Trends in Electronics and Informatics (ICEI) IEEE &
978-1-5090-4257-9, May 2017.
[3] Chandrasegar T hirumalai, Shridharshan R R, Ranjith Reynold L, “An
Assessment of Halstead and COCOMO Model for Effort Estimation ”,
International Conference on Innovations in Power and Advanced
Computing T echnologies (i-PACT ), April 2017.
[4] Abdul Rehman Shaikh, “Applying Halstead Metrics in Your Programs”,
https://www.academia.edu/23024048/Applying_Halstead_Metrics_in_Y
our_Programs/ last accessed on 18 March 2020 .
[5] Anurag Bhatnagar, Nikhar T ak, Shweta Shukla, “ A Literature Survey on
Various Software Complexity Measures”, International Journal of
Fig.3. Comparision chart of T ime (T )

978-1-7281-5518-0/20/$31.00 ©2020 IEEE 942

Authorized licensed use limited to: East Carolina University. Downloaded on July 27,2020 at 22:45:44 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Trends in Electronics and Informatics (ICOEI 2020)
IEEE Xplore Part Number: CFP20J32-ART; ISBN: 978-1-7281-5518-0

Advanced Studies in Computer Science and Engineering, Volume 1, [11] Rajib Mall, “ Fundamentals of Software Engineering”, Fourth Ed., PHI
Issue 1, pp. 1-11, June 2012. Learning Private Limited, (2016).
[6] Aparna T ripathi, Varsha Kumari, Nikhil Govil, "Impacts of PLC [12] Pankaj Jalote, “ An Integrated Approach to Software Engineering”, Third
Reducer on Software Design Cohesiveness", International Journal of Ed., Narose Publishing House, (2008).
Innovative Technology and Exploring Engineering, Volume-8 Issue-8, [13] https://en.wikipedia.org/wiki/Halstead_complexity_measures/ last
pp. 2871-2875, June 2019. accessed on 27 March 2020.
[7] V. Kumari, A. T ripathi, N. Govil and S. Pundhir, "A Proposed Model: [14] https://www.geeksforgeeks.org/software-engineering-halsteads-
Linearly Extensible T riplet Network (LET N)," 4th International software-metrics/last accessed on 27 March 2020.
Conference on Information Systems and Computer Networks (ISCON),
[15] https://www.javatpoint.com/software-engineering-halsteads-software-
Mathura, India, 2019, pp. 1-6.
metrics/ last accessed on 27 March 2020.
[8] Paul Goodman, “ Practical Implementation of Software Metrics”,
McGraw Hill Book Company, UK, 1993. [16] Rashmi Popli, Naresh Chauhan, “ Agile Estimation Using People and
Project Related Factors”, 2014 International Conference on Computing
[9] K.K.Aggarwal and Yogesh Singh, “ Software Engineering”, T hird Ed., for Sustainable Global Development (INDIACom), June 2014.
New Age International (P) Limited P ublishers. (2009).
[10] Roger S. Pressman, “Software Engineering: A Practitioner’s Approach”,
Fifth Ed., McGraw–Hill Higher Education, (2001).

978-1-7281-5518-0/20/$31.00 ©2020 IEEE 943

Authorized licensed use limited to: East Carolina University. Downloaded on July 27,2020 at 22:45:44 UTC from IEEE Xplore. Restrictions apply.

You might also like