# Basic programming question

**URL:** <https://boards.straightdope.com/t/basic-programming-question/569281>\
**Category:** Factual Questions\
**Created:** [January 28, 2011, 9:19am UTC](https://boards.straightdope.com/t/basic-programming-question/569281 "2011-01-28T09:19:00Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![qazwart](https://avatars.discourse-cdn.com/v4/letter/q/5fc32e/32.png) [@qazwart](https://boards.straightdope.com/u/qazwart)\
**Post date:** [February 1, 2011, 3:20am UTC](https://boards.straightdope.com/t/basic-programming-question/569281/21 "2011-02-01T03:20:49Z")

</div>

> [@Hennessy](#):
>
> He jumps right into how to navigate this robot using commands such as “move, turnLeft, pickUp” and he also uses conditions such as move only if no object blocks path. The programing program is called Eclipse.
> 
> What I want to understand is what created the commands and conditions, and how the robot can react to them.

Woof! I’ve been programming computers for over two decades, and I never heard of Karel as a programming language. It’s actually very much like “LOGO”. In LOGO, you moved a cursor around to draw pictures. Here’ you’re moving a robot around to do various tasks.

Even when you learn _real_ programming languages like Java, you’re not going to learn how a computer actually “understands” the commands and executes them. That takes some electronics knowledge of gates and logic. Something that can take years of study to do.

However, as you learn to program, you’ll get a bit more familiar on how small bits and pieces can be fitted together to make something bigger. You can then use this concept to dig deeper and deeper into software and architecture. If you’re really interested in getting down to the basics of computer architecture, you might want to take a course in the C programming language _ **AFTER** _ you’ve finished your Java course. Java will teach you how to think when you program. C will give you a better idea how architecture and software interact.

C is sort of a middle level programming language. In Java, the Java VM handles your memory for you. Need a bigger integer? Java will allocate more memory. Don’t need a piece of memory anymore? Java will throw it out for you. In C, you have to do all of that by your lonesome self. Put a number in too small a variable? Tough. Forgot to deallocate memory you no longer need? Not only might your program crash, but you might provide a security hole for a hacker to walk through,

And, once you get an understanding of C, and you still haven’t been scared away, you might want to play with some hardware. Take a look at [Arduino controllers](http://www.arduino.cc/), and see if there’s a [Hackerspace](http://hackerspaces.org/wiki/List_of_Hacker_Spaces) near you.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [February 1, 2011, 7:11pm UTC](https://boards.straightdope.com/t/basic-programming-question/569281/22 "2011-02-01T19:11:54Z")

</div>

> [@Hennessy](#):
>
> The teacher says he likes to start in the middle and work his way up and then fill in the blanks at the end. I’m sure he would but I need the blanks filled in to keep my interest in trying to program. I’m not doubting his way of teaching in any way as I would guess it’s harder to pick up the beginning than to throw the student right into the commands. Anyway I’m on lecture 2 of his class.
> 
> He jumps right into how to navigate this robot using commands such as “move, turnLeft, pickUp” and he also uses conditions such as move only if no object blocks path. The programing program is called Eclipse.
> 
> What I want to understand is what created the commands and conditions, and how the robot can react to them. I guess to not give me a full lecture on the question, just tell me if it is part of the programmers job to create commands and conditions for the program they are building or is that the magic of the each different programming software? Any extra details are welcome. Programming won’t be hard for me as long as I can make any to some sense about it.

To simplify all the other answers, each programming environment, like yours, can look like a computer with a specific set of instructions and data. In this case the instructs are move, turn left, turn right, and the data are the blocks.  
Until you get down really low, each of these environments is implemented by yet another environment. For the purpose of your block world, it is not important if it were done in Java, or C, or C++, or Perl, or even assembler. Hierarchy and abstractions hide the messy details from you, and you can have exactly the same environment implemented in a couple of different ways.

Going up, you could use the language you are now programming in to define a new environment, say with instructions like pile up all blocks, spread all blocks, etc. Probably not too useful, but you can.

Let’s compare C and Java going down. Java does not work by translating Java instructions into machine instructions. Rather it runs on a program called an interpreter which takes a Java instruction, does some checking as to validity, and runs a subroutine to execute it. C on the other hand compiles its code right into assembler or machine language, depending on the implementation. At this level also the implementation can be done in several ways. You can interpret C if you’d like to, or you can compile Java right into machine language, but the language definition probably assumes an interpreter so this might not be real Java anymore.

The same principle holds even when you go down to machine or assembly language. (An assembler just makes it easier to write machine language, it is not actually a language per se.) When I taught assembly language on an old CDC machine we weren’t going to let students run actual assembly language programs which might crash the entire system and get lots of people mad. They ran instead on a simulator which produced the same results and gave them useful information when the screwed up.  
As another example of this, two computers with the same set of instructions can be implemented in different ways. IBM pioneered this - the faster versions of the 360 series had instructions in hardware, the cheaper and slower ones had them implemented in microcode. One big sales point was that they implemented microcode to emulate an IBM 1401, very popular at the time. People having 1401 programs (usually written in machine language) could move them to a 360 where they would run without changes and run faster.

So, whatever you are doing, think about the set of instructions at that level, and if you need to dig deeper think of the way someone implemented that set of instructions. It clarifies things tremendously.

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