Syntax & Semantics (Structure & Meaning) in Programming Languages & Life

| | TrackBacks (0)

Two concepts introduced early-on in the career of any aspiring programmer are » syntax & semantics. Syntax refers to the structure (or form) of code that a programming language specifies. Semantics refer to the meaning .. assigned to symbols, characters & words.

Arabic numeral threeI first became familiar with the notion of syntax while studying Cascading Style Sheets. CSS syntax employs the following form » selector {property:value}. Simple enough, no?

This form/structure allows you to style your web pages with 'rules' such as » p {color:green} .. which will change the color ('property') of text in a paragraph ('p' = selector) to (a 'value' of) » green.

While CSS might not be an official programming language, it does contain aspects that (in some ways) resemble them. And all programming languages employ syntactic rules. BTW - here's a good CSS book.

A professor once told me that the standard form (syntax) of a sentence in the English language is » Noun-Verb-Direct Object. In other words » 'Bill hit the ball.' Or, 'Mary ran up the the hill.' ( "This does that to the other." )

Most English-speaking people would agree that this format tends to work best (to convey ideas). But it is not a hard-n-fast rule. You can easily say » 'Up the hill ran Mary,' or 'Mary up the hill ran.' People might think you weird, but they'll know what you mean.

In English, we say "black beans." But the Spanish-speaking Mexicans here in Southern California put the adjective AFTER the noun » "Frijoles negros." (Can't believe frijoles negros has its own dang Wikipedia entry.) I'm chowing on a bowl of some frijoles negros & rice right now.

Programming languages (on the other hand) have little sense of humor. Break one of their structural rules and they will not only protest, but boycott your program outright. Obviously there are reasons for this strict precision. There can be no misunderstanding.

••• today's entry continues here below •••

Semantics & Symbols | Meaning is Arbitrary

Semantics refer to MEANING. The arabic symbol '3' (for example) contains no meaning in and of itself. They are just pixels on your screen (or a blob of ink on your paper).

You & I assign meaning to it. We assign the numeric value » 'three'. Indeed the whole literate world seems to agree with us in this numeric assignment. And obviously, it works for us. But only because we agree on this convention.

While studying the topic of semantics (not to be confused with Symantec), it struck me that I (my brain) had 'hard-linked' (so to speak) the numerical idea of the number 'three' with the symbol shaped thusly » 3. And it struck me even more that I hadn't noticed the semantic coupling hiding there. I'd always assumed the symbol and the nunmeric value were one & the same.

This idea stuck with me for some time afterward .. as if talking to me .. that an unseen semantic link existed between symbols/words and their associated meanings .. but only because WE put them there.

Train couplingAnd if WE put them there (here's comes the cool part) .. then we could take them away (decouple them) .. or replace them outright.

I used to work with this guy everybody called 'Bubba.' (Big burly guy with a bushy beard.) Bubba was very smart and gregarious but a little eccentric. His study of the brain/mind led him to believe that "pain is not real" (as he liked to say).

If you burnt your hand (he argued), your brain "interprets" the signals from the nerves in your hand AS pain.

(I've known some who interpret pain as something pleasurable .. an interesting twist, seeing both signals use the same neural conduits.)

In a way, Bubba was right. Because, if you block the signals coming from your hand (with good drugs, for example), you would no longer feel any pain. Yet your hand would still be damaged .. perhaps even blistered or charred.

I don't want to get side-tracked (on Bubba, who was from Boston, or his entertaining ideas), but my point is » we often make "connections" (or associations) .. assigning meaning to things .. without ever realizing it.

I could be wrong, but it seems that these 'connections' (which assign various 'meanings' to various symbols & characters, & groups of characters called words) lie at the heart of programming languages .. and indeed ALL written languages.

After we learn what symbols & characters are contained in a particular language, the next step is to learn the rules for assembling (syntax) those symbols & characters into 'grammatically' correct sentences. Then we learn what meaning has been assigned to the various symbols & characters (semantics).

Lastly, we try to become proficient at manipulating those symbols & characters (in accordance with syntactic rules) to accomplish the things we desire (.. such as changing some text to green).

But the meaning is arbitrary (as Bubba will gladly tell you). It's not hard-wired. Rather, it's merely a convention that we agree on .. or something the designer of a particular programming language specifies. Tho it certainly appears fixed because everybody seems to treat it as such.

This concept (of unfixed semantics) it seems, has applications that extend far beyond programming languages. If we aren't aware that we make these connections & associations, and that they aren't really hard-wired/fixed, we can never question them. And if we never question them, we have no hope of changing them.

Hopefully the awareness of the malleability of the semantic link (that we, ourselves create) will lead us to question the unquestionable and take less for granted. And maybe even make some changes in our semantic associations .. to eliminate some pain. Wish I could remember Bubba's real name.

For more along these lines, here's a Google search preconfigured for the query » syntax semantics computer programming language

« Previous Rad entry ||| NEXT Rad entry »

0 TrackBacks

Listed below are links to blogs that reference this entry: Syntax & Semantics (Structure & Meaning) in Programming Languages & Life.

TrackBack URL for this entry: http://radified.com/cgi-bin/xmt4/mt-tb.cgi/166

About this Entry

This page contains a single entry by Rad published on August 31, 2009 11:36 AM.

Programming Feels Like Coming Home was the previous entry in this blog.

Horrible Dream @ 4:44 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.