views:

2673

answers:

39

A friend of mine asked me the other day if I'm just looking at lists of numbers when I'm programming, or how it works. I tried to explain that it's generally more like math formulae, with the odd english word tossed in, and that it's generally mostly readable. But that's a very vague explanation, and it doesn't really explain much to a non-programmer.

But it got me to thinking about what would make a good example. Not because I want to teach her programming or anything, but simply to give her an idea of what program code "looks like".

And that got me to wonder about what would actually work as a good example. And that's turning out to be surprisingly difficult.

My first thought was obviously a simple "Hello World" program. But it really doesn't show anything useful. It doesn't really show how we use functions, or variables, or control flow structures like if or while to make a program that actually does something. There's no logic to it. The program doesn't react to anything.

So perhaps something like computing prime numbers would be a better example. But then again, that might be too theoretical and impractical... (What good is that? What does it have to do with writing "real" programs?) And again, there's no significant control flow logic in it. It's just a straight sequence of maths.

And also, which language should be used?

Ideally, I don't think it has to be a very "clean" language. But rather, it should probably make the structure clear. If it does that, then a certain amount of noise and clutter might be fine. Perhaps something like C++ would actually be a better example than Python for that reason. The explicit curly braces and type specifiers are obvious "hooks" to help explain how the program is structured, or to highlight that it's not just simple statements that can almost be read out as english.

But with C++ we also get into some downright weird syntax. Why is std::cout << x used to print out x? Why not a "normal" function call syntax? And printf isn't much better, with its arcane format string, and lack of extensibility (do I want to complicate the program by using char* for strings? Or do I use std::string and settle for calling the seemingly unnecessary s.c_str() to get a string that can be printed with printf?

Perhaps a higher level language would be better after all. But which one? And why?

I know there are plenty of similar questions here about which language/example program to use to teach programming. But I think the requirements here are different. When teaching programming, we want simplicity more than anything. We want to avoid anything that hasn't been taught yet. We want to make sure that the student can understand everything on the screen.

I'm not interested in simplicity per se. But rather in giving an "outsider" an idea of "what a program looks like". And programs aren't simple. But they do generally exhibit a certain structure and method to the madness. What language/program would best highlight that?

Edit
Thanks for all the suggestions so far. Some of you have had a somewhat different angle on it than I'd intended.

Perhaps an example is in order. I can't fly an airplane, but I've got a basic understanding of what the cockpit looks like, and what a pilot "does" while flying.

And I'm not a trained carpenter, but I know a saw or a hammer when I see one.

But when you see anything to do with programming in movies, for example, it's usually just screens filled with garbage (as in the green text in the Matrix). It doesn't look like something a normal human being can actually do. There's nothing recognizable in it. Someone who isn't a programmer simply thinks it's black magic.

I don't want to teach her to fly, or to program software. But I'd like to give her a basic frame of reference. Just an idea of "ah, so that's what you're working with. So it's not just random symbols and numbers on the screen". Even just showing a simple if-statement would be a revelation compared to the Matrix-style random symbols and numbers.

Some of you have suggested explaining an algorithm, or using pseudocode, but that's what I want to avoid. I'd like something that simply shows what actual code looks like, in the same way that you don't have to be a carpenter to look at a saw and get a basic idea of what it is and how it works.

When I was a kid, we once went on vacation in Italy. On the way down, the pilot let me into the cockpit of the plane. Of course, I didn't learn how to fly the plane. But I did get a peek into the pilot's world. I got an idea of how they make the plane go, what the pilot actually does.

That's really all I want to do. My friend has no interest in learning programming, and I don't want to force her to understand source code. But she was curious about what kind of tools or entities I work with. Is it Matrix-style symbols scrolling across the screen? Pure mathematics? English in prose form?

All I'm interested in conveying is that very high-level understanding of "What does it look like when I work".

+1  A: 

I say show him bubble sort.

It's an easy, understandable trick, converted to a formal language.

That's what our job is about. Expressing our ideas in a strict, formal language, such that even a machine can understand. A little similar to designing procedures for organizational design.

