ArticleslgStudy

computer science

Programming complexity

Programming complexity is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Programming complexity rather than just read about it. In short: Programming complexity (or software complexity) is a term that includes software properties that affect internal interactions. Several commentators distinguish between the terms "complex" and "complicated".

Key takeaways

  • Programming complexity belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Programming complexity to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Programming complexity from memory before moving on to harder problems.

Reference excerpt

Programming complexity (or software complexity) is a term that includes software properties that affect internal interactions. Several commentators distinguish between the terms "complex" and "complicated". Complicated implies being difficult to understand, but ultimately knowable. Complex, by contrast, describes the interactions between entities. As the number of entities increases, the number of interactions between them increases exponentially, making it impossible to know and understand them all. Similarly, higher levels of complexity in software increase the risk of unintentionally interfering with interactions, thus increasing the risk of introducing defects when changing the software. In more extreme cases, it can make modifying the software virtually impossible. The idea of linking software complexity to software maintainability has been explored extensively by Professor Manny Lehman, who developed his Laws of Software Evolution. He and his co-author Les Belady explored numerous software metrics that could be used to measure the state of software, eventually concluding that the only practical solution is to use deterministic complexity models.

Types The complexity of an existing program determines the complexity of changing the program. Problem complexity can be divided into two categories:

Accidental complexity relates to difficulties a programmer faces due to the software engineering tools. Selecting a better tool set or a higher-level programming language may reduce it. Accidental complexity often results from not using the domain to frame the form of the solution. Domain-driven design can help minimize accidental complexity. Essential complexity is caused by the characteristics of the problem to be solved and cannot be reduced.

Measures Several measures of software complexity have been proposed. Many of these, although yielding a good representation of complexity, do not lend themselves to easy measurement. Some of the more commonly used metrics are

McCabe's cyclomatic complexity metric Halstead's software science metrics Henry and Kafura introduced "Software Structure Metrics Based on Information Flow" in 1981, which measures complexity as a function of "fan-in" and "fan-out". They define fan-in of a procedure as the number of local flows into that procedure plus the number of data structures from which that procedure retrieves information. Fan-out is defined as the number of local flows out of that procedure plus the number of data structures that the procedure updates. Local flows relate to data passed to, and from procedures that call or are called by, the procedure in question. Henry and Kafura's complexity value is defined as "the procedure length multiplied by the square of fan-in multiplied by fan-out" (Length ×(fan-in × fan-out)²). Chidamber and Kemerer introduced "A Metrics Suite for Object-Oriented Design" in 1994, focusing on metrics for object-oriented code. They introduce six OO complexity metrics: (1) weighted methods per class; (2) coupling between object classes; (3) response for a class; (4) number of children; (5) depth of inheritance tree; and (6) lack of cohesion of methods. Several other metrics can be used to measure programming complexity:

Branching complexity (Sneed Metric) Data access complexity (Card Metric) Data complexity (Chapin Metric) Data flow complexity (Elshof Metric) Decisional complexity (McClure Metric) Path Complexity (Bang Metric) Tesler's Law is an adage in human–computer interaction stating that every application has an inherent amount of complexity that cannot be removed or hidden.

Chidamber and Kemerer Metrics

Chidamber and Kemerer proposed a set of programming complexity metrics widely used in measurements and academic articles: weighted methods per class, coupling between object classes, response for a class, number of children, depth of inheritance tree, and lack of cohesion of methods, described below:

Weighted methods per class ("WMC")

W M C = ∑ i = 1 n c i {\displaystyle WMC=\sum _{i=1}^{n}c_{i}}

n is the number of methods on the class

c i {\displaystyle c_{i}} is the complexity of the method Coupling between object classes ("CBO") number of other class which is coupled (using or being used) Response for a class ("RFC")

R F C = | R S | {\displaystyle RFC=|RS|} where

R S = { M } ∪ a l l i { R i } {\displaystyle RS=\{M\}\cup _{all\ i}\{R_{i}\}}

R i {\displaystyle R_{i}} is set of methods called by method i

M {\displaystyle M} is the set of methods in the class Number of children ("NOC") sum of all classes that inherit this class or a descendant of it Depth of inheritance tree ("DIT") maximum depth of the inheritance tree for this class Lack of cohesion of methods ("LCOM") Measures the intersection of the attributes used in common by the class methods

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Programming complexity

Start with the simplest possible case. Write down what Programming complexity claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Programming complexity before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Programming complexity ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Programming complexity

In research
Programming complexity appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Programming complexity in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Programming complexity is common in secondary-school and first-year university syllabi. It links to neighbouring topics Complex systems theory, Software metrics, so understanding it makes those chapters shorter.
In everyday life
Look for Programming complexity outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Programming complexity” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Programming complexity in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Programming complexity means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Programming complexity out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Programming complexity in simple terms?

Programming complexity (or software complexity) is a term that includes software properties that affect internal interactions. Several commentators distinguish between the terms "complex" and "complicated".

Why does Programming complexity matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Programming complexity?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Programming complexity.

Tags

  • Complex systems theory
  • Software metrics

Keep exploring