Logout

4.3.3

Explain the essential features of a computer language.

 

Teaching Note:

For example, fixed vocabulary, unambiguous meaning, consistent grammar and syntax.

TOK Language and meaning.


 

Sample Question:

sdfsdfsf

JSR Notes -

Firstly, here's an explanation of some of the English words used above, to help with your understanding:

 

All of these things result in a double-edged sword situation. You have to be very, very exact, indeed almost perfect with the code you write while programming for things to work at all, let alone the way you want them to.

Along these lines, there's a great quote that goes: "If it's almost right it's wrong".

But, conversely, with computers, "when it's right, it's completely right, and right all the time*, which is nice".
*The understanding, though is that to be "right", all exceptions, i.e. all, as in ALL, possible situations are taken into account.

 

But the point is that this is unlike an English essay, for example, where a grammar error can exist and the essay is still a great read, and indeed potentially an A+. With programming, with one solitary "grammar" (i.e. syntax) error in a program, the complier will not (at least should not) let the program be executed. But once you've got it right, you've got it perfectly right.

Along with this goes the concept that with computers and IT systems "there's a reason for everything", it's just a matter of tracking down that reason at times.

 


Syntax (vs. grammar) Versus Semantics:

The importance of consistent "grammar and syntax" are mentioned above. By grammar we generally mean the order of words, and syntax, generally the spelling.


Syntax Errors

So the following are syntax error:


System.out.printline()                 system.out.println()                 Systm.out.println()

Note that the following is as syntax error too:


String nameOfStudnt = "Charlie"; //no syntax error; we can spell the variable any way we wish.

System.out.println(nameOfStudent); //syntax error - variable not spelled the way it was initially defined.

And we could say that the following is a "grammar" error:


System.println.out();


Semantic Errors

But there's another term along with syntax that is important to get straight farily early on, and that is semantics. By semantics we mean meaning. So a semantic error is an error in meaning, or an error in intent; what we intended to happen with out code will not happen.

Here is an example of bad Java syntax but Ok semantics - there are at least three problems:


for(int i = 0 : i < 100; i++)
{
    System.out.println('Hello world')
}  

The compiler will pick up these syntax errors and not completely compile the program until you have corrected them.


And here is an example with proper Java syntax, but bad semantics:


for(int i = 0 ; i < 100; i--){
    System.out.println("Hello world");
}

The compiler will not pick up the error in intention. This infinite loop will execute, unfortunately.