Extremeely basic programming question.

I disagree with the C++ trope that guns don’t kill people, people kill people. C has some tragic design mistakes and C++ amplified them. Some things often considered mistakes are features but not all of them.

Try this quiz:
http://blog.regehr.org/archives/721

And if you’ve never read it, A guide to undefined behavior in C and C++ is quite good.

And if you use C++ and haven’t read the FQA then there is no time like the present.

You really have no idea what I’m talking about.

You would probably need to do some additional manipulation in that code on a S/370 due to how it stores floating point (base 16 instead of base 2).

I’ve always hated crap like that (took me a couple minutes to mentally run that code and make sure it did what it intuitively looked like it did).

I even find myself not using new language features because they aren’t available in other languages that I am switching back and forth between, so I end up with a lowest common denominator set of instructions that I can create error free code with minimal brain power, and so I can read it quickly and clearly later.

Kind of RISC programming.

Um, hi.

Could I possibly go back to the original question? I still don’t get it.

If “Integer A” is 10, and “Integer B” is 20, how can A equal B? Doesn’t that mean 10 equals 20? Wouldn’t that blow up the computer, or tear a hole in the universe or something?

I also don’t understand the point of the article that the OP links to. It seems to be saying that you can only learn programming if you already understand programming…?

Sorry to be an idiot here. The only programming I know, is how to make text bold and italic using HTML ^_^;

The computer A=B does not mean the same as the mathematics A=B.

In a computer, A=B means “take the value of B and assign it to A”. It’s an assignment operator, not an equality statement.

So, Bear_Nenno … when do you intend to “fully participate”?

You know, I was thinking about this and I just realized that both COBOL and RPG would handle this in a more straightforward fashion and in 2 fewer lines of code (no need to do the pointer switching) :slight_smile:

They both allow the redefinition of a variable as a different type and they support floating point as well as binary. You wouldn’t need to do the “// evil floating point bit level hacking”, you wold do floating point operations on VAR_FLOAT (for example) and binary ops on VAR_BIN that both pointed to the same memory.

Feel free to explain yourself, then.

An interface isn’t just the set of operations that you can perform on an object. It also includes the set of constraints that must hold before and after.

Every grade-schooler knows the “interface” to the numbers. You started to list the operations yourself: addition, subtraction, multiplication, and so on. Not only this, but they know which constraints hold:
A+B == B+A
AB/B == A for B != 0
sqrt(A
A) == abs(A)
…and so on.

But even in a language which doesn’t allow direct bit access, any physical computer will violate these constraints, and indirectly expose the internal representation.

Yes, a programmer with a “first course in numerical analysis” will know that the constraints are only approximations, and modify her code appropriately. But that doesn’t mean the junior programmer doesn’t discover them almost immediately.

Truly abstract interfaces only exist on paper. Real interfaces leak data no matter what language they’re written in. Security researchers have a field day with this stuff.

The S/370 ain’t IEEE-754 compliant :). But yeah, the base-16-ness is going to pose problems. The exponent part probably just needs a new constant, but the mantissa shift isn’t going to do the right thing without some munging.

engineer_comp_geek has it. A = B is shorthand for “take the current value of B, and replace A’s current value with the new value”.

The point of the article is that programming requires not only training, but also a certain talent that only certain people have. It may be that the lack of talent can be overcome, but it requires time. It’s a bit like saying that people who can’t carry a tune are going to have a harder time learning a musical instrument.

Or, “Assign to the variable A the current value of variable B.”

I tend to agree. My job is teaching college math (algebra, calculus, statistics, etc.). I once taught a course in computer science (BASIC, back in the day of MS-DOS and QBASIC), and I found it difficult to teach (much more so than teaching math), because I didn’t/don’t know how to teach someone else to think like a programmer. It’s a way of thinking that’s always come natural to me, but how do I teach other people to think that way?

(Underline and bold added)

Okay, Strangelove, now you gone done done it! You done brung up a whole new concept into this already-esoteric thread (NOW do you see what you’ve done, Sicks Ate? :eek:) Interfaces that “leak”, indeed! What, they’re gonna pee on us now? :smack:

Yes, that’s right. Let down your guard, and interfaces (that’s an abstract concept there) tend to piss on you. For anyone who’s new to this idea, here’s an article on the subject: “The Law of Leaky Abstractions” by Joel Spolsky.

TL;DR summary: All non-trivial abstractions leak. With discussion of what that means.

Essentially, abstractions (meaning, interfaces) are designed to hide the internal workings and representations of things, and by “leaking” is meant that they never fully truly succeed at this, which generally has implications, often undesirable.

Recommended reading: This, and a whole bunch of other essays on the above-linked Joel Spolsky site.

This may be true, but I do not believe the test is effective at identifying this talent.

A more likely hypothesis is that the test is effective at identifying people who have had some previous exposure to computer programming. (This in itself probably being predictive of success, for various reasons.)

I know that they use a “get-out” clause of saying that any consistent rule-based interpretation of the test is treated as correct. However it should be clear that it is much easier for someone familiar with the conventions to interpret them (at all, let alone consistently or correctly).

