Two definitions quoting one of our favourite courses1.
- Syntax. By syntax, we mean the rules that define what forms a well-formed program in the language. Including the keywords, restrictions on whitespace and formatting, punctuation, operators, etc.
- Semantics. By semantics, we mean the rules that define the behavior of programs. In other words, semantics is about the meaning of a program—what computation a particular piece of syntax represents. Note that although "semantics" is plural in form, we use it as singular. That's like "mathematics" or "physics".
So then, what is code readability?
- Code readability = syntax that make semantics obvious.
If a block of code is written in an imperative style or functional style doesn't matter. Ask yourself instead, are the semantics clear? Are we coping or moving the values? Are we cloning the references? Are we iterating over mutable references or copies of the value?
A good language, with good code readability, makes semantics obvious. A good programmer, encourages good readability. With good readability we don't have doubts about what a piece of code is doing.
1 Cornell Ocaml cs3110 cs3110