Pavel Radzivilovsky
But sorting (unless you are obsessive regarding your CD collection) is not something people do routinely in "real life". And if they do do it, they certainly don't use a bubble sort.
anon
But isn't that what makes it a good example? You don't program a computer like you give instructions to a person. Computers don't have intuition; or the ability to see, and take, a proper shortcut. The fact that a bubble sort even EXISTS explains we have programmers at all. Many facets of programming are reliant on the fact that computers are fast, not smart.
mmc
Bubble sorting is the *default* sort for normal humans (you have 7 cards in your hand, how do you go about arranging them?). I think it's a great example.
Seth
@Set I look at them ALL AT ONCE and find the largest. What I don't do, is look at card 1, compare it with card 2 etc. in a loop.
anon
When I have to sort large numbers of items, such as when I had to unpack a thousand or so books and put them in order on my shelves, I think I use something more like an insert sort.
Rich
Yeah, I'd say insertion sort is a more normal human algorithm (although as Neil pointed out, we can usually look at larger batches than 2 cards at a time to find the largest card. But once we have the largest one, we usually do something like insertion sort.)
jalf
@Neil, Maybe your ability to look at them all at once is an abstraction over your brains actual sorting algorithm :) You know there has to be one.
Carson Myers
+5  A: 

When my 5 y.o. daughter asked me the question I made her "develop" the program for a little arrow "robot" that will get him into the upper-left-corner of the board using flowchart-like pieces of paper signifying moves, turns and conditions. I think it applies to grown-ups as well.

I do not claim the invention of this answer, though.

About your edit: I'm afraid, programmers have even less idea of the idea others have about programming. ;-) People think that programming is a matrix-like green video card corruption about as much as they think that spies are all equipped with James Bond's hi tech toys. And any professional in any field is normally irritated when watching the movie concerning his job. Because the movie maker has no idea! Do we know how to properly depict programming in the movie on the other hand? ;-)

Michael Krelin - hacker
Sometimes programming is more like RoboRally (http://en.wikipedia.org/wiki/RoboRally) than is entirely comforting.
itowlson
There's a beginning Python programming environment called [Guido van Robot (or GvR)][1] that is really quite nicely done. Surprisingly it involves learning to drive a little robot icon around a grid in various ways.[1]: http://gvr.sourceforge.net/
Peter Rowell
itowlson, I knew the technique from the precursor of now-available Russian programm KuMir (can't remember its name) back in school in late 80s ;-)
Michael Krelin - hacker
Peter, at first I thought it would be more comfortable if it didn't involve neither computers nor the language. It turned out, though, that writing steps down like we do in programming languages is an acceptable technique now that she's 5 years and 4 months old when we had another programming "session"
Michael Krelin - hacker
+2  A: 

I would just write something in pseudocode that demonstrates how to use a computer to solve an everyday problem. Perhaps determining which store is cheaper to buy a particular grocery list from or some such.

jball
+41  A: 

BASIC

10 PRINT "Sara is the best"
20 GOTO 10

Update: when I was 12, my cousin (he was 14) brought Turbo Pascal 7.0 and installed it in my computer.
He programmed a tic tac toe game from scratch (in BGI mode, for those who know).
I watched/observed step by step how a program evolves until it becomes a complete application.
Until then, I knew only how to print strings in BASIC :-B

You can do a similar thing. Pair programming. Well, actually your friend will be an observer but she'll get an idea ;)

Nick D
Actually, I think this is the best idea so far.
anon
It's certainly the best Sara :).
Liran Orevi
Provided the number of times she would be praised by now... (the answer was submitted 37 minutes ago, according to SO)
Michael Krelin - hacker
... she would overflow this thread, I know :-)
Nick D
+1 for pair programming, and the fact that you can guide her through step by step and show her the output sounds pretty cool!
melaos
+1 at least for mentioning BGI :) --- As a side note, my grandma was very proud when she saw her name in one of my first basic programs - Else.
peterchen
Unfortunately, the OP says "My friend has no interest in learning programming".
Stephen C
@Stephen C, she doesn't have to learn programming. Watching a painter drawing a portrait doesn't make you a painter too.
Nick D
+1: BASIC was designed originally as a teaching tool for more complex languages. It might be worth noting that <subjective>getting too happy with just BASIC and trying to use it for serious application can lead to brain damage</subjective>. I was one of those brain damaged kids who learned BASIC as a young teenager for years and carried over a lot of bad habits when I transitioned to C and eventually C++. That might not be the case so much nowadays if one were to look at Visual Basic.NET, for instance, which deviates quite a bit from earlier versions of BASIC (ex: includes OOP).
A: 

I vote for quicksort, which is more elegant than bubble sort and easier to understand too:

qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
Rich
Yes, most people have no trouble at all thinking recursively.
anon
I'm glad that you share my faith in most people! ;)
Rich
That code doesn't make sense to _me_ and I'm a programmer :p I doubt Haskell is a good language to start with.
nlaq
But is this representative of real-world source code? Where are the helper functions? Where's the notion of writing different bits of code that work together to produce the desired result? Quicksort feels more like a party trick, a way to impress a beginning programmer with how recursion can solve all your problems.
jalf
But you could explain it really easily using cards with numbers on or something. "Okay, pick a card!" "Got one!" "Put the card on the table and then go through the other cards, putting smaller numbers in a pile to its left and bigger numbers in a pile to its right" "Done!" "Now do the same to each of the piles!" "Right!"
Rich
Dude, that's what quicksort looks like in Haskell? It looks incredibly strange, but I think I can wrap my head around in it... that's actually quite elegant.
Mark
It's easier to understand if you know that x:xs is a list with head x and tail xs, that (< x) is a function that returns True if the argument is less than x and False otherwise (and similarly for (>= x) ), and that ++ is the list concatenation operator.
Rich
neat. I have a book about haskell I have barely begun reading. Too much else to do in my programming time
Carson Myers
I've only just started learning Haskell but it's fun. It's certainly made my Javascript code a little, um, different...
Rich
+1  A: 

Code up something quick that reads stock quotes and writes them to an excel spreadsheet. This is easy enough to do with a few minutes and impresses non technical types very quickly as they see the practical value of it.

