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
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")
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.
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.
In terms of programming-language jargon, there are several notions of semantics:
Static semantics tells you which programs that are grammatical are also well formed. Many languages either have no static semantics (Scheme, Ruby, Python, Icon, Lua, Perl) or have a static semantics that is primarily about implementing a type system (Java, C, C#, Haskell). "Declaration required before use" is another possible static semantics. Static semantics answers the question "is this program meaningful?" and does so at compile time.
Dynamic semantics tells you one of two things:
If you read the word "semantics" in a manual or article, and the context is informal English rather than precise mathematical description, the author is probably referring to the dynamic operational behavior—if you will, an operational semantics informally described. This kind of informal description can be quite helpful to compiler writers and programmers.
In other words, given the context of the 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.
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.