What , Why , How is Semantic Code ???

Understanding The Semantic Code


Web designers like to throw around a lot of jargon. So, I want to focus on the more popular techno-babble and try to dispel some of the mystery. First up: semantic code.


What Is Semantic Code?

Even if you are not a web designer, you are probably aware that your site is written in HTML. HTML was originally intended as a means of describing the content of a document, not as a means to make it appear visually pleasing.


Semantic code returns to this original concept and encourages web designers to write code that describes the content rather than how that content should look.


For example, your web designer might have coded the title of your page like this:


<font size="6">
   <strong>Article Title</strong>
</font>


That would make the title large and bold giving it the appearance of a page title, but there is nothing that describes it as a title in the code. That means a computer is unable to identify this as being the page title.


To write the same title semantically so that a computer understands that this is a title, you would use the following code:


<h1>Article Title</h1>


The appearance of your heading is defined in a separate file called a “cascading style sheet” without interfering with your descriptive (semantic) HTML code.



Why Is Semantic Code Important?

One reason why semantic code is essential is that without explaining what a piece of content is, a computer has no way of knowing. The ability of a machine to understand your content is vital for two main reasons:


  • Many visually impaired people rely on speech browsers to read pages back to them. These programs cannot interpret pages very well unless the website clearly explains them. In other words, semantic code aids accessibility

  • Search engines need to understand what your content is about to rank you properly on search engines. Therefore, semantic code tends to improve your placement on search engines, as it is easier for them to understand.


However, semantic code has other benefits too:


  • As you can see from the example above, semantic code is shorter and so downloads faster.

  • Semantic code makes site updates easier because you can apply design style to headings across an entire site instead of on a per-page basis.

  • Semantic code is more straightforward for people to understand too, so if a new web designer picks up the code, they can learn it much faster.

  • Because semantic code does not contain design elements, it is possible to change the look and feel of your site without recoding all of the HTML.

  • Once again, because the design is held separately from your content, semantic code allows anybody to add or edit pages without having to have an astute eye for design. You describe the content, and the cascading style sheet defines what that content looks like.



How to Ensure a Site Uses Semantic Code?

Unfortunately, no tool can check for semantic code. It is a matter of looking at the code and seeing if it refers to colours, fonts or layout instead of describing what the content is.

If looking at code, all sounds a bit too scary then an excellent place to start is by asking your web designer if he codes semantically. If he looks at you blankly or starts waffling, you can be sure he does not.


Difference Between Syntax and Semantics

Syntax and Semantics are very significant terms relating to any programming language. The syntax in a programming language involves the set of permitted phrases of a language whereas semantics expresses the associated meaning of those phrases.

There are some relationships between syntax and semantics where each semantic element is linked to at least one syntactic rendition and the other one assures that each syntactic representation has a distinctive meaning.


BASIS FOR COMPARISON SYNTAX SEMANTICS
Basic Permitted phrases of a language. Interpretation of the phrases.
Errors Handled at the compile time. Confronted at runtime.
Relation Syntactic interpretation must have some distinctive meaning. Semantic component is associated with a syntactic representation.



Definition of Semantics

Semantics term in a programming language is used to figure out the relationship among the syntax and the model of computation. It emphasizes the interpretation of a program so that the programmer could understand it in an easy way or predict the outcome of program execution. An approach known as syntax-directed semantics is used to map syntactical constructs to the computational model with the help of a function.

The programming language semantics can be described by the various techniques 
– Algebraic semantics, Axiomatic semantics, Operational semantics, Denotational semantics, and Translation semantics.

  • Algebraic semantics interprets the program by defining an algebra.

  • Axiomatic semantics determine the meaning of a program by building assertions about an association that detain at each point in the execution of the program (i.e. implicitly).

  • Operational semantics compares the languages to the abstract machine, and the program is then evaluated as a sequence of the state transitions.

  • Denotational semantics expresses the meaning of the program in the form of a set of functions operating on the program state.

  • Translational semantics focuses on the methods used for translating a program into another language.


Definition of Syntax

The Syntax of a programming language is used to signify the structure of programs without considering their meaning. It basically emphasizes the structure, layout of a program with their appearance. It involves a collection of rules which validates the sequence of symbols and instruction used in a program. The pragmatic and computation model figures these syntactic components of a programming language. The tools evolved for the specification of the syntax of the programming languages are regular, context-free and attribute grammars.

However, what is the use of grammar in this aspect? The Grammars generally are the rewriting rules whose purpose is to recognize and generate the programs. Grammar does not rely on the computation model instead used in the description of the structure of the language. The grammar contains a finite set of grammatical categories (such as noun phrase, verb phrase, article, noun, etc), solitary words (elements of the alphabets) and the well-formed rules to specify the order within which components of the grammatical categories should appear.

Syntax analysis is a task performed by a compiler which examines whether the program has a proper associated derivation tree or not.

The syntax of a programming language can be interpreted using the following formal and informal techniques:

  • Lexical syntax for defining the rules for basic symbols involving identifiers, literals, punctuators and operators.

  • Concrete syntax specifies the real representation of the programs with the help of lexical symbols like its alphabet.

  • Abstract syntax conveys only the vital program information.


Types of grammars

  • Context-free grammar is prevalently used to figure out the whole language structure.

  • Regular expressions describe the lexical units (tokens) of a programming language.

  • Attribute grammars specify the context-sensitive part of the language.


Conclusion

The syntax of a programming language is a collection of rules to specify the structure or form of code whereas semantics refers to the interpretation of the code or the associated meaning of the symbols, characters or any part of a program.


Previous Post Next Post