ennuikiller
It's not really about "impressing" though, but just about giving them an idea of what code "looks like". Something that basically goes "call library A. Pass result to library B" probably isn't ideal.
jalf
maybe "impressing" wasnt the correct word. Substitue "shows the value of" instead
ennuikiller
Yeah but what I want is really to give her an idea of what it means when I say I'm programming. What am I looking at, if not just tables of raw numbers or 1's and 0's?
jalf
this would do as it involves input, output, and computation (show the average of the stock prices or something.
ennuikiller
A: 

Show R's basics, it is easier than C to understand, has many build in functions such as mean or sqrt, and at least R's assigment sign is "<-"

ilhan
I would have thought `=` was an easier assignment operator for a non-programmer to get, since it stems from way back in algrbra... y=2x etc
Carson Myers
Algebraic `=` is both ways, while assignment is one way: it assigns the right hand side to the left hand side. Both `:=` and `<-` are thus better symbols.
Adrian
@Adrian, while that's true that "=" is bidirectional in mathematics, most people I've tutored seemed to immediately understand its use in programming. Unfamiliar symbols such as ":=" and "<-" would only serve to confuse those not already very familiar with mathematics. And those folks seldom have any issues understanding the basics of programming. . . Heck many of those folks write programs to help solve advanced math problems. . . It's best to stick with what your audience knows...
Jason D
+27  A: 

I would explain that programming is giving detailed instructions so the computer can make complex tasks.

How to make two cups of coffee?

  1. Fill the kettle
  2. Boil water

  3. Coffee in cup

  4. Pour on water
  5. Add sugar
  6. Add milk

  7. Do 3 to 6 again

jbochi
While this is useful for describing the discipline of programming, it doesn't really give an idea of 'what program code "looks like".' jalf's friend asked if he just looks at lists of numbers while programming: she wants to visualise what are the entities that jalf works with. So I think he'd want to show e.g. functions, classes and variables: the kettles and cups of *programming*, not of coffee-making.
itowlson
Code is but step by step instructions, I think this is perfect example what programming "looks like" without displaying the rather frightening arsenal of terminologies and languages. And for all we know, someday programming will be like this.
aredkid
I like this example, throw in a 'if kettle is empty' goto 1. Then you have a programming structure.
Qwark
I was just going to suggest this, when I saw this post. I always tell curious people that coding is like writing food recipes. It's a decent analogy for what an algorithm is.
Mads Elvheim
I took the example from here (http://www.tutorials4u.com/c/loopsdecisions.htm) and made some small modifications. On the page there are more complex/interesting examples.
jbochi
i think that the example is really bad, but maybe its becouse i have never written coffee app. you do not program outside of work, right?
01
I tried running this program and I got a cup of coffee and a puddle. Bug!
Stephen C
+1  A: 

My usual choice is to retrieve a set of customer records from a database. Using C# and LINQ in Visual Studio, it takes maybe 10 minutes at most to build a web page and dump out the "Northwind" database customers into a grid. The nice thing is that a "list of customers" is something that almost anybody can understand.

Cylon Cat
+29  A: 

Why not consider a language that doesn't exist (or does, if you so believe) and use Pseudo Code? I think, depending upon what you want to achieve - I'd consider the example of task familiar to the person, but carved up into a pseudo code example.

I generally find the idea of "cooking" or "recipes" to be a great fit when explaining things to non-programmers.

I ask the person to imagine they had a recipe that was fairly complex - e.g. a curry & rice dish. I then suggest that they should try and write it down for someone who has absolutely no idea what they are doing, so that they can cook it.

There is a very definite few stages involved:

  • Gather the ingredients and tools for the job.
  • Prepare the ingredients. This is complex. e.g.
    • get 3 Small Red Peppers.
    • for each red pepper you have, chop it into chunks about 1cm square.
    • place the red pepper chunks into a bowl for later.
  • Seperately to this, call the prepare rice function and have this working asynchronously in the background while you continue on with the cooking.

I'm sure you can see where this is going... ;)

There are a lot of similarities with Cooking and Programming (as there are with many things, but more people have an understanding of cooking than of building a house). There stages / similarities (as I see it) are:

  • Gathering: (declaration of what is required to achieve the goal and getting them together).
  • Preperation: Chopping the ingredients or readying the data connection objects etc for first use.
  • Asynchronous: The ability to have one thing going while another thing going.
  • Functions: The rice making, the chicken cooking and the curry cooking all require separate processes and only at the end can you have the makeCurry(chickenMeat, rice) function.
  • Testing: Ensure that as you are going along, you aren't missing any bits and that everything is going smoothly - e.g. ensuring chicken is cooked before you move to the next stage.
  • Garbage: Once you've done, you must ensure that you tidy up. ;)
  • Principals of Best Practice: There are efficient ways of doing things that like cooking, beginning programmers have to learn in addition to the code - sometimes it can be hard to get your head around. e.g. D.R.Y, how to chop efficiently with a knife & don't eat raw chicken ;)

Basically, I think for teaching programming as a general topic - I wouldn't necessarily teach from a language unless you had a compelling reason to do so. Instead, teach initially from the abstract until they understand at least the fundamentals of how things might fall together. Then they may find it easier when sat in front of a monitor and keyboard.

I think there may not be one "right answer" for this one. But I think maybe a few really good ideas you could maybe take bits from all of.

Amadiere
Great answer. At last somebody focuses on the principles of programming rather than on geeky stuff that is nearly meaningless to non-programmers.
CesarGon
In many cases I'd agree, but in this case, I think it's the geeky stuff that's most relevant. Her question was not "how do you write a program", but simply "what does it look like? Are you just staring at a screen full of numbers?" I think the best answer is to show some actual code, show that there's actual meaning and structure hidden in it. What it actually *means* is less relevant. It doesn't matter if she can read the code, but if she can recognize that it's made up of a few english words (if, while), and small mathematical expressions (x = y+z) gives a basic frame of reference.
jalf
I can't really agree with that at all. That kind of comment comes about from a fundamental misunderstanding about how learning works. All these abstract concepts might have made programming easier to understand *for you*, but only because you already had the benefit of hundreds of concrete examples, and probably some experience actually programming. What someone completely new craves is those concrete examples of actually really programming with real code, otherwise there's nothing to relate these abstract concepts to, no personal experience that it's relevant to. Also, it's way too much.
Breton
Sorry, my comment was directed at CesarGon and Amadiere, not jalf
Breton
Amadiere
+1 for mentioning pseudo-code.
luiscubal
+20  A: 

To answer your question directly - what programming “looks like”, I'd show them a print out of a large application. Toy apps or cute things like qsort in haskell really give the wrong idea.

anon
Yeah, that might actually be the best approach. Just let her take a look at some of the actual code I'm currently working with
jalf
Of course, if she starts critiquing your indentation style or your poor use of STL algorithms, you may come to regret taking this approach.
anon
Haha, if she does that, she can take over debugging of the race condition I've been chasing for the last week... That'll teach her! ;)
jalf
+1 to Neil and jalf. Too funny.
Jason D
But don't people usually ask these questions *after* seeing a screenfull of `make` output and claiming they couldn't understand even that for the life of theirs?
Michael Krelin - hacker
In this case she just asked because I said I had spent the last 2 weeks trying to fix a bug in my code. But yes, you're right, that's probably what usually prompts that kind of question ;)
jalf
This is what I ended up doing, pretty much. Actually, I finally managed to fix th ebug I'd been hunting when she first asked, and simply showed her the erroneous line, and what I'd replaced it with. Anyway, accepting this :)
jalf
+4  A: 

Definitively something either with graphics, or windows, in a higher level language.

Why? A non-programmer is usually a non-matematician too, that's why he won't get the beauty of sorting. However showing something drawn on a screen ("look, a window!", "look, so little typing and we have a 3D box rotating!") can work wonders ;).

