Programming Fundamentals

As students dive deeper into the heart of programming, I bring you another set of questions that I will try to answer. Feel free to correct me and make comments. Thanks!

  • What is the difference between an Arduino and a Raspberry Pi? (Hint)

From a user’s perspective, the Arduino is more designed for “hackers” to be used in embedded systems. For instance, the example often presented is if you want to turn on an LED in code. Using the Arudino, you just wire up an LED and a resistor to one of the IO pins on the arduino and do a little bit of coding.

With the Raspberry Pi on the otherhand though, because it is a full on microprocessor, one first needs to load an operating system (however system) before doing any kind of cool things (like turning on an LED). But because it is essentially a full on computer, the Raspberry Pi can do much more complex tasks that would be impossible (or just too difficult to do natively) with the Arduino (i.e. output videos to your television).

  • What is a function and what is a parameter? Give an example from one of your projects and identify what part is the function name and what parts are the parameters.

In programming lingo, a function is just a piece of code that performs some action. In performing that action though, a function may or may not need some information from the outside. The information would be consider parameters, extra pieces of information given to the function in order for the function..to well function. For example, in Processing, “background()” is a function that sets the paints over the drawing surface with a color. Of course, in order to paint, it needs to “know” what color to paint and that is the parameter you would give it. To specify a gray scale value for instance, you can call background(GRAY_SCALE_INT) where GRAY_SCALE_INT is an integer between 0 and 255 inclusive.

  • What is the difference among: int, float, bool, and char. What do each of them mean?

Int, float, bool, and char are all native data types used in Java. They represent different types of data.

  • The int is used to represents a integer number (-2,147,483,648…-2,-1,0,1,2…2,147,483,647)
  • The float is used to repesent decimal numbers.
  • The bool represents one of two values: true or false.
  • The char is used to represent characters (e.g. ‘A’, ‘g’, ‘\u123’) (Note the single quotes)
  • What is the difference between ”=” and ”==”?

So the single equal sign (“=”) is used in assignment such as int x=7 which assigns the value of 7 to the variable x.

The double equal sign (“==”) on the other hand is used in comparisons and evaluates to true or false depending on whether the two operands are equal or not, respectively. (e.g. 5==7 would evaluate to false)

  • Why do we use variables in programming?

From a functional standpoint, the use of variables allows the coder to manipulate piece of data without knowing the value of the data apriori thus leading to more general code. (For instance, if you were asked to calculate the sum of the integers from 1 to 100 inclusive, you can use a for loop that sums up the numbers 1, 2, 3…, 99, 100. But if generalized the problem to summing up integers from integer startInt to endInt, then you can reuse the same code for calculating the sume of integers from any number to any other higher number.)

Of course using variables often make code more readable by giving pieces of data more meaning names. For instance, if we were using Processing to create a sketch window of width 300 and height 300, we can say “size(300, 300)”. But if we came back to this piece of code months later and forgot about what size accepts but need to change the window to have width 300 and height 200, then we need to do a little research to figure how to do so. On the other hand, if we from the start defined variables width and height and instead had code that said “size(width, height)”, we would easily be able to just change the variables to meet our needs.

 

  • Why do we use loops in programming?

The use of loops is all about creating more manageable code. Having to mimic the functionality of loops without the loop structure often leads to repeated code which leads to code that is harder to change/and even understand. Some functionality is even impossible to perform without loops.

For instance, say you wanted to go through an integer array and print out the contents of the array without knowing the size of the array at the time of coding. Well, then the coder, without loops, has no way to actually perform the task. That is because, without loops, the coder essentially has to hardcode reading each part of the array and print out the contents but without knowing the size of the array, the coder doesn’t even know how many lines to hardcode.

 

  • Explain what this means.

The image above is just a schematic representing generally how code high-level code that many coders write (using Java, C, etc.) actually gets translated into something that can be processed and run by a computers. As you can see, the code that we write in a high-level language first gets compiled into assembly (often less human-readable code that represents the exact functionality of the high-level code but in terms of instructions that the computer chip understands). From there, the assembler then translates the assembly into computer code,  a series of 0’s and 1’s which the computer actually operates on.

 

I’ll leave the following for another time…

  • Write a sentence about 3 things you’ve learned that you haven’t written about on your website yet.
Advertisements

Game Review #3: Achievement Unlocked

For the third game review of the summer, I bring you Achievement Unlocked. If you played This is the Only Level, the game review in our last review, then the main character of Achievement Unlocked will seem quite familiar. That’s right, the little blue elephant is back, this time stuck in the same closed off world for 20+ minutes as you try to figure out how to unlock 100 achievements.

As such, there isn’t much guidance as to what to do (outside of the name of the achievements) in order to unlock those achievements. At least with This is the Only Level, you know that you need to get the elephant to the tunnel at the end. With Achievement Unlocked though, you can spend countless minutes trying to figure out how to unlock the achievement (until you give up and look at the hint).

