VCE IT Lecture Notes by Mark Kelly, McKinnon Secondary College
Syntax of a programming language |
||||||||
|
2011 - SD KK4.1.06- the syntax of a programming language |
||||||||
All human languages have syntax, which is the set of rules for constructing an intelligible sentence. e.g. in one language one uses the form "adjective noun" (e.g. the big dog) but in another the syntax may be reversed to "noun adjective" (the dog big). Better? Worse? No, just different. If you ignore the rules, you are either misunderstood or not understood at all. If ignore the rules you do, either misunderstood or not understood at all you are. Computer programming languages are dumb animals. They expect instructions and data to be given to them in a 100% unambiguous and predictable style. Express yourself incorrectly and the language will interpret your input with its inflexible inbuilt rules and either not understand what you say (a syntax error) or misunderstand your intent (a logic error). Neither is good. Most computer programming syntax is arbitrary - why did the language's author choose /* to mark a comment instead of an apostrophe? Who knows, and who cares? The fact is, the choice was made and you have to comply with it. Why did the same author choose SQR instead of SQRT to name the square root function? Again, it doesn't matter, but the language will understand SQR and not SQRT. That is the syntax of a language: the rules of expression, including command and function names, the order of things and the punctuation. Compare two similar routines:
All of these segments of code do exactly the same thing: display the numbers 1 to 9, but their syntax is quite different. In one language (Basic) the loop's counter is automatically incremented by the language. In C, it must be done by the programmer (i++) but the the differences are relatively minor. When learning to program, the important things are the underlying basic concepts that all languages share: variables, data types, loops, logic statements, program flow etc. Every language has these core concepts; all you have to do is memorise the syntax that each language uses to achieve the same results. Professional programmers are all fluent in at least 2 languages, probably more. Switching between languages, with practice, becomes no more difficult than switching between the language you use to speak to your mates and the language you use with your grandmother. |
Back to the IT Lecture Notes index
Back to the last page you visited
Created 13 Sep 2010
Last changed: September 13, 2010 3:24 PM
VCE IT Lecture notes copyright © Mark Kelly 2001-