Docsity

Tok Module Design: Analyzing Function Size, Complexity, and Quality, Exams of Software Engineering

Toggle sidebar
bg1
3.5 Tok Module Design
The tok module is well designed, although there are a few concerns regarding testing. Looking at Table 5.1, we see that the fifteen
member functions in tok are all small and have low complexity except for the important getTok function. This function is the main
interface to the module and consists of 60 lines of code and an awesome cyclomatic complexity of 25. Generally, one would like to
see complexity less than 5 or 6, so this implies that the getTok function will be hard to test and may contain lingering latent errors.
These worries are somewhat allayed by the well organized layout of the function’s code. However, there is a lot of internal state and it
seems clear that testing will be difficult.
The names of the functions clearly denote their operation, and each possesses a very good or excellent abstraction. For example, the
eatComment function is aptly named – it consumes text until it encounters a comment terminator. Furthermore, the public interface is
small, consisting of five of the thirteen functions, and they are well documented in the module’s manual page. All of the functions
have very good to excellent cohesion. The eatComment function has very good cohesion because its only task is to consume
comments. Its cohesion would be rated as excellent except for the fact that it deals with both C and C++ style comments.
The tok module’s coupling is very good. Two public functions take no arguments, other than the tok class’s internal state. Two
public and one private functions take a single primitive type as arguments. All the other functions, two public and six private
functions, take a single object reference as arguments. There is very little assumption coupling between the tok module and its users.
The only significant assumption is made by getTok(). It assumes that the stream handed to the toker constructor has been successfully
attached to a file to be tokenized.
Locality of Reference and Use of Objects attributes are assigned as follows. If the references are entirely local – that is, to local
variables only, then the rating is excellent. If the references are to local and class member data, and standard C++ library identifiers,
then the rating is very good. References to standard C library identifiers are rated as good. Each function has the rating of its lowest
rated reference. Use of Objects ratings are excellent if most references are to standard library objects or user defined objects. Very
good Use of Object ratings go to functions that refer only to member data of the tok class. Functions that are extremely simple and
make no references to objects are rated as NA – not applicable.
Looking at the summary data in Table 5.1, we see that this module accomplishes a fairly sophisticated set of operations for a very
small number of lines and low total complexity. It has a well designed abstraction with tight cohesion and loose coupling, both very
desirable properties. Finally, it uses objects – streams and strings - from the standard library effectively and needs few references
beyond its own member data and two of the standard libraries.
pf2

Partial preview of the text

Download Tok Module Design: Analyzing Function Size, Complexity, and Quality and more Exams Software Engineering in PDF only on Docsity!

3.5 Tok Module Design The tok module is well designed, although there are a few concerns regarding testing. Looking at Table 5.1, we see that the fifteen member functions in tok are all small and have low complexity except for the important getTok function. This function is the main interface to the module and consists of 60 lines of code and an awesome cyclomatic complexity of 25. Generally, one would like to see complexity less than 5 or 6, so this implies that the getTok function will be hard to test and may contain lingering latent errors. These worries are somewhat allayed by the well organized layout of the function’s code. However, there is a lot of internal state and it seems clear that testing will be difficult. The names of the functions clearly denote their operation, and each possesses a very good or excellent abstraction. For example, the eatComment function is aptly named – it consumes text until it encounters a comment terminator. Furthermore, the public interface is small, consisting of five of the thirteen functions, and they are well documented in the module’s manual page. All of the functions have very good to excellent cohesion. The eatComment function has very good cohesion because its only task is to consume comments. Its cohesion would be rated as excellent except for the fact that it deals with both C and C++ style comments. The tok module’s coupling is very good. Two public functions take no arguments, other than the tok class’s internal state. Two public and one private functions take a single primitive type as arguments. All the other functions, two public and six private functions, take a single object reference as arguments. There is very little assumption coupling between the tok module and its users. The only significant assumption is made by getTok(). It assumes that the stream handed to the toker constructor has been successfully attached to a file to be tokenized. Locality of Reference and Use of Objects attributes are assigned as follows. If the references are entirely local – that is, to local variables only, then the rating is excellent. If the references are to local and class member data, and standard C++ library identifiers, then the rating is very good. References to standard C library identifiers are rated as good. Each function has the rating of its lowest rated reference. Use of Objects ratings are excellent if most references are to standard library objects or user defined objects. Very good Use of Object ratings go to functions that refer only to member data of the tok class. Functions that are extremely simple and make no references to objects are rated as NA – not applicable. Looking at the summary data in Table 5.1, we see that this module accomplishes a fairly sophisticated set of operations for a very small number of lines and low total complexity. It has a well designed abstraction with tight cohesion and loose coupling, both very desirable properties. Finally, it uses objects – streams and strings - from the standard library effectively and needs few references beyond its own member data and two of the standard libraries.

Table 3.1 - Tok Module Design Attributes

function size complexity Abstraction Cohesion Coupling Local’y Ref Use of Objects codeDelimiter::operator() 14 1 VG^1 E E E NA xmlDelimiter::operator() 16 1 VG E E E NA lines 2 1 VG E E VG NA scopeLevel 2 1 E E E VG NA nestedComments 2 1 VG E E VG NA collectSingleQuotes 4 1 E E E VG NA toker 4 1 E E VG VG E type 8 4 VG E E VG NA isComment 11 5 VG E VG VG E isWhite 10 4 VG E VG VG E eatWhite 15 4 E E VG G E eatComment 37 10 E VG VG G E isQuote 8 3 VG VG VG VG E collectQuote 15 6 E VG VG VG E getTok 61 25 E VG VG G E Totals or Average 174 65 VG-E VG-E VG G-VG E (^1) operator() supports the C++ functor notation. Its abstraction is very good only if the reader understands the use of C++ functors.