PQC Verified

The Shape of Software, Seen by the Eye

by gg582 · 2026-11-07 13:50:27 · 34 views · 5 min read

Table of contents

Understanding Code Through Shapes

8gwifi.org-tikz-diagram-1794054659244.svg

The if-else family represents branching like the branches of a tree. The switch family represents polygonal branching, since execution jumps directly to each case.

A ternary operator divides into true and false paths. It is syntactic sugar intended to improve readability when evaluation is extremely simple, so there is a good reason to visualize it in a way similar to if-else.

Some compilers optimize simple branches using cmov. Extremely simple if statements and ternary operators fall into this category.

Therefore, ternary operators and if-else statements are similar. It is perfectly reasonable to visualize both using the same tree-branch shape.

Forcing complex conditions into individual cases to construct a switch statement makes the code difficult to read and makes it harder to examine each situation independently.

In other words, it becomes difficult to tell what will happen when I introduce condition A.

If a polygon has infinitely many vertices, it becomes a circle. And a circle is continuous.

What does this mean? Suppose a construct with four cases is represented as a square. Its sharp edges are immediately visible.

However, if a construct has 32 cases and is represented as a 32-sided polygon, its boundaries become difficult to distinguish when viewed from a distance. It begins to look circular.

It is easier to understand this by printing a square and a 32-sided polygon and looking at them from several meters away.

For such a large number of branches, the compiler may generate a separate comparison table. From a human perspective, the boundaries become even less visible, but internally, evaluation can jump directly to each individual entry.

The analogy of a polygon's discontinuity fits well here.

Then why did I previously advise against writing switch-case statements with too many branches? They can even improve performance.

The reason is that humans have to maintain the code.

Sixteen branches are reasonably manageable. Twenty are also fine. But tracking and following 64 individual branches is difficult.

If you really want optimization, enable compiler optimization options. The compiler can examine the structure and automatically convert it into a jump table or another suitable form.


A loop is a construct with a condition. There are also cases where the condition determines whether the loop should terminate.

The statements inside a loop form the repeating axis, while the statements outside act as observers monitoring conditions such as termination.

A switch statement beneath an if-else resembles branches and flowers: you can understand the larger structure first and then examine its smaller components. This makes the code readable.

However, if statements beneath a switch can resemble a chrysanthemum with disorderly branching beneath its receptacle, provided the density is sufficiently high. The overall shape remains visible, but its smaller components become difficult to distinguish.

People have different tendencies, but humans generally try to understand structure through the whole.

Consider the following.

ASTRONO
MY     BI
OLOGYAN
AL    OGY
NO    MAD

You probably read R before ASTRONOMY, BIOLOGY, ANALOGY, or NOMAD.

Even though this is merely an analogy, excessively dense if-else branches beneath a switch statement generally resemble a chrysanthemum. The same applies to nested switch statements when they become densely packed.

Just as individual flowers are difficult to distinguish, small if statements beneath them are easy to overlook. It is better to have only a few simple if statements that could be replaced with ternary operators.


Operator shorthand can also be understood through shapes rather than through mere technical sophistication.

The form a /= b; represents taking a piece of a itself, dividing it into b portions, and discarding all but one portion. Writing it as a = a / b; instead requires you to mentally process the assignment operation as well, which adds cognitive overhead.

a /= b; evaluates the left-hand operand only once, whereas a = a / b; does not necessarily do so.

High-Level and Low-Level

8gwifi.org-tikz-diagram-1794055868149.svg

Procedural code with few compound conditions tends to be vertically elongated.

Code with many compound conditions and branching jumps tends to be horizontally elongated.

If we consider complexity in terms of shape, boilerplate is tall and elongated (高長), while protocol specification implementations are low and wide (低廣).

Local details mean looking at something from close range.

High-level business logic means looking at something from a distance.

Consider an analogy. Implementing protocols or firmware is like looking at individual trees or small patches of forest. Middleware focuses on the body of the mountain itself.

Business logic is more like looking down at lower mountains from a high peak, as in the composition of a traditional landscape painting.

From this perspective, vibe coding that relies entirely on AI is like flying over a mountain and looking down only from its summit.

Progress becomes easier when you understand the underlying logic at least approximately before working on it. If you know nothing and attempt to survey the terrain while looking only from the mountaintop, it becomes difficult to draw the mountain itself.

That is why the argument that AI should be used "wisely" is so prevalent.

Looking at mountain ridges from an aircraft does not tell you whether pine trees or cedars grow there. You cannot even properly understand the mountain's elevation and overall terrain.

You do not necessarily need to conduct a forestry survey, but even hiking or taking a cable car gives you a better view.

However, when the program is small, the shape is reversed. In this case, you can make a rough sandcastle and judge it from above, much like a child removing excess sand after building one.

Not all vibe coding is bad. However, vibe coding is difficult when applied to certain shapes.

It is also unwise to categorically declare what those shapes are and criticize AI-generated output based on that assumption.

The evidence for determining whether code was written in a manner inconsistent with its shape exists in the actual lines of code. First, examine whether the shape has become distorted or remains intact.

This is xiangshu for code: images, but disciplined by number.

Related posts

Back
Report

Comments

No comments yet.

Markdown supported: **bold**, *italic*, `code`, lists, links, images, $math$.