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

8

43

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!

Adjoin answered 28/7, 2010 at 16:57 Comment(5)
en.wiktionary.org/wiki/semanticPregnant
@Anurag... I wasn't referring to software.Adjoin
@Bears - It was a pathetically misguided attempt to say that a question about the "semantics of" or the "meaning of" cannot be answered by something that just looks and sounds like it. You really have to understand it.Dialectal
Possible duplicate of What is the difference between syntax and semantics in programming languages?Honour
It's another way to say "meaning" :)Tiptop
E
64

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.

Ehlers answered 28/7, 2010 at 17:8 Comment(3)
multiChildStroller.width = numberOfChildrenWickliffe
@Wickliffe Actually, multiChildStroller.width = numberOfChildren * (childWidth + padding); sorry, but another semantic error. ;)Ous
perhaps numberOfChildrenWhoWontWalkAntwanantwerp
T
31

Syntax is structure. Semantics is meaning. Each different context will give a different shade of meaning to the term.

HTML 5, for example, has new tags that are meant to provide meaning to the data that is wrapped in the tags. The <aside> tag conveys that the data contained within is tangentially-related to the information around itself. See, it is meaning, not markup.

Take a look at this list of HTML 5's new semantic tags. Contrast them against the older and more familiar HTML tags like <b>, <em>, <pre>, <h1>. Each one of those will affect the appearance of HTML content as rendered in a browser, but they can't tell us why. They contain no information of meaning.

Tootsie answered 28/7, 2010 at 17:0 Comment(0)
W
9

The word ‘semantic ‘as an adjective simply means ‘meaningful’ which is very related to the word 'high level' in computer science. For instances: Semantic data model: a data model that is semantic, that is meaningful and understood by anyone regardless of his background or expertise. C++ is less semantic than Java, because Java uses meaningful words for its classes, methods and fields. HTML5 semantics: refer to the tags that describe themselves such , ,

and so on.

Wring answered 8/10, 2011 at 14:42 Comment(0)
C
8

It means "meaning", what you've got left when you've already accounted for syntax and grammar. For example, in C++ i++; is defined by the grammar as a valid statement, but says nothing about what it does. "Increment i by one" is semantics.

HTML5 semantics is what a well-formed HTML5 description is supposed to put on the page. "Semantic web" is, generally, a web where links and searches are on meaning, not words. The semantically correct way to do something is how to do it so it means the right thing.

Cotsen answered 28/7, 2010 at 17:5 Comment(0)
D
3

It is not just Computer Science terminology, and if you ask,

What is the meaning behind this Computer Science lingo?

then I'm afraid we'll get in a recursive loop just like this.

Dialectal answered 28/7, 2010 at 17:4 Comment(2)
haha... I wasn't aware of the recursive Google Search. That is hilarious!Adjoin
@Adjoin - hehe, I don't click that link myself anymore. Impossible to get out :PDialectal
J
3

In the HTML world, "semantic" is used to talk about the meaning of tags, rather than just considering how the output looks. For example, it's common to italicize foreign words, and it's also common to italicize emphasized words. You could simply wrap all foreign or emphasized words in <i>..</i> tags, but that only describes how they look, it doesn't describe why they look that way.

A better tag to use for emphasized word is <em>..</em>, because it conveys the semantics of emphasis. The browser (or your stylesheet) can then render them in italics, and other consumers of the page will know the word is emphasized. For example, a screen-reader could properly read it as an emphasized word.

Jp answered 28/7, 2010 at 17:16 Comment(0)
F
0

From my view, it's almost like looking at syntax in a grammatical way. I can't speak to semantics in a broad term, but When people talk about semantics on the web, they are normally referring to the idea that if you stripped away all of the css and javascript etc; what was left (the bare bones html) would make sense to be read.

It also takes into account using the correct tags for correct markup. This stems from the old table-based layouts (tables should only be used for tabular data), and using lists to present list-like content.

You wouldn't use an h1 for something that was less important than an h2. That wouldn't make sense.

Fibroid answered 28/7, 2010 at 17:3 Comment(0)
T
-1

The below is syntactically different but semantically the same:

C, C++, C#, Java, JavaScript, Python, Ruby, etc.
x += y

Perl, PHP
$x += $y

Tiptop answered 22/11, 2022 at 2:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.