In terms of programming, what do semantics mean?

Richard Nienaber picture Richard Nienaber · May 27, 2009 · Viewed 11k times · Source

This is a sentence from Eric Lippert's blog:

Given that unfortunate situation, it makes sense to emphasize the storage mechanism first, and then the semantics second.

It's easy to get a dictionary definition of what "semantic" means but what does it mean in terms of computer jargon?

Answer

Konrad Rudolph picture Konrad Rudolph · May 27, 2009

but what does it mean in terms of computer jargon?

Essentially the same thing. Example:

x = 5;

The above is the syntax (representation). The meaning (i.e. the semantics) of this term is to assign the value 5 to a symbol (variable, whatever) called x. Different languages offer different syntaxes to provide the same semantics. For example, the above assignment would be written as

x := 5;

in Pascal, and as

x <- 5

in several other languages. In all cases, the meaning is essentially the same. But sometimes, the same syntaxes can also have different meanings, depending on the language and/or context. VB for example redefines the equals operator to mean two different things. First, an assignment, just as above.

Secondly, in the following code sippet, rather than assigning, it takes the meaning of comparing two values:

If x = 5 Then Console.WriteLine("x is 5")