I believe the designers of the test (and most of the commenters here) have failed to put themselves in the mind of a person who has never seen a computer program. They wonder, “how might I interpret this 3-line program if I were unfamiliar with the conventions used?”

This is not the correct question. A more appropriate question is “what does someone who has never before encountered a computer program see, when they see these three lines of text?”

A programmer sees a series of instructions, to be executed in a certain order. A naive reader sees what appears to be a series of statements about the world.

A programmer sees the first three letters “int” and knows they have a meaning related to how data is stored as a variable. The naive reader sees an unfamiliar word and doesn’t know what it means. The programmer may say “it doesn’t matter in this instance, just ignore it”, but the naive reader has no reason to think it can be ignored.

Finally, the programmer sees an assignment, the naive reader sees an equation, and at this point is completely mystified.

Is it reasonable to expect someone in that situation to form a consistent rule-based interpretation? Is it reasonable to conclude that if he/she does not, he/she has no aptitude for programming?
By analogy, if I prepared a multiple choice test with questions like:
重いの反対は
a) 深い
b) 軽い
c) 赤い
d) 小さい

and someone did poorly, could I conclude that they had no aptitude for learning Japanese?

Would it make a difference if I said the answers didn’t have to be right, as long as they represent a consistent understanding?

Programming languages almost always assign to the single variable on the left.

That’s not a bug, it’s a feature. :smiley:

If this were true, bugs would not be as prolific as they are.

And that’s a really good question, don’t you think? Because not all languages act this way.


C:
a = b+c;

scheme:
(= a (+ b c))

These seem like apparently equivalent constructs, within the syntax, but in fact the second is not equivalent to the first because the second checks for equality; destructive assignment looks very different. A modern programmer should be prepared to use different languages and different languages can and do have different syntax. Building a consistent mental model is the primary challenge of programming. It starts with the syntax, but carries through to the abstraction the programmer creates, and the seas of the language can run quite high indeed.

Both of these really are aspects real programming languages really use.

A C programmer sees assignment. A lot of languages do not use ‘=’ for assignment, and for some of us we consider it to be a really bad idea to use this as assignment. (Some of us don’t even like destructive operations if we can reasonably avoid them.)

If this ability cannot be taught, or at this time we don’t know how to teach it, then it seems like a fairly reasonable conclusion.

This is a good point.

I was thinking back to when I first started programming, and trying to determine why it came so naturally to me whereas some other people I’ve encountered just never quite seem to get it even after working at it.

For me it was almost immediately/intuitively understood that the computer was a machine that I could control by giving it sequences of instructions - and my brain could simulate in an abstract sense what the computer was doing/what I wanted it do. Every step of learning just filled in the details.

On the other hand, when I’ve worked with programmers that were not very good, it seemed that their brain was processing the information very differently from my own. They weren’t “seeing” the same abstraction/model inside their head.

My gut feel says that test is not the best we can do because it doesn’t seem like it gets at this ability to mentally model the computer processes. I’m no researcher and they could certainly be right that it’s a great test, but it seems like a better test would be one that describes a very simple “language” and then has problems to be solved, for example:

Background:

  1. You manage a rock quarry (LOL)
  2. There are 5 trucks that you control (truck #1, truck #2, etc)
  3. There are 3 sizes of rocks, small, medium, large
  4. There are 10 locations to store rocks (location #1, loc #2, etc.)
  5. A truck can carry 1 large rock, or 2 medium rocks or 4 small rocks

Instructions you can give the trucks:



Simple commands:
Drive to a location #
     example: 
           Truck#1, drive to Location#2

Get a rock 
      examples: 
           Truck #1, get a small rock (from location truck is sitting at)
           Truck #3, get a medium rock

Drop off a rock
     examples:
           Truck #2, drop off a large rock
Advanced commands:
Do these same instructions X times
    example:
          Do these instructions 5 times
                 Truck #1, drive to location #1
                 Truck #1, get a small rock
                 Truck #1, drive to location #9
                 Truck #1, drop off a small rock

Drive to next location #
    explanation: 
        if truck is at location #1, this instruction sends it to location #2
        if truck is at location #10, this instruction sends it back to location #1

    example:
          Truck #1, drive to next location


I can think of lots of questions, from simple to hard that, I think, would tell whether the person has some natural ability, but I could be wrong.

This is a tangent, but as I was reading up on some related articles to this thread, I stumbled upon this comment:

"Very very common, alas. I once interviewed a candidate for a VBA job (yes, you can stop booing for the peanut gallery) whom I asked to swap two variable contents without using a temp variable. It’s the standard a=a+b, b=a-b, a=a-b problem. His answer? Well, I can’t do it in VBA, but if you let me use Excel I can put the values in two cells and swap the cells’ contents using a third cell.

We hired the guy who said, well, “if they’re integers, then I’d do it by a=a|b, b=a^b, a=a^b. But I don’t know how to do it if they’re strings.” "
Basically this guy is actively trying to hire only the people that know how to write crappy code.

And incorrect code, in the case of that last guy (the | should be a ^ as well).

Personally, if I got that interview question, I’d say “Why? Memory’s dirt cheap nowadays; surely I can spare a temp variable to make my code more comprehensible.”. And that’s even with knowing how to do it without.