Kornel Kisielewicz
"look, so little typing and we have a 3D box rotating!" -- And what magical language are you working in that can produces a 3D, rotating box in "so little typing?" Most of my "I can haz box!" code is at least around 100 LOC. (Create the window, instantiate the 3D lib, setup the matrices, create the verticies/indices, push them to graphics memory, update rotations, bind and render verticies, let's not even TALK about textures or lighting...)
Toji
XNA can really cut down on the total lines of code.
ChaosPandion
+3  A: 

It's really hard to understand what programming is like just from a source code example, because it is so abstract.

There is nothing wrong with starting on hello world, as long as you can show what the computer actually does with it. You can then introduce one construct at a time. That's what programming is like- Making incremental changes, and seeing the results.

So you have a hello world program. Now change it to

string Name = getLine();
printf("Hello, %s", name);

then the if construct

printf("Do you like cake?");
string answer = getLine();
if(answer==="yes") {
    printf("Yeay! I like cake too!");
}
if(answer==="no") {
    printf("Filthy cake hating pig!");
}

then demonstrate that the last program fails when it recieves an answer other than either "yes" or "no", and how you would go about fixing it....

and so on. I don't think you need to go into deep concepts like recursion, or even functions really.

It doesn't really matter what programming you use for this, as long as you're able to show, on a computer, the result of these different programs. (though these psuedocode examples are probably pretty close to being valid python)

Breton
I liked the example in this answer, +1!
Carl Smotricz
A: 

Totally depends on the level of her interest (or your level of interest in her). Most people ask that question as idle conversation, and don't really want to know.

Programming is more than algorithms (like "How to make a cup of coffee), it's also fundamentally rooted in mathematics. Most people will be quickly tripped up by the subtle use of mathematical terms (what's a "function"?).

In order to really teach programming, it may help to think back to your own first programming experiences, your first programming teacher, your first programming language. How did you learn? when you were learning, what skills did you already have fresh in your mind (i.e., calculus)? What motivated you to want to understand what a variable is or why there are three different kinds of loops?

Language-wise: Use something like python. Really high level, non-curly-bracket probably better.

Seth
+10  A: 

Maybe everyone is concentrating too much on the code rather than tools. Possibly it's best to show her a project in an IDE, and how it includes various source files and maybe some diagrammatic things like a database schema or a visual user interface designer too. Visual Studio, Eclipse or Xcode are quite far away from most people's mental image of rapidly scrolling glowing green symbols on a black background.

Rich
Yeah, this is pretty much what I thought, too. Just show her around in your working environment for a few moments, like I click here to run, here to open files, here I edit the text, etc.
Fabian Steeg
+7  A: 

Code something that has any comprehensible value to a non-programmer. If I'd demonstrate Quicksort to my mother, it wouldn't be of any use.

Ask the person about his interests. If he/she's into stock exchange for example, hack together a script that reads some stock statistics from a appropriate web page and compiles them into an excel sheet (use csv, to avoid heavy brain-damage ^^) or maybe into a nice graph.

If the person uses Twitter, code something that counts the followers of his followers or something like that.

These tasks are simple enough to be done in a very short time and they already utilize a lot of the basic tools that we programmers use, like loops, libraries (for all the http stuff involved), maybe recursion.

After you're finished or while you're coding (even better), you can explain how your program does its magic.

Just keep it simple and talk in human language. If you show them megabytes of code and talk about things like prototypal inheritance, you just intimidate them and they will lose interest immediately.

Techpriester
+1 for keep it simple, yet relevant to the audience.
Jason D
I love the idea of involving Twitter. Perhaps do it using HTML and JS/jQuery: this lets you whip something up that they can see on their computer too. Hell, bung it on the Interwebs. "And now anyone can use this just by going to example.com/myawesomestuff. How cool is that?"
Samir Talwar
+6  A: 

There was a CLI graphics package called LOGO, and best known for Turtle Graphics, used to draw shapes on screen using commands like LT 90, RT 105 etc. See if you can find that, it would be a nice experience to try and draw something of medium complexity.

LOGO - Logic Oriented Graphic Oriented programming language.

REPEAT 360 [FD 1 RT 1] -- draws a circle, etc.

See more at logothings or Wikipedia which also has links to modern logo interpreters.

anijhaw
This must have been my first introduction to programming. It has enough fundamentals for people to understand what programming is about without boring them to death.
Robert Paulson
then your friend can ask a question on SO about how to move the turtle in logo...
Antony
+1 Antony. I would laugh my butt off if I saw a LOGO question here... speaking of which I've not done any LOGO in decades... it was a bit... well ... uninteresting for me... even at age 12...
Jason D
this was taught in my elementary school! can't say it had a thing to do with my interest now though. was a long time ago. you could do cool things with it though, i remember we pieced together some (relatively) impressive games.
Nona Urbiz
@Jason D: Perhaps you should check this one out then. http://stackoverflow.com/questions/1003841/how-do-i-move-the-turtle-in-logo
Samir Talwar
+5  A: 

I think you should download some big win32 application, written in AT&T assembly language, and show it to her in notepad, and tell her, "As you can see, it takes a superhuman like myself to program."

Carson Myers
Good as a joke only.
luiscubal
+1. Finally applying the maxim of "Your user is a 22-year old in a college dorm room. How will this software get him laid?" to Stack Overflow. You're a revolutionary, man.
Adrian Petrescu
chicks dig assembly programmers EVEN MORE than unix gurus.
Carson Myers
Chicks dig Unix gurus? Damn this curse of MS that pays my bills!
Jason D
LOL @ Carson Myers's comment... A bit like how I dig cleaning up a puddle of vomit EVEN MORE than cleaning up two puddles. :)
j_random_hacker
(Speaking as a frequent assembly programmer and Unix aficionado)
j_random_hacker
+5  A: 

I've found that the best approach to "teach someone what programming is without teaching them programming" is actually to just drop anything related to a specific programming language.

Instead (assuming they're actually interested), I would talk them through implementing a function in a program, like a simple bank loan application (most people have had to deal with loans at some stage, if they're above a certain age), and then poking holes in all the assumptions.

Like, what should happen if the user types in a negative loan amount? What if the user cannot afford the loan? How would the loan application know that? How would the loan application know which bank account to check and which payment history to check (ie. who is the user actually)? What if the user tries to type in his name in the loan amount field? What if the user tries to take the loan over 75 years? Should we limit the choices to a list of available lengths?

And then in the end: Programming is taking all of those rules, and writing them in a language that the computer understands, so that it follows those rules to the letter. At this point, if it is felt necessary, I would pull out some simple code so that the overall language can be looked at, and then perhaps written out one of the rules in that language.

Bonus points if you can get your friend to then react with: But what if we forgot something? Well, then we have bugs, and now you know why no software program is bugfree too :)

Lasse V. Karlsen
A: 

Alice which was developed at Carnegie Mellon.

Alice is an innovative 3D programming environment that makes it easy to create an animation for telling a story, playing an interactive game, or a video to share on the web. Alice is a teaching tool for introductory computing. It uses 3D graphics and a drag-and-drop interface to facilitate a more engaging, less frustrating first programming experience.

Robert Paulson
Interesting, and I've chosen to download it. . . However this might give the wrong impression of programming as it is today. . . "Real programming" is far less visually stimulating. . .
Jason D
A: 

Most programming languages syntax and even semantics are meant for MACHINES interpreter. This is mostly for facilitating design of the language itself NOT for the benefit of the programmer.

That's why I like Rebol, it's the only known language where you can write nearly in plain english or PSEUDO code that is ... EXECUTABLE like:

send "Hello World" [email protected]

or

write %temp.txt read %hello.txt
Rebol Tutorial
+8  A: 
Mark Harrison
So you're saying that all programmers are socially inept males. It saddens me to see people promoting this negative stereotype. I'll give you [1] as suggested reading and leave it at that.[1] http://www.sas.upenn.edu/~nathanen/files/cbi-gender.pdf
Steve Johnson
I am a computer programmer. I've known many who fit the stereotype depicted above... and many who don't. I still got a good chuckle out of it.
Jason D
Steve, lighten up, it's funny *because* it's recognized as a stereotype. The two images are separated by nearly half a century, but are essentially identical. I had thought everyone would recognize the Coulter/SpiffWorld Code Monkey, but I've added a link to the image. Check it out, it's great!
Mark Harrison
hehe, i agree, if programmers can't make fun of programmers, who can we make fun of? :)
melaos
+1 melaos, well said!
Mark Harrison
+1  A: 

Why not just show the timelapse video A Day in the Life of a Scrum Team?

Adrian
Oh god, kill me now! ;-)
Tall Jeff
Problem is that most programmers will identify with what's happening in that video, but anyone else will see a group of people getting in late, chatting a lot, taking a long lunch, goofing off, and only occasionally waving their hands in the direction of a computer. (I know that what we DO, but we don't want to give people the wrong impression now, do we?)
Toji
A: 

