What is the difference between Syntax and Semantics?
This is best handled using programming languages and errors.
When building a program, you are creating a model ( in code ) of the behavior you want. This is a description of the behavior you’d like the program to have. This description is then compiled( or interpreted ) in order to translate this description of behavior to a language a machine can understand ( zeros and ones in a certain order ). This translation of the user entered model ( for instance the C code ) to machine language ( bits ) is done with very strict rules.
Syntax errors are violations of the most basic model language construction rules. One of these rules is to never use reserved words of the language ( like IF, WHILE, etc.. ) in places where the intended FUNCTION is NOT meant. Syntax errors can be caught by the compiler, since these are seen during parsing of the code. These errors show themselves before executing code. They are static by nature.
Semantic errors are differences between the intended behavior and the implemented behavior. These errors only show themselves during execution of code. They are dynamic by nature.
Syntactic sugar : these are additions to the model that don’t change the behavior of the implementation, but are there to increase the readability of the model ( code ). Usage of white space and tabs for instance can be viewed as syntactical sugar since they don’t change the behavior of the resulting compiled code in any way. Syntactic sugar elements can be removed and the removal won’t make ANY difference in the resulting behavior of the compiled code.
Semantical sugar : these are additions to the model that don’t change the behavior of the implementation( like syntactical sugar ), but are there to increase the understanding of the reasons WHY a certain behavior was chosen. In software terms, these relate to remarks ( comments ) or carefully chosen function and variable names that explain what the reason is for the existence of a variable or function. Semantic sugar refers to the reason WHY a certain behavior was chosen. They relate to the requirements of the model.