Logout

Home Topic 4 Last Next

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 the key terms 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, the corollary of that - and it's good news - is that with computers, "when it's right, it's completely right, and right all the time*".

 

The point is that code is unlike an English essay, for example, where a grammar error can exist and the essay is still a good read, and indeed potentially an A+. With programming, if there is one solitary "grammar" (i.e. syntax) error in a program, the complier will 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 Errors

In Language Studies, as part of the overall grammar rules, syntax, is really only word order. But in computer programming, when we say "syntax" error, we also include the mis-spelling of the words that are part of the fixed vocabulary, and (in most programming languages) incorrect capitalization as well.

So the following all contain syntax errors:


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

Another example of syntax errors are when we are inconsistent with our own spelling of variable names. For example:

String studentName = "Charlie";
System.out.println(studentsName); 
//syntax error - variable not spelled the way it was initially defined.

Here is another example of bad Java syntax but OK semantics - there are four 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.



Semantic Errors

There's another term associated with errors, along with syntax, that is important to get straight fairly 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 with proper Java syntax, but bad semantics:


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

The Java compiler looking at the above code will not pick up the error in intention, i.e. the semantic error. This infinite loop will execute, unfortunately.