lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

"John Hind" <> dixit:

> Yes, high information density is a very mixed benefit IMHO.

I guess there is a proper measure for this, but it may be personal:

1 action <--> 1 instruction
where 'action' refers to conceptual action (in the mental model for the topic to be coded).

For instance,
   map(numbers, square)
is ok --and better than a foreach loop-- because this maps (pun intended) to a single mental operation.

On the contrary,
   map(filter(numbers, isOdd), square)
is wrong because there obviously are 2 operations. I don't think it's possible to conceive this as a single step.
If yes, then the above expression is good for the people who can (I'm not one of them, so I write it in 2 separate instructions) --if the code is never to be read by others. Note that the possibility to express a set of operations in a single natural language sentence is not a measure of conceptual action: every procedure can be expressed as a single sentence.

I think such a measure makes code reading flow regurarly and easily. Also, there is a kind of auto-commenting effect due to some more names than in dense expression:
   oddnumbers = filter(numbers, isOdd)
   squares = map(oddnumbers, square)

There is a kind of language-specific culture on this topic of code compacity. While C is the only language I learned in training course, and density is prized in C (I guess), I later "un-learnt" this practice if favor of clarity (my key word in the coding field).
A good language from this POV is one that directly makes this mapping be correct, so to say "naturally", unless one cleverly plays with the language's syntax and/or semantics. Lua is imo very good at that (not too clever, unlike eg python), except for some missing features for builtin types and some weirdities around metatables.


la vita e estrany