Search code examples
definitionsemantics

What does the word "semantic" mean in Computer Science context?


I keep coming across the use of this word and I never understand its use or the meaning being conveyed.

Phrases like...

"add semantics for those who read"

"HTML5 semantics"

"semantic web"

"semantically correctly way to..."

... confuse me and I'm not just referring to the web. Is the word just another way to say "grammar" or "syntax"?

Thanks!


Solution

  • Semantics are the meaning of various elements in the program (or whatever).

    For example, let's look at this code:

    int width, numberOfChildren;
    

    Both of these variables are integers. From the compiler's point of view, they are exactly the same. However, judging by the names, one is the width of something, while the other is a count of some other things.

    numberOfChildren = width;
    

    Syntactically, this is 100% okay, since you can assign integers to each other. However, semantically, this is totally wrong, since the width and the number of children (probably) don't have any relationship. In this case, we'd say that this is semantically incorrect, even if the compiler permits it.