# Extremeely basic programming question.

**URL:** <https://boards.straightdope.com/t/extremeely-basic-programming-question/624300>\
**Category:** Factual Questions\
**Created:** [June 6, 2012, 6:48pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300 "2012-06-06T18:48:37Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![KneadToKnow](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kneadtoknow/32/3999_2.png) [@KneadToKnow](https://boards.straightdope.com/u/KneadToKnow)\
**Post date:** [June 6, 2012, 8:46pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/21 "2012-06-06T20:46:50Z")

</div>

> [@ZipperJJ](#):
>
> Now my name is his name.
> 
> What is my name?

You can’t fool me, John Jacob Jingleheimer-Schmidt.

---

<div class="post-metadata">

**Author:** ![Sicks\_Ate](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@Sicks\_Ate](https://boards.straightdope.com/u/Sicks_Ate)\
**Post date:** [June 6, 2012, 8:52pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/22 "2012-06-06T20:52:03Z")

</div>

> [@lazybratsche](#):
>
> As it happens, I just read through the same links…
> 
> That test is not looking for a “correct” answer. The test is looking for **consistent** answers, from a bunch of similar problems. If you always use the assign-to-left rule, that counts as consistent. If you instead guess that the rule means something else, like assign-to-right as **Chronos** mentions, and answer all of the questions accordingly, you’re still being consistent, and the authors of the test think that you could easily learn the correct rule for any particular language.
> 
> I think the idea is that the ability to consistently apply a simple rule is required for programming. If you can’t figure that out, you won’t even be able to figure out why your program doesn’t behave like you expect.
> 
> Now, my WAG is that there’s something to that idea, but this test isn’t perfect. A lot of people won’t be able to get past “10 = 20”, as it’s completely counter to every prior use of the “=” sign. Some of the people branded “hopeless” by the test would probably figure things out with different syntax, or a simple explanation of assignment.
> 
> As a total aside, I’ve been teaching myself R, and I really appreciate the \<= assignment operator. Just follow the fucking arrow…

You’re right, that slipped my mind between reading the article and composing the OP:

> [@](#):
>
> •44% of students formed a consistent mental model of how assignment works (even if incorrect!)

As you state, that’s actually what they were looking for…the ability to hold to a consistent set of rules.

---

<div class="post-metadata">

**Author:** ![Senegoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senegoid/32/6606_2.png) [@Senegoid](https://boards.straightdope.com/u/Senegoid)\
**Post date:** [June 6, 2012, 8:53pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/23 "2012-06-06T20:53:45Z")

</div>

Here is a link that I promised a few posts above.

[http://www.textfiles.com/100/famous.bug](http://www.textfiles.com/100/famous.bug)

This is the classic famous “Famous Bugs” document. It is a plain-text file from an earlier era (I first saw it in the mid-1980’s), consisting of a loosely collected compendium of disastrous programming bug reports. And yes, it includes some mentions of bugs that killed people, for example by fouling up high-tech medical equipment. There is one story of a space probe that was lost because somebody tried to send it a software update that caused the directional antenna to cease pointing back at Earth, thus losing all communication with it forever. It’s a kinda fun read.

---

<div class="post-metadata">

**Author:** ![Sanity\_Challenged](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Sanity\_Challenged](https://boards.straightdope.com/u/Sanity_Challenged)\
**Post date:** [June 6, 2012, 9:07pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/24 "2012-06-06T21:07:35Z")

</div>

> [@TriPolar](#):
>
> I can see how someone with no programming experience would have no idea what’s going on. But it doesn’t address one’s ability to program. If I were presented a sentence written in Chinese I would have no idea what it meant, but that doesn’t mean I couldn’t learn to read Chinese. The real test would be to provide a set of clear instructions for interpreting the code, and see if someone can follow the directions to understand the result.

Actually if you read the whole article (and its an interesting one, especially if you are ever in a position to educate or hire potential programmers), the point is to NOT give the test-taker any instructions for interpreting the code. Give him a group of very similar problems, and see if the results are consistent. Incorrect is OK, as long as the answers are consistently incorrect. If the test-taker is able to construct a consistent mental model of how assignment works (even if the model is wrong), that person has a much higher chance of successfully learning to program than someone who can’t.

---

<div class="post-metadata">

**Author:** ![Senegoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senegoid/32/6606_2.png) [@Senegoid](https://boards.straightdope.com/u/Senegoid)\
**Post date:** [June 6, 2012, 9:09pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/25 "2012-06-06T21:09:16Z")

</div>

> [@Napier](#):
>
> a = b could also be interpreted as the claim that a and b are already equal. It would evaluate to 1 if that were true and 0 if it weren’t. For example **5 + (a = b)** could be 5 or 6, depending.

(Bolding added)

This is an example of the discussion I wrote above, why there was a need for two separate symbols: One for assignment, and one to test equality. In the primitive FORTRAN days, the language didn’t permit such things (in particular, multiple assignments on one line), and a statement like:

A = B = C

was clear: It meant compute (B = C) (that is, compare B to C and produce a true/false result), and store this result into A (which is presumably a Boolean variable). With the advent of multiple assignment, as in Algol, this became ambiguous.

As for the \<= symbol as assignment operator, mentioned by **lazybratsche** a few posts above: This idea has been kicking around for a while. The actual symbol \<= could be a problem, as it also means “is less than or equal” in most languages. The above example  
A = B = C  
might be written: A \<= B \<= C and what would THAT mean?

As far back as the early Algol days in the late 1960’s, the symbol ← (arrow pointing to the left) was proposed as the assignment operator. Only problem was, computers in those ancient days typically only had some 48 to 63 characters in their entire character set, and ← wasn’t one of them. This is the same reason we use ⁕ (asterisk) for multiplication and not × (multiply-cross symbol) instead, even unto this very day.

Boolean (logical) results were represented in various ways in various computer systems. The idea that they should have standardized mappings to integers (0=false, 1=true), and that these values should be actually synonymous and interchangeable with integers, was considered by some (myself included) to be an abomination. C and successive C-like languages have perpetrated and continue to perpetrate this, whereas other stricter languages (Java in particular these days) have rejected that and maintain a wall of separation between Boolean and integer values.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [June 6, 2012, 9:19pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/26 "2012-06-06T21:19:19Z")

</div>

> [@](#):
>
> Actually if you read the whole article (and its an interesting one, especially if you are ever in a position to educate or hire potential programmers), the point is to NOT give the test-taker any instructions for interpreting the code. Give him a group of very similar problems, and see if the results are consistent. Incorrect is OK, as long as the answers are consistently incorrect. If the test-taker is able to construct a consistent mental model of how assignment works (even if the model is wrong), that person has a much higher chance of successfully learning to program than someone who can’t.

The catch there is that a student might construct a perfectly sensible and consistent internal model that is nonetheless completely unlike any model the test-writers ever anticipated, and thus look to them like an inconsistent model (I’ve seen similar things happen, myself). This can be cleared up by talking directly with the student, but it takes a lot of time.

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [June 6, 2012, 9:19pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/27 "2012-06-06T21:19:22Z")

</div>

> [@Sanity\_Challenged](#):
>
> Actually if you read the whole article (and its an interesting one, especially if you are ever in a position to educate or hire potential programmers), the point is to NOT give the test-taker any instructions for interpreting the code. Give him a group of very similar problems, and see if the results are consistent. Incorrect is OK, as long as the answers are consistently incorrect. If the test-taker is able to construct a consistent mental model of how assignment works (even if the model is wrong), that person has a much higher chance of successfully learning to program than someone who can’t.

I did not have time to read the whole article, but I will find time to do that. What you’re saying makes sense, but may be a hit or miss approach. It would certainly uncover those who make excellent programmers. But I’ve found the most basic problem that determines programming ability is following a set of instructions in a step by step manner, just as a computer does. Some people aren’t able to set aside a intuitive feel they get looking at code. But beyond that, programming involves some higher level concepts that go beyond the step by step approach. I recall from glancing at the article that recursion and concurrency were mentioned, and those do require higher level conceptual models.

---

<div class="post-metadata">

**Author:** ![Senegoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senegoid/32/6606_2.png) [@Senegoid](https://boards.straightdope.com/u/Senegoid)\
**Post date:** [June 6, 2012, 9:26pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/28 "2012-06-06T21:26:13Z")

</div>

> [@TriPolar](#):
>
> I recall from glancing at the article that recursion and concurrency were mentioned, and those do require higher level conceptual models.

To understand recursion, you must first understand recursion.

---

<div class="post-metadata">

**Author:** ![Thudlow\_Boink](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/thudlow_boink/32/320_2.png) [@Thudlow\_Boink](https://boards.straightdope.com/u/Thudlow_Boink)\
**Post date:** [June 6, 2012, 9:26pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/29 "2012-06-06T21:26:34Z")

</div>

> [@Napier](#):
>
> a = b could also be interpreted as the claim that a and b are already equal. It would evaluate to 1 if that were true and 0 if it weren’t. For example 5 + (a = b) could be 5 or 6, depending.

This is the sort of thing that depends on which computer language is being used. Many (but not all) computer languages distinguish between an assignment operator (“assign to a the value of b”) and a comparison operator (“return TRUE if a and b are equal”).

In Pascal, which beginning computer science students learned back in the 1980s, “a := b” means the former and “a = b” means the latter.  
In C and its descendents, “a = b” means the former and “a == b” means the latter.  
In BASIC, “a = b” could mean either depending on the context, though the former would be short for “LET a = b.”

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [June 6, 2012, 9:30pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/30 "2012-06-06T21:30:39Z")

</div>

> [@Senegoid](#):
>
> To understand recursion, you must first understand recursion.

To understand concurrency, you must first understand both recursion and concurrency.

---

<div class="post-metadata">

**Author:** ![Keeve](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Keeve](https://boards.straightdope.com/u/Keeve)\
**Post date:** [June 6, 2012, 10:26pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/31 "2012-06-06T22:26:14Z")

</div>

> [@Fuzzy\_Dunlop](#):
>
> int is a data type used when declaring a variable in a strongly typed programming language like C or C++.

Got it. Thanks. (Wow, has a lot been posted in the time since I left work!)

---

<div class="post-metadata">

**Author:** ![Xema](https://avatars.discourse-cdn.com/v4/letter/x/9de053/32.png) [@Xema](https://boards.straightdope.com/u/Xema)\
**Post date:** [June 6, 2012, 10:42pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/32 "2012-06-06T22:42:49Z")

</div>

> [@Senegoid](#):
>
> Many modern languages let you declare a variable and assign an initial value to it on one line, thus:  
> int i = 5 ;  
> but to assign any value to the variable at any later time, you just write:  
> i = whatever ;  
> without re-declaring it with the int keyword.

This concept becomes clear if you think about what the compiler does at each step:  
**int i = 5;** - causes the compiler to reserve memory sufficient to store an integer, then to set that memory to a value of 5  
**i = somethingNew;** - sets the memory previously reserved to the new value

A subsequent statement of the form **int i = 7;** would cause the compiler to react as follows:  
“You previously asked me to reserve space for an integer variable to be called **i**. If you want to assign a value to that, don’t include **int** , as this implies you wish me to reserve further memory. If you DO wish to reserve additional memory, don’t refer to it by a previously assigned name, as that leads to ambiguity and problems.”

---

<div class="post-metadata">

**Author:** ![BarryB](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@BarryB](https://boards.straightdope.com/u/BarryB)\
**Post date:** [June 6, 2012, 11:03pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/33 "2012-06-06T23:03:18Z")

</div>

> [@Chronos](#):
>
> The catch there is that a student might construct a perfectly sensible and consistent internal model that is nonetheless completely unlike any model the test-writers ever anticipated, and thus look to them like an inconsistent model (I’ve seen similar things happen, myself). This can be cleared up by talking directly with the student, but it takes a lot of time.

Here are the models they considered (lines in figure 1 being the answers)

1. Value moves from right to left (a := b; b := 0 – third line in ﬁgure 1).
2. Value copied from right to left (a:=b–fourth line of ﬁgure 1, and the ‘correct’ answer).
3. Value moves from left to right (b := a; a := 0 – eighth line of ﬁgure 1).
4. Value copied from left to right (b := a – ﬁfth line of ﬁgure 1, and a reversed version of  
the ‘correct’ answer).
5. Right-hand value added to left (a := a+b – second line of ﬁgure 1).
6. Right-hand value extracted and added to left (a := a+b; b := 0 – ﬁrst line of ﬁgure 1).
7. Left-hand value added to right (b := a+b – omitted in error).
8. Left-hand value extracted and added to right (b := a+b; a:=0 – omitted in error).
9. Nothing happens (sixth line of ﬁgure 1).
10. A test of equality: nothing happens (fourth and ﬁfth lines of ﬁgure 1).
11. Variables swap values (seventh line in ﬁgure 1).

What other models are there?

---

<div class="post-metadata">

**Author:** ![Senegoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senegoid/32/6606_2.png) [@Senegoid](https://boards.straightdope.com/u/Senegoid)\
**Post date:** [June 6, 2012, 11:28pm UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/34 "2012-06-06T23:28:20Z")

</div>

> [@Xema](#):
>
> This concept becomes clear if you think about what the compiler does at each step:  
> **int i = 5;** - causes the compiler to reserve memory sufficient to store an integer, then to set that memory to a value of 5  
> **i = somethingNew;** - sets the memory previously reserved to the new value

With much disgust, I must respectively disagree about this concept becoming clear. In the plethora of programming languages that allow a variable to be declared and initialized at the same time, there are many different conventions about exactly “what the compiler does at each step”.

In the process of compiling, link-editing, loading, beginning execution, and continuing execution, there are several different points in time that the variable could be set to its initial value, with subtle and not-so-subtle implications. It also depends on the memory class of the variable (static, auto, or whatever other new-fangled classes certain languages provide).

The statement: int i = 5 ;  
could produce subtly different results in different languages, and sometimes even in different implementations of the same language if the meaning is not specified precisely enough.

The pair of statements:  
int i ;  
i = 5 ;  
is much more UN-ambiguous, and it is quite clear what result this causes. I think modern languages typically _attempt_ to define the single statement: int i = 5 ; to produce the same result in all cases – but it gets confusing, I think.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [June 7, 2012, 12:37am UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/35 "2012-06-07T00:37:41Z")

</div>

> [@](#):
>
> Quoth **BarryB** :
> 
> What other models are there?

I’m the wrong person to ask, because I’ve had such extensive exposure to mainstream programming languages that I’m conditioned to think of case 2 as “natural”. But I’d bet you that if you presented that question to a thousand folks who didn’t have programming experience, one or two of them would manage to come up with something not on your list.

It should also be noted, by the way, that C’s practice of using different symbols for assignment and comparison also has its dangers and pitfalls, in that typos can lead to valid code that isn’t what the programmer intended. The code snippet

```auto

if (i = 1) {
...
}

```

is perfectly valid, and will compile without errors (though some compilers will probably give a warning for it). It’ll set the value of i to 1, and then it’ll check to see if the value it just assigned is nonzero, and then it’ll run the conditional code.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [June 7, 2012, 12:40am UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/36 "2012-06-07T00:40:51Z")

</div>

Actually, come to think of it, I _can_ think of another sensible way that

```auto

int a = 10;
int b = 20;
a = b;

```

could be interpreted. I could think, “Well, a and b are not equal, but the computer is trying to force them to be equal. I’ll have to adjust those values to make that happen, and it’s probably best to adjust them both by the same amount. So after I force equality, a and b will both be equal to 15.”.

---

<div class="post-metadata">

**Author:** ![tellyworth](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@tellyworth](https://boards.straightdope.com/u/tellyworth)\
**Post date:** [June 7, 2012, 1:13am UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/37 "2012-06-07T01:13:58Z")

</div>

[This article](http://andy.wordpress.com/2012/05/30/programming-is-not-algebra/) might be of some help.

---

<div class="post-metadata">

**Author:** ![Xema](https://avatars.discourse-cdn.com/v4/letter/x/9de053/32.png) [@Xema](https://boards.straightdope.com/u/Xema)\
**Post date:** [June 7, 2012, 1:45am UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/38 "2012-06-07T01:45:38Z")

</div>

> [@Senegoid](#):
>
> there are many different conventions about exactly “what the compiler does at each step”.

Indeed, the details can vary. I was attempting to describe what is typically happening “behind the scenes”.

---

<div class="post-metadata">

**Author:** ![robert\_columbia](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@robert\_columbia](https://boards.straightdope.com/u/robert_columbia)\
**Post date:** [June 7, 2012, 1:49am UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/39 "2012-06-07T01:49:16Z")

</div>

> [@KneadToKnow](#):
>
> You can’t fool me, John Jacob Jingleheimer-Schmidt.

Hey, that’s my name too!

---

<div class="post-metadata">

**Author:** ![BarryB](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@BarryB](https://boards.straightdope.com/u/BarryB)\
**Post date:** [June 7, 2012, 1:49am UTC](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300/40 "2012-06-07T01:49:38Z")

</div>

> [@Chronos](#):
>
> Actually, come to think of it, I _can_ think of another sensible way that
> 
> ```auto
> 
> int a = 10;
> int b = 20;
> a = b;
> 
> ```
> 
> could be interpreted. I could think, “Well, a and b are not equal, but the computer is trying to force them to be equal. I’ll have to adjust those values to make that happen, and it’s probably best to adjust them both by the same amount. So after I force equality, a and b will both be equal to 15.”.

What if you then asked them the same question except with 30 instead of 10? If they were consistent, they’d answer 25. You could say that the test marker would label those answers as inconsistent if they did not understand, but I would assume that over a number of questions they would pick up that a person was averaging the two.

[Previous page](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300.md?page=1)

[Next page](https://boards.straightdope.com/t/extremeely-basic-programming-question/624300.md?page=3)
