NoAtomicExpression
Expressions must consist of more than one piece
A single piece, like a literal or name, also is an expression
CorrectionHere is what's right.
Even 1
is an expression.
The same applies to a
, or m()
, or new Point()
.
There is no need for an operator.
Of course an expression can involve operators,
thus 1 + 3
or 1 + a
are expressions, too.
Explain by Referring to the Definition
An expression is a piece of code that evaluates to a value. Anything that evaluates to a value is an expression. A single variable name also evaluates to a value, so does a method call (with a non-void return type), a constructor call, or even a literal (a value that stands for itself).
Explain with Expression Trees
The following tree represents the expression val + 1
:
The entire tree, rooted in +
, is an expression.
Moreover, the subtree rooted in val
, which consists of a single node, also is an expression.
The same applies to the subtree rooted in 1
,
which represents the literal 1
,
which is an expression (that always evaluates to the value 1).
Language
Concepts
Expressible In
Related Misconceptions
Other Languages
Literature References
The following papers directly or indirectly provide qualitative or quantitative evidence related to this misconception.
Quantitative systematic research
97 Swiss high school teachers and their students
Programming Language Misconceptions studied:
Qualitative and quantitative systematic research
542 hand-drawn expression trees from 12 exams in 6 university courses
Diagram mistakes studied: