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 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".

 

But the point is that code 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 ) 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 incorrect capitalization as well.

So the following all contain syntax errors:


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

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.


Semantic Errors

But there's another term associated with errors, 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.


Now, 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.