views:

490

answers:

7

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?

+11  A: 

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")
Konrad Rudolph
This may be a meaning of "semantic" but I don't see how it fits the context (or common usage for that matter) at all.
Daniel Straight
+1  A: 

As I understand it, semantics is "what it all means to a human". It's the what it does part, not the how it does it.

Vilx-
+4  A: 

The dictionary definition applies.

Semantics is (are?) all about the meaning of words.

For example, if you use the .NET type KeyValuePair to represent something OTHER than a key and value, you've got a semantic problem. It may work... it may be the best solution, but it isn't semantically accurate.

This is exactly what he's talking about in that blog post. We list return types first in C-like languages, but really the return comes last. That's semantically inaccurate.

Daniel Straight
+2  A: 

In other words, given the context of hte article, he is saying that it would have been better for the developers of C# to concentrate on how they would store the data internally when a variable was declared and not care so much about specifying the precise method of declaring the variable.

In other words by doing this in C#

static int customerCount

you are telling the compiler to prepare storage for a statically accessable integer and then telling it to label that storage as customerCount.

whereas in VB you would use this line

dim shared customerCount as Integer

telling the compiler, in theory, that you have a variable called customerCount that it should store and make statically available, and oh by the way, it happens to be an Integer.

It all really a fine line distinction kinda thing.

Goblyn27
+2  A: 

A little more context from the blog:

Therefore in C you put the storage metadata first (static int customerCount;) rather than the semantics first (it could have been var customerCount: static int;).

He's saying that "static int" appears before "customerCount". Calling "static int" storage metadata and "customerCount" semantics. The storage metadata is information about what the variable holds - implicit in it is how many bits it occupies, what values it may hold, whether it's shared among instances, and its volatility.

The semantics, the variable name, is information for readers of the code about what should be stored in the variable. What the variable means. You could call it "x" and the program would work just as well, but it would be hard for a programmer to understand it. Calling it "customerCount" provides the variable with meaning, and that's semantics.

Carl Manaster
+2  A: 

Semantics is WHAT we mean the program should do. Sytax is language-specific constraint on how we express the semantics.

In theory, as long as a program's semantics are correct, it doesn't matter what language was used to write it.

Peter Perháč
+1  A: 
Norman Ramsey