AchievementUnlock_Screenshot

So, I have a love hate relationship with Achievement Unlocked. I enjoyed unlocking those achievements but the lull time leading up to those unlocks got old quickly.

Getting Started with Processing

Today, with the students diving deeper in the world of Java using Eclipse, I say farewell to the language of Processing (temporary anyway).

Having been deeply ingrained in C, I found that working through the book was a great refresher on Java. I can only imagine what fun it would have been to start learning Java with this program. Sure it hid away many of the ideas of classes but the graphic/sketch emphasis really motivated me to code and experiment. So I didn’t learn much content from the book per-say given my background in coding, but seeing how involved the students got in their projects with processing, I got a glimpse into how to really motivate such students to code.

Day 3 – No Storm Yet

Day 3 (yesterday) revealed to me these kid’s creativity. Many knew what they want and were willing to experiment. Unfortunately, I felt many still need to work on really understanding their code. Too often was I asked “How do I do <insert action>?” which was immediately followed by “Can you show me how to do <insert action??” Perhaps I need to try a different strategy of getting them to figure out how to do things for themselves. Perhaps entering the world of Eclipse will force them to do so. Day 4, here I come.

Day 2 – Calm Before the Storm?

The second day was rather easy. I get the feeling that the students are really understanding how to get the work done and gaining a great deal of experience with blogging and gaming. Some may need to work on how to debug/interrupt errors but hopefully they will get plenty of experience with that as they move on to a more mainstream IDE like Eclipse. With all that said, the second day was less hectic and so I got to work on the Lego Mindstorm instead (got bluetooth working!).  I fear though that with the introduction of real Java and Eclipse, will I get to experience the rush of Day 1 again? Either way, I can’t wait for day 3.

Game Review #2: There is Only One Level

For the second game review this summer, the class (including myself) played “There is Only One Level” which can be found here: http://armorgames.com/play/4309/this-is-the-only-level

OnlyOneLevel_HA

I was intrigued by the various controls (and the cleverly labelled stages of the “one level”) and really appreciated the creativity that the creators put into getting an elephant to the end of the tunnel. At points it got kind of repetitive, at others I was lost, and yet still at others you wanted to throw your keyboard ON THE GROUND because you just can’t get the elephant to stop getting impaled on the deadly spikes. In the end though, I found myself enjoying the game (and the stats at the end almost made me play it again just to see if I could do better).

How We Talk To Computers

Now that the students had a chance at tackling these questions, let’s see what I can come up with. (If you are reading this, feel free to chime in with corrections/comments. Thanks!)

nextep1

  • What do computers do better than humans?

Well, computers were designed to…compute. So computers are definitely better (faster/more accurate) at computing then most humans. This translates into rendering images faster, storing data more reliably, communicating at longer distances…the list is endless.

  • What do humans do better than computers?

That is not to say that computers are better then humans at everything especially since humans created computers. So humans can design…can think outside of the box. Sure, there are advanced in AI but have yet to really match humans in our ability to make sense of our sensors (eyes, tongue, nose, ears, skin) and judge the quality of something. Above all else, computers have yet to achieve true consciousness…we think.

  • What is the difference between a Microprocessor and a Microcontroller?

Generally, the two are the same. It is just that microcontrollers (like the Arduino) are typically purposed into embedded systems/smart products and so  are designed to perform “simple” actions quickly and made to be more hacker/hobbyist friendly . On the otherhand, the microprocessor is typically purposed into computers and so are designed as such.

  • What does the Assembler do?

The “assembly” takes assembly code and converts that into bits that the computer can execute.

  • What does the Compiler do?

The “compiler” takes source code (something say a coder would write in Java or C) and covert that into a much lower level code (e.g. assembly or even machine code).

  • What is an IDE?

IDE typically is an acronym for Integrated Development Environment. IDEs like Eclipse are quite ubiquitous in the programming world because they combine a lot of the functions a coder needs into one piece of software (including a place to edit code, functions to run the code, and functions to debug the code).

  • What is the Processing IDE?

The Processing IDE are partial differential equations…I mean PDE. Find more information here.

  • Why do we program in High Level Languages?

Since we often think at a high level, being able to program at the same level will allow us to get working code up faster and help us to move on to tackling more problems. (At the other extreme, if we instead had to talk in computer language–binary–imagine how long it would take to just tell the computer to print out “Hello World!”. And even if we did survive to do so, then we had to suddenly switch to a different computer with a different chip, we would have to do it all over again.)

  • What is binary, octal, decimal, and hexidecimal?

Binary, octal, decimal, and hexidecimal are all common forms of representing numeric values, each constrained to using only a certain set of symbols.

Binary is only allowed to use 0 and 1, octal 0 to 7, decimal 0 to 9, and hexidecimal 0 to 9 and to A to F.

For example the equivalent to the numeric value of 29 (which is decimal) is

  • Binary: 11101
  • Octal: 35
  • Decimal: 29
  • Hexidecimal: 1D