Syntax, Semantics, Micronesian cults and Novice Programmers

Syntax, Semantics, Micronesian cults and Novice Programmers

Rate This
  • Comments 48

I've had this idea in me for a long time now that I've been struggling with getting out into the blog space.  It has to do with the future of programming, declarative languages, Microsoft's language and tools strategy, pedagogic factors for novice and experienced programmers, and a bunch of other stuff.  All these things are interrelated in some fairly complex ways.  I've come to the realization that I simply do not have time to organize these thoughts into one enormous essay that all hangs together and makes sense.  I'm going to do what blogs do best -- write a bunch of (comparatively!) short articles each exploring one aspect of this idea.  If I'm redundant and prolix, so be it.

Today I want to blog a bit about novice programmers.  In future essays, I'll try to tie that into some ideas about the future of pedagogic languages and languages in general. 

Novice programmers reading this: I'd appreciate your feedback on whether this makes sense or it's a bunch of useless theoretical posturing.

Experienced programmers reading this:  I'd appreciate your feedback on what you think are the vital concepts that you had to grasp when you were learning to program, and what you stress when you mentor new programmers.

An intern at another company wrote me recently to say "I am working on a project for an internship that has lead me to some scripting in vbscript.  Basically I don't know what I am doing and I was hoping you could help."  The writer then included a chunk of script and a feature request.  I've gotten requests like this many times over the years; there are a lot of novice programmers who use script, for the obvious reason that we designed it to be appealing to novices.

Well, as I wrote last Thursday, there are times when you want to teach an intern to fish, and times when you want to give them a fish.  I could give you the line of code that implements the feature you want.  And then I could become the feature request server for every intern who doesn't know what they're doing…  nope.  Not going to happen.  Sorry.  Down that road lies cargo cult programming, and believe me, you want to avoid that road.

What's cargo cult programming?  Let me digress for a moment.  The idea comes from a true story, which I will briefly summarize:

During the Second World War, the Americans set up airstrips on various tiny islands in the Pacific.  After the war was over and the Americans went home, the natives did a perfectly sensible thing -- they dressed themselves up as ground traffic controllers and waved those sticks around.  They mistook cause and effect -- they assumed that the guys waving the sticks were the ones making the planes full of supplies appear, and that if only they could get it right, they could pull the same trick.  From our perspective, we know that it's the other way around -- the guys with the sticks are there because the planes need them to land.  No planes, no guys. 

The cargo cultists had the unimportant surface elements right, but did not see enough of the whole picture to succeed. They understood the form but not the content.  There are lots of cargo cult programmers -- programmers who understand what the code does, but not how it does it.  Therefore, they cannot make meaningful changes to the program.  They tend to proceed by making random changes, testing, and changing again until they manage to come up with something that works. 