In pseudo-code:

function dealWithPerson(person){
    if(ILike(person)){
        getCookie().giveTo(person);
    }
    else{
        person.tell("You shall receive no cookies!");
    }
}

dealWithPerson(Person.fromName("Nick"));
dealWithPerson(Person.fromName("John"));

This demonstrates the concept of functions, object-orientation and strings, in a C-like syntax(when I say C-like syntax I refer to the weird characters).
It also shows how code can be reused. Note that although it is pseudo-code, I wouldn't be surprised if there was some language that accepted this syntax(perhaps JavaScript allows this?).

You could also adapt this example to have loops. Hope this helps show that person how a program looks like(since it is a realistic syntax and it is relatively easy to understand).

luiscubal
I would say this code is more akin to java than C. . . Unless Java is considered an offshoot of C...
Jason D
function is a JavaScript keyword, not a Java/C keyword. So I guess this is JavaScript-like syntax... But I agree that the object-oriented part of it makes it less C-ish. Not that a non-technical person would know.
luiscubal
A: 

I have been teaching programming for many years and found out that the number of ways you need to explain things is equal to the number of students you have. But one method that works most of the time is as follows:

  1. Present a flow chart that shown the flow of logic of a simple application
  2. Write the instructions in full human language (e.g. English)
  3. Abbreviate each instruction to the short-hand used in the programming language
  4. Choose a less cryptic language like Basic or Pascal for teaching purposes

