Archive for September, 2010

Where to Start

Posted: September 17, 2010 in Development
Tags: , , ,

One of the most frequently asked questions I get from beginners in programming, is that of where to start. This is very common amongst beginners, that they are given the tools to do almost anything, but they lack the inspiration of what these tools can be used for. As with anything, practice makes perfect, and programming is no different, so anything you can think of is really good exercise.

Besides practicing the use of the tools you are given though, I recommend a gradual move into practicing techniques, rather than syntactical practice. I look at programming as problem-solving, and each time you solve a problem you learn a technique for a given task, with practice you learn more and more techniques — some even for the exact same problem, just more efficient than the last. So, I suggest setting yourself goals, modest goals to begin with, practice the goal until you have a thorough understanding of the problem and solution, even try different ways of accomplishing the same goal — this way you will not only have understood the problem, but also gain a deep knowledge of various techniques to solve it, which will come in handy later on.

From Beginner To Intermediate
These are a few suggestions for you to practice, that get increasingly difficult to solve. If you finish all, go back to the first project and try to solve it with any new technique learned as you progressed. And if you are learning an object oriented programming language, such as C++, make sure you make everything an object in the project, as it will ensure a very good understanding of how OOP (Object Oriented Programming) works. Once you get familiar with OOP and comfortable working with it, you will not be wanting to go back to procedural programming — and then you can call yourself an intermediate programmer.

  • Hello World — Printing a string to the console.
  • Guessing Game (eg. guess a number) — Generate a random number, have the player try to guess the number.
  • Tic-Tac-Toe — Slightly more complicated game, will challenge you on several aspects of basic programming.
  • Pong — Very simple game, but requires animation, which can be quite difficult at first. Will get you familiar with time-based programming, real-time input interpretation and event handling.

Anytime you feel like you don’t know exactly how to solve a problem, write it out in pseudo-code, as such:

create keyboardInputVariable
generate aRandomNumber

while keyboardInputVariable does not equal aRandomNumber
     ask user for input
     set keyboardInputVariable equal to keyboardInput

// once outside this loop, the number has been guessed
print game-over string

By writing out pseudo-code, things become much easier to solve, as you have the solution in —almost— plain english.

I hope this helped you get started on your first projects. If i neglected to mention something, that you as a beginner, would like to know on the subject of getting started, let me know by commenting and I’ll update the post accordingly.

Count in Binary

Posted: September 10, 2010 in Tips & Tricks
Tags: ,

I felt like doing a quick post on something this evening, and so tonight I’ll be teaching you how to count in binary. Regardless of whether or not you are a programmer, being able to count in binary is quite fun.

What is Binary?
Binary refers to a system consisting of two components, and in the realm of computing we recognize these two as ones and zeroes.

1 .. 2 .. 4 ?
Counting in binary is quite simple. Consider a block of zeroes, say 8 (eg. 00000000), each of these numbers are called bits, and 8 bits make up one byte.

0	00000000
1	00000001
2	00000010
4	00000100

Notice the pattern here, that each time you move the 1 one over toward the left, you increase the value by a factor of 2 (multiplication by 2). So, 8 would be 00001000.

Where did 3, 5, 6 and 7 go ?

0	00000000
1	00000001
2	00000010
3	00000011
4	00000100
5	00000101
6	00000110
7	00000111
8	00001000

Notice that on each pass of multiplication by 2 (1, 2, 4, 8, 16), we fill the gap of zeroes behind it in a pattern similar to how we did the multiplication. The only difference is that we are counting on top of it. If you look away from the bit that make up the number 8 (fifth bit from the left), you are just counting 1, 2, 3, etc. all over again — this is illustrated below.

8	00001000
9	00001001
10	00001010
11	00001011
12	00001100
13	00001101
14	00001110
15	00001111
16	00010000

There is also a visual pattern going on here, if you look at each column of the numbers 0 through 8, look at the rightmost column, and you will see the alternating pattern of even and odd numbers (0 is even, while 1 is an odd number). The same pattern emerges when you look at the next column, which alternates in a pattern of 2/2 (2 zeroes, 2 ones, etc.). As you may have guessed, these patterns are found all throughout the columns, as the next column will then be 4/4 — this makes a nice rule of thumb to remember binary counting by, you can also immediately tell whether or not it is an odd or even number, just by looking at the rightmost column.

If this still doesn’t make a whole lot of sense, try adding two binary numbers together, as shown below (overly simplified, for illustrating the correlation).

8 + 2 = 10	00001000 + 00000010 = 00001010
16 + 5 = 21	00010000 + 00000101 = 00010101

Hopefully this was understandable. It is quite easy to count in binary, once you know the pattern. With 8 bits (one byte), you can count from 0 to 255, of course you can always extend the range to 16, 32 or even more bits if you wish. Knock yourselves out, have fun.