(Incidentally, Richard Feynman wrote a great essay on cargo cult science.  Do a web search, you'll find it.)

Beginner programmers: do not go there! Programming courses for beginners often concentrate heavily on getting the syntax right.  By "syntax" I mean the actual letters and numbers that make up the program, as opposed to "semantics", which is the meaning of the program.  As an analogy, "syntax" is the set of grammar and spelling rules of English, "semantics" is what the sentences mean.  Now, obviously, you have to learn the syntax of the language -- unsyntactic programs simply do not run. But what they don't stress in these courses is that the syntax is the easy part.  The cargo cultists had the syntax -- the formal outward appearance -- of an airstrip down cold, but they sure got the semantics wrong.

To make some more analogies, it's like playing chess.  Anyone can learn how the pieces legally move.  Playing a game where the strategy makes sense is the hard (and interesting) part.  You need to have a very clear idea of the semantics of the problem you're trying to solve, then carefully implement those semantics.

Every VBScript statement has a meaning.  Understand what the meaning is.  Passing the right arguments in the right order will come with practice, but getting the meaning right requires thought.  You will eventually find that some programming languages have nice syntax and some have irritating syntax, but that it is largely irrelevant.  It doesn't matter whether I'm writing a program in VBScript, C, Modula3 or Algol68 -- all these languages have different syntaxes, but very similar semantics.  The semantics are the program.

You also need to understand and use abstraction.  High-level languages like VBScript already give you a huge amount of abstraction away from the underlying hardware and make it easy to do even more abstract things.

Beginner programmers often do not understand what abstraction is.  Here's a silly example.  Suppose you needed for some reason to compute 1 + 2 + 3 + .. + n for some integer n.  You could write a program like this:

n = InputBox("Enter an integer")

Sum = 0
For i = 1 To n
      Sum = Sum + i

MsgBox Sum

Now suppose you wanted to do this calculation many times.  You could replicate the middle four lines over and over again in your program, or you could abstract the lines into a named routine:

Function Sum(n)
      Sum = 0
      For i = 1 To n
            Sum = Sum + i
End Function

n = InputBox("Enter an integer")
MsgBox Sum(n)

That is convenient -- you can write up routines that make your code look cleaner because you have less duplication.  But convenience is not the real power of abstraction.  The power of abstraction is that the implementation is now irrelevant to the caller.  One day you realize that your sum function is inefficient, and you can use Gauss's formula instead.  You throw away your old implementation and replace it with the much faster:

Function Sum(n)
      Sum = n * (n + 1) / 2
End Function

The code which calls the function doesn't need to be changed.  If you had not abstracted this operation away, you'd have to change all the places in your code that used the old algorithm.

A study of the history of programming languages reveals that we've been moving steadily towards languages which support more and more powerful abstractions.  Machine language abstracts the electrical signals in the machine, allowing you to program with numbers.  Assembly language abstracts the numbers into instructions.  C abstracts the instructions into higher concepts like variables, functions and loops.  C++ abstracts even farther by allowing variables to refer to classes which contain both data and functions that act on the data.  XAML abstracts away the notion of a class by providing a declarative syntax for object relationships.

To sum up, Eric's advice for novice programmers is:

  • Don't be a cargo cultist -- understand the meaning and purpose of every line of code before you try to change it.
  • Understand abstraction, and use it appropriately.

The rest is just practice.

  • Wow! In the long line of highly decent blogs, this has to be the top of the top. Well done Eric! I've printed (gasp) a copy out and will refer to this many times in the future. To address your query: I fall into the "experienced" programmer category. I program all day (in JScript no less!) and teach Jr/Sr High kids programming at night. This is exactly what I stress: Syntax is the easy part, it's just memorizing "ie before e except after c" type of stuff. While VB is syntactically different than C#, it has the same basic foundations, and it's those that are critical for learning. I've known some brilliant (fill in the language) coders in my time and many of them knew their language dejour in and out. But how to program...that was a different question. Thank you for the great analogy (Cargo Cult programming) and your Function Sum example is exactly what I've been using to demo implementation for a number of years. Well done!
  • My next piece of advice would be: Learn to use your debugger.

    I see it so often on message boards where a novice's code isn't working right, and they have just run the code, looked at the output (which was wrong), and then been stuck on what to do next. Often it's something simple like a reversed boolean test, or an uninitialized variable, stuff that would be immediately evident if they stepped through the code.

    After that, I'd reiterate the rule: Just because your code compiles, doesn't mean the code is correct. If it compiles, but doesn't produce the right output, then don't just throw up your hands and say "what's wrong? it compiles!" Use the debugger. If it compiles, that just means you matched up all the {} or begin/end pairs. It says nothing about the semantics.
  • You are so cool! I love this story!
  • I agree with Mike about importance of knowing your debugger, but after learning to use the debugger many people, even very experienced, remain closely tied to it. When they find a bug, they immediately begin to debug it, passing lots of code just in order to get to the _suspected_ piece and find that the problem isn't there. The continue the routine until they finally find the bug, then they fix it and feel proud of themselves.

    I think that the very important thing for novices (and not only for them) is: Learn to NOT use your debugger until you _absolutely_ have to do so. Reading logs (and putting them in necessary places in first place) and passing code in mind can give you enough information to fix the bug, and it will take tenth of time you would need to find the problem with debugger.
  • I have been programming since 1997, when I took Introduction to Computer Graphics in art school. I thought it would be Macromedia Director type stuff, and the school's course catalog was a little confusing. It turned out that it was a semester of C followed by a semester of C with OpenGL. I ended up liking it more than art courses.

    I think I can still remember what that level of knowledge was like, and I wish it had been made clearer to me just how hard it is to be a good programmer. I think most novice courses lie about this difficulty, in order not to intimidate students.

    I wish someone had showed me this:

    Teach Yourself Programming in Ten Years
  • Truthfully, I probably still fall into the "novice" category. I am less than a year out of college though, so that is acceptable in my eyes.
    I do see myself moving more towards "advanced" as the months pass. I spend less and less time throwing random print, debug, etc. statements into code trying to find the problem and more and more time analyzing the code trying to see the problem(s) before gutting it.

    Please continue these types of essays, I have been reading for a few weeks and you always have something interesting (even if some of it flies above my head the first read through).
  • As a professional programmer for many years (25 at least), I've been thru it all and back and all again. Your cargo story is right on the money. It all has to do with people's abilities to abstract information and operational levels. I use several different analogies when telling what/how programming works. First of all, scripting IS programming. All the ego-driven drivel about compiled vs. scripted, whatever is just that...ego. It's all code, it all AT SOME LEVEL controls a system in some fashion. Hell, I use Excel/Access macros every chance I get rather than writing VB(A), tho' of course, I'd rather write Java for everything...but's that's just dumb. Learn programming well and you've learned it all. Languages just become a means of expression. Again, it's the appropriate level of abstraction that counts first of all.

    Second...I've started seeing in college C.S. tracks an Introduction to Programming Concepts (or something or other) where the intent of the course is not only syntax but BEGINNING semantics i.e. how to convert a problem (usually in some form of pseudocode) into a structured block of syntactically correct code...the key here is that Structured Programming as defined in the late 70s - early 80s was NOT supplanted by object-oriented programming or by scripting but complemented it and made it easier to develop an application. Take that intro class. Get your company to pay for it.

    Next point: OOP definitely the landscape tho. I've seen the REVERSE problem: older programmers who've said to me, "Geez, you can put code just about anywhere!" which to old structured programmers appears to be some form of chaos...well, yes you can in a badly designed/written piece of OOP (whether it is script or not...everything has SOME sort of OO going on, regardless of how pure it is). Design becomes very critical with OO-based languages. ASP is a perfect example of that.

    Debuggers are important tools. Learn to use them, but learn to read/write code first. As another person said: you should know EXACTLY what every line of code does in terms of overall program behaviour. In fact, if you can't tell why that code is THERE at THAT place in the code, you shouldn't be touching it because you don't know enough.

    So in many respects it's both harder AND easier...but you have to make the first steps PAST the syntax and begin to understand the appropriate placement of lines of code into blocks that perform the FUNCTION you want.

    As I said to my son who was taking his first C++/programming class: it's like an onion, you keep peeling layers to find more layers. And if you REALLY want to master it, you'll keep peeling in spite of the tears.

    Another suggestion: READ CODE, DON'T WRITE IT!!! Everyone thinks the key to programming success is writing code. The secret to programming success is READING CODE, other people's code, on all kinds of topics/functions/apps, learn from reading, not writing (this is the secret of the whole open source...honestly we don't snitch code, we "borrow" ideas that we've read!)

    Programming in 10 years....that's the right idea!
  • My math teacher always said "It's not important to get the right answer. But it's important to get the right solution". Is it the same?
  • Getting the right answer _is_ important. Very, very important!

    But I think I see what your teacher is getting at. If I could paraphrase, I'd say that what is important is that your logic be sound. If your logic is sound then you can't help but get the right answer. Just having the right answer is not enough -- you might have guessed, or cheated, or whatever. You must have a reliable method, because that's what mathematics is all about -- coming up with methods that work EVERY TIME.

    I think your teacher is making the same point that I'm making. It's not enough to have an arithmetic technique that does the right thing. The whole point of learning mathematics is to UNDERSTAND why those techniques work, and to PROVE that they are reliable.
  • Another fabulous adventure in blog-reading. :-) A couple of thoughts. Thought one: while no one can argue that the philosophy of "understand how it works" is right, there is also the type of programmer (let's call them the programmer-by-accident, occasionally thought of as "Mort") who actually doesn't want to become an advanced programmer; he or she has some job that needs doing. Perhaps we can call them the second-job programmer, whose first job is managing or crunching numbers or whatever. This type of programmer is probably the classic cut-n-paste programmer -- "well, I found this on the Web, and it seems to work." (A nod here to Scott Hanselman's recent comment on this practice.) Such a programmer can in fact learn in a slightly way from what you're describing. Ok, here's a piece of code that I got working. It's not quite what I need. What if I change this? Aha. What if I change this? Oops, better change that back. Etc. You can learn a lot by dismantling things. (And by pestering your colleagues and fellow listserv members to help you get it working.)

    Thought two, which I believe is complementary to your thesis: programming language, eh. It's _object models_ that need to be mastered. I have a friend who's learning ASP.NET. He's competent enough in C#; when he calls me for help, it's because he's flummoxed by ASP.NET or ADO.NET. Is that semantics, too?
  • Wonderfull post. I will use the term "Cargo Cult Programmer" from now on. This is indeed something I had discovered - to a devastating hlarge percntage within the amount of professional developers (I would say 20% to 25% of all developers out there earning money are nothing more than cargo cultists), but to a much larger degree in training courses which I occasionally hold to keep my speaking skills intact.

    Here (in germany) there were a lot of retrainig programs (making an unemployment cook a programmer in 12 months), and heck - everyone I met there (with the unusual occasional exception) has been a cargu cultist, including the majority of the trainers.

    I would say we live in a bad time for IT - the problem is that IT professionals as a group do not show enough of a honour attitude. Wherever you go there is this "cheap and fast is best" thing, and most people can go through years of training and working without ever meeting any one developer who knows what he does. Cargo Cult grows on an understandig like "it is good enough to just get it working somehow".

    nice point. But copy/paste is not what makes a programme ra cargo cultist. I do copy/paste regularly, too - it is simpler. YOu want to get something special done, dig up a KB article with some sample source. Why not copy it in and use it as a starter point :-) This is not cargu cult. Cargo cult is copy / paste / clueless. THe clueless part is important here. These are the guys you meet regularly in newsgroups and message boards that have copy/pasted and now ask for the trivial modification (I foudn the sample to create a directory named "foo" - what do I need to change to create a drectory named "bar"), often saying "I get an error" (gues s which) and then being helpfull by posting some source (and the directory is created in a winform app in a dialog, and I have included the 200 pages of code - the form also handles some database interaction - so that you know what I am doing), often with a nice request for help (you can clean up the code if you want). THIS is a cargu cultist :-)

    ::when he calls me for help, it's because he's
    ::flummoxed by ASP.NET or ADO.NET. Is that
    ::semantics, too?

    No, this is him being too lazy to read the documentation. Especially ADO.NET is trivial as object model. ASP.NET is not really complex wither, but it is always an advantage to know what happens there - means: for ADO.NET it really helps a lot to know what HTML is and how the web works (it is interesting how many people working with ASP.NET have no clue about how http does work).
  • Perfect analogy. I'm neither novice or expert, but your article really spoke to me.

    I was once learning Pascal (long time ago) and at the same time assisted Fortran students - I didn't know Fortran. For the most part, it's just a different syntax for accomplishing a task, though.
  • What you need to learn first is learn to learn. I sometimes say, “A programmer who does not learn is either sleeping or dead. And I’m not actually sure about sleeping”.

    Many people ask for my help in programming matters. By “help” they usually mean “do for me”. They don’t care about learning, they want a solution, to show it to their instructor and get a passing grade. I then try to see if they can solve it on their own with a little pointing in the right direction, and if they can’t and actively resist, well, too bad for them. “Sorry, can’t help you.”
  • Cargo cult programming seems to be what I call parroting. That is people who only can answer back with what you have already told them. They can't use what they have learnt in one programming language with another programming language.

    A lot of understanding of programming comes from being thaught with the right tools. Getting the right error messages. It also helps that the teaching language reads reasonably well. Verbosity is a plus.

    That is why C/C++/Java are not good starter languages. It is the reason Ada/Eiffel/Delphi are good starting points. The latter programming languages are more productive. If you don't belive that, it is because you are unaware of how you are spending your time: You forgot to factor in the time it took you to get the program to actually work.

    Countrary to popular belief, the effectiveness of a programming language is not inverse of the number of characters a program consists of. That is probably why Cobol is alive and well.


  • How about starting education with the documentation ?
    As an experienced programmer who occasionnally has to (heck, wants to!) use scripting languages, the (human) language in which the scripting documentation is written consistently gets in my way when I'm looking for information on the _semantics_ of a scriptable API, by repeatedly addressing the syntax, probably in the assumption that a) scripting languages are for beginners and b) beginners tend to forget about the syntax.

    I'm probably not making myself clear at this point, so let's look at an example : the documentation for Microsoft's scripting runtime library. Just about any reference page will do, like for example
    (the Copy method of the FileSystemObject).

    The method is presented like this :
    object.Copy( destination[, overwrite] );

    Below, we find that "object" is an "argument" (in a very technical sense, I suppose it is) which is (must be ?) "Always the name of a File or Folder object."

    Now is that syntax or semantics ? Does that mean I can't write :

    (new FileSystemObject()).Copy(...)

    Or :



    I hope my point is clear now. I could go on for hours - in just this method's description there are several more problems such as not specifying the type of the "destination" argument (is it OK if I pass a Folder object, then ? Why not ?), but there is also the Internet SDK that insists on segregating 'properties' from 'objects' and 'collections', hopelessly confusing the cargo cultist into thinking they are funamentally different to the parent object.

    Don't you think improving the documentation should be the first priority ?

Page 1 of 4 (48 items) 1234