All code is simply shorthand for natural language. Written in full English most programs seem trivial.

As for a good algorithm, that is another story. It is sad to see many Computer Science courses no longer teach algorithms or brush over it.

Square Rig Master
A: 

I would consider Greenfoot. Though it is intended for children to learn programming, the graphics would probably help the reader relate the code to "actions". Here is an article on Greenfoot by a colleague of mine.

Michael Easter
+1  A: 

A programmer writes instructions for the computer to perform.
Running the program results in the computer actually following those instructions.

An example is a cook will follow a recipe in order to bake a loaf of bread. (even if it's in their head)... that's programming. Unlike my wife, the computer follows the recipe exactly every time. My wife, does it in her head and it turns out different but delicious every time ;-)

If you want to go ahead and teach this in more detail then pseudo-code is easy to understand.

e.g.

IF today's date is the 1st of may then
  print to screen "Happy Birthday"
ELSE
  print to screen "It's not your birthday yet"

The beauty of psuedo code is nearly anyone can understand it and this is the point of it.

Matt H
A: 

I like to motivate intro programming with the "Locker Room Problem" (say, 100 locker rooms, initially closed. Person 2 enters and opens all that are even-numbered, person 3 enters and changes the status from open to closed and viceversa of all lockers whose numbers are divisible by 3, person 4 enters and those this for lockers whose numbers are multiples of 4, etc., until person 100 enters). Question is, which lockers remain closed? Of course, there is an elementary math solution to this (only perfect squares remain open), but it is a good exercise for intro programming, I think.

dsantos
I'm not trying to motivate an intro programmer though. I'm trying to give a non-programmer a mental image of what programming *is* and nothing else. ;)
jalf
A: 

I'd walk a person through one relatively simple function, with less than ten lines of code. Don't focus too much on the syntax; focus on what it is supposed to do, and the steps it takes to do it. Also touch a little on some of the tradeoffs made (speed vs. space, to check for errors or not to check, etc.).

Then explain that what you showed is 0.01% of the entire program. And explain that 90% of your time is not spent writing the stuff, but trying to read the stuff and figure out why it isn't working.

Kristopher Johnson
+10  A: 

A junior coder at work

It looks a bit like this.

Stephen C
+1 for the LOLs. (And because I've debugged that program before!)
Toji
A: 

My wife knows absolutely nothing about programming and computers. But she did understand when I explain that the computers are absolutely brainless and only follow instructions. You can define and control those instructions with a programming language. Basically you're telling a computer what to do using a programming language; it is the language a computer (in)directly understands.

It can be a long story, but a good demonstration example is a calculator such as calc.exe (or whatever calculator program your OS is using). Every programmer should be able to explain in easy-to-understand language what it is doing "under the hood" (telling the computer that it should listen and remember what buttons are pressed and what to do with those values). You could also consider to try to demonstrate that as well in your own language, which should at end also be fairly easy to understand. At least, it helped my wife (I assume ;) ).

BalusC
+1  A: 

Jalf,

What usually works best is showing something the person is already familiar with.

Selecting a file and printing is something very familiar to most people.

So, you can show a small piece of code that asks for a file and do something with it. It can be very short and still show how a program is built.

A piece of code like that will demonstrate: Overall structure Flow Use of variables and statements Use of API

Klinger
+1  A: 

alt text

{
   wait for 6/8;
   play F (5), sustain it for 1/4 and a half;
   play E flat (5), sustain it for 1/8;
   play D flat (5), sustain it for 1/8 and a half;
   play F (4), sustain it for 1/16;
   // ...
}

Perhaps a metaphor could be that of a composer writing a musical score. The job of a composer is the intellectual activity of creating music. With a score, the composer is telling the pianist what to play, and he does it by means of precise instructions (notes, pauses and so on). If the "instructions" are not precise enough, the pianist will play something different.

The job of a software developer is the intellectual activity of solving problems (problems that have to do with automated processing of data). With source code, the developer is telling the computer what to do, and he does it by means of precise instructions. If the instructions are not precise enough, the computer will do something different and will not solve the problem correctly.

Federico Ramponi
With music, the performer is explicitly expected to produce an artistic interpretation of the literal notes on the page, for which there are many possible expressions. Computers have no such notion. Hence, this comparison would be particularly bad to use with a musician.
Novelocrat
This comparison would probably ONLY make sense to a musician at that. How many people out there find reading music just as baffling as reading code?
Toji
@Novelocrat: of course I agree that interpretation is part of the story, still a computer can also add slight variations (not with artistic intent). For example, think at random(). Also, much contemporary electronic music is actually written by means of "programs" (in graphical programming languages, with block diagrams etc.)
Federico Ramponi
+4  A: 

To give my wife an idea of what I do to bring in a paycheck (It's real work! I promise! we don't just browse the web all day!) I sat down with her one evening with Python and showed her a couple of the basic concepts: calling a function (print), assigning and reading a variable, and how an if statement works. Since she's a teacher, I likened the concept of conditionals to working with preschoolers :)

IF you hit Jonny THEN you're in time out OTHERWISE you can have a snack.

After reviewing a couple of the very high level concepts, I then showed her the code to a simple number guessing game and let her play it while looking though the code.

# Guessing Game
import random

print("Guess a number between 1 and 100: ")

target = random.randint(1, 100)
guess = 0
guess_count = 1

while guess != target:
    guess_count += 1
    guess = int(input())

    if guess == target:
        print("Correct!")
    if guess < target:
        print("Higher...")
    if guess > target:
        print("Lower...")

print("Congratulations! You guessed the number in " + str(guess_count) + " guesses!")

Aside from the somewhat abstract concept of "import", this is a very straightforward example that is easy to follow and "connect" to what's happening on the screen, not to mention it actually does something interesting and interactive. I think my wife walked away from the experience a little less mystified by the whole concept without really needing to know much in the way of code.

I think the key is being able to have someone see the code AND it's end result side by side.

Toji
+2  A: 

What does it look like when you work?

It looks like typing.

Seriously though, programming is kind of like if Legos were text, and to build a big Lego house, you had to type a lot of text in, just right, hooking up the right pegs with the right holes. So that is how I generally describe it.

Eugene Efremov
It's like baking a cake, except the ingredients are words, and in order to ice it, you had to type a lot of words.
Breton
It's like playing hockey, except the hockey stick is a keyboard, the puck is words, and the goals are correct syntax.
Breton
It's like being frightened of a clown, except that the words you say to make the clown go away are words, and the clown's insistance on trying to be amusing is like your daily frustration with your company's management
Breton
It's like a burrito, except the beans are words, the salsa is preparser directives, and the tortilla is the compiler.
Breton
It's like attending the theater, except that the script is made of words, and you don't fall asleep 5 minutes before intermission.
Breton
+1 for "it looks like typing" ... cause it does, really.
ldigas
+3  A: 

Robotics is great for explaining programming, I think, because even simple, contrived examples are practical. The robotics equivalent of Hello World or printing a list of numbers might be having the robot move in a line or spin in a circle. It's easy for a non-programmer to understand that for a robot to do ANYTHING useful it must first move and position itself. This lets you explain simple program structure and flow control.

You want the robot to move forward, but only while there is nothing blocking its path. Then you want it to turn and move again. That's a simple routine using basic flow control, and the functions that you're calling are pretty easy to understand (if your platform has decent abstractions anyway).

Graphics might also work. Anything that has immediate results. jQuery even, because everyone is familiar with rotating pictures and web animations. Even contrived examples like pushing elements around in the DOM has an easy to see effect, and most people will understand what and why the statements in the program do.

Things like Robocode and LOGO are probably really good for this.

Matt Olenik
A: 

Quoting Steven C. McConnell, from his great book Code Complete, in Ch.2 he talks about Software Metaphors

A confusing abundance of metaphors has grown up around software development.

  • Fred Brooks says that writing software is like farming, hunting werewolves, or drowning with dinosaurs in a tar pit (1995).
  • David Gries says it’s a science (1981).
  • Donald Knuth says it’s an art (1998).
  • Watts Humphrey says it’s a process (1989).
  • P.J. Plauger and Kent Beck say it’s like driving a car (Plauger 1993, Beck 2000).
  • Alistair Cockburn says it’s a game (2001).
  • Eric Raymond says it’s like a bazaar (2000).
  • Paul Heckel says it’s like filming Snow White and the Seven Dwarfs (1994).
medopal
A: 

Want to show her what programming looks like? Just pop a terminal and

find /
gb
A: 

I'd say either do some standard algorithm in psuedocode (pretty much any n^2 sorting algorithm should be fine. I like selection sort.) or point them to http://99-bottles-of-beer.net/

then again, I just like pointing people to 99-bottles-of-beer.net B-)

Brian Postow