Introduction to Programming for Laymen

sarkinen.com > johan > Teaching > Programming

3. What Is a Language?

< 2. Why Learn Programming? 4. What Languages to Learn >

Words, Syntax, Semantics

Learning a formal and constructed language - like a programming language (e.g. JavaScript) or a markup language (e.g. HTML) - is basically no different from learning a natural language like English or Swedish.

You need to learn words and grammars, and consider semantics (the meaning). And practice - practice a lot!

When engineers talk about formal languages, you will more often see syntax instead of grammar1. So, from an engineering and computer science major viewpoint:

Words:  

the vocabulary the language have, often denoted reserved words in programming languages

Syntax:   how words may be put together, the rules for putting words together (~grammar in natural languages)
Semantics:   the meaning of how the words were put together

1 Note that syntax and grammar are not identical terms, but let's not muddy the waters here with too much unnecessary semantics. (Google difference between grammar and syntax)

As a brief illustration, English natural language:

Words:  

an, arrow, banana, flies, fruit, like, time

Syntax:   Order of nouns, verbs, predicates, ...
Semantics:  

Time flies like an arrow;

fruit flies like a banana.

The sentence above is an absolutely great example of a completely correct sentence - in English - but with details both someone learning English and a computer would have problems understanding.

Some additional references:

Other Disciplines - Maths, Logic, ...

And like when communicating in a natural language like English, you are also using other disciplines - probably more or less without really thinking too much about them - like mathematics and logic.

Humans = Smart, Computers = Dumb

As you soon will realize, all the above (words, syntax, semantics, logic, and mathematics) are all crucial components of programming, or using a markup- or query language.

The main difference is we as humans are really smart and easily handles issues with semantics, are forgiving with (minor) grammatical (syntactical) errors, etc, and computers must be told exactly everything - no room for ambiguities.

In English natural language In JavaScript programming language
- correct (intended) semantics

 

"First I have to pay the bills but if I
have thousand dineros left I will buy
a nice present for my spouse
otherwise I have to call the debtors
and discuss payments of the bills."

 

Even if a sentence with both serious

grammatical and logical problems,

we all understand the meaning.

 

 

$cash_at_hand = check_wallet_subroutine();
$current_bills = check_outstanding_debt_subroutine();
if ($cash_at_hand >= $current_bills)
{
    // Ok, at least have enough dough to pay the bills...
    $cash_at_hand = $cash_at_hand - pay_bills_subroutine();
    if ($cash_at_hand >= 1000)
    {
        // great, can also buy a nice present!
        go_shopping_subroutine( $cash_at_hand );
     }
}
else
{
    call_debtors_to_negotiate_payments();
}

We'll get back to this example later in regard to intendations, proper writing of code, and debugging (troubleshooting).

References


< 2. Why Learn Programming?4. What Languages to Learn >
Updated 2013-01-05

sarkinen.com | Personnel | Businesses | General/Adm | webmaster | J&P Group (JandP.biz)
Copyright © 1999-2016 J. Sarkinen. All rights reserved.