2017-11-26

about the syntax of programming languages

keywords and identifiers

there seem to be two extremes of keyword and identifier naming styles

symbolic: languages that prefer special characters and abbreviations. examples: apl, mathematical notation, haskell, perl

indicatory: languages that prefer words from the english language and alphanumeric characters. examples: coffeescript, scheme, ruby

different ways to mark nesting

keyword

example (vbscript)

if 3 = x then
  msgbox "test"
end if

for each a in list: msgbox a: next

benefit: quick to type

bracket

example (c)

if (3 == x) {
  printf("test");
}

for (int i=1; i<array.size; i+=1) { printf("%u", array.data[index]); }

example (scheme)

(if (= 3 x)
  (display "test"))

(for-each display list)

indent

example (coffeescript)

if 3 is x
  console.log "test"

list.forEach (a) -> console.log a

benefit: code written by different authors looks more similar, because they can not vary the placement of and whitespace around brackets a lot because few brackets are used. there is also only one main pattern to nest expressions, indent

operator placement style

prefix

+ 1 2 3 4

infix

1 + 2 + 3 + 4

suffix

1 2 3 4 +


tags: programming start document syntax computer language classification