Skip to content

Comment on A word for “the number of things you need to know to understand the code”?parent

Comments

Clickable:

https://en.wikipedia.org/wiki/Halstead_complexity_measures

https://en.wikipedia.org/wiki/Cyclomatic_complexity

Halstead complexity is about the call graph: the number of possible paths through the code.

Cyclomatic complexity is about the number of 'units of syntax' in the code, which I think is closer to what OP is asking. It uses the terms "operator" and "operand".

In the terminology typically used around parsing code, one way to measure complexity is the number of tokens. In the Halstead terminology that would be both operators and operands. https://en.wikipedia.org/wiki/Lexical_token

Another is the number of symbols. The Wikipedia article is a little abstract: https://en.wikipedia.org/wiki/Symbol_(programming) but in the Halstead terminology would be operands.

(The following is a little hand-wavy because the definition of "symbol" varies.)

Tokens, space delimited: if ( obj . index == 0 && ( f_mode > 3 || state [ 1 ] != null ) )

Symbols: if obj index f_mode state null

versus

Tokens: if ( Membership . IsExpired )

Symbols: if Membership IsExpired

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.