Posts

Laid out (arrayed) out before you...

We're at the last building block - data structures! But, there is no way to cover every kind of data structure because it is possible for anyone (even you) to make a new one at any time. So instead, we will start with the Array. Just about every programming language includes a built in type that corresponds to an array and the defining characteristic of an array is that each element stored in it can be referenced by an index number that counts up from index [0] and goes up through index [n-1] where 'n' is the number of elements in the array. Usually, there is an easy way to know how many elements there are in an array with some sensible name like 'size', 'length', or 'len'. That is a bunch of words, so let's see a simple example of an array called 'example' with ten elements in it. Here is the list of all of the elements along with their indexes (indices?): example[0] example[1] example[2] example[3] example[4] example[5] e

Are there bees around here?...

Image
One test that many programmers are asked to do at some point in their life is FizzBuzz. If you haven't heard of it - The problem of FizzBuzz is this (stolen from HackerRank): Write a short program that prints each number from 1 to 100 on a new line. For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number. I said last time that I was going to start with a clumsy solution so here is my 'phoning it in' version of pseudo-code for this (let's call it version 1): Loop through the numbers from 1 to 100 and put that number into a variable called 'num' If 'num' is evenly divisible by 3 Print 'Fizz' Else If 'num' is evenly divisible by 5 Print 'Buzz' Else If 'num' is evenly divisible by both 3 and 5 Print 'FizzBuzz'

Is trying to program making you loopy...?

So we've discussed two of the main building blocks of programming: Data and Control Structures. With those, you can do things once for every time your program runs. Well what if you want to do more than once and done? Loops. As I've mentioned before, there are two basic kinds of loops. One kind runs a particular number of times that the program 'knows' in advance. The other type runs until some condition becomes true. That first kind is a For loop. Here is an example of how you would use one...Suppose you wanted to print out the numbers from one to one hundred. The pseudo-code: For the numbers 1 to 100 Print the number Sort of a trivial use though. How about if we want to also print out whether the number is even or odd: For the numbers 1 to 100 If the number is even Print the number and the word even Else Print the number and the word odd Did you just feel a twinge of excitement? The pieces are starting to come together... Let'

Am I too controlling?...

Well, we've discussed an overview or programming terms and discussed data. How do we get a program to do something interesting? The answer...control structures! Control structures are commands that check for some condition and then, base on the result of that check - run different blocks of code. The simplest type of check is whether or not something is 'true'. To accomplish this, we use If-Then. For example, suppose we want to have a program either say 'Good Morning' if it is before 12 noon. I will be using pseudo-code so I get to ignore some of the details - like 'how do you know what time it is?': Find the time and store the hour of the day in a variable If the hour is less than 12 then Print 'Good Morning' Easy-peasy! But, if it is after noon, then our program won't do anything (at least as far as the user can tell). So, let's have the program say 'Good Afternoon' if it isn't morning. To do this, we move on

Constants and Variables....

So, you want to make a computer do something useful. Well, then data is going to be involved one way or another. Even the simplest programs (like 'Hello World') deal with data! Some of it might be invisible to you - but it is there. Let's take a look at Hello World. First of all, if you don't already know - the objective of this 'first' program whenever you are beginning to program in a new language is to print out 'Hello World!' (or some variation of that). We may as well take a look at the objective to figure out what the algorithm and pseudo-code would be for this. First the algorithm: Open a connection to some output device (usually the screen) Print the string 'Hello World!' Close the connection Most programming languages automatically open a connection to the screen for you so this step is almost always ignored. But if you think about the fact that it is happening (even if behind the scenes) then it will make your life eas

Building Blocks...

When thinking about how to build a program, you need some vocabulary and some pieces to build programs out of. There are a relatively small number of basic building blocks to build programs out of: Data Control Structures Loops Data structures Each one of these deserves and needs extensive explanation. But first, here is a quick overview of these. To start - lets talk about about data. In order to make sure that we don't make this specific to any particular language I will just talk about fairly basic data types: Integers (whole numbers) Reals (decimal numbers) Booleans (true or false) Strings (text) With these four types (possibly in combination) you have enough to store just about anything that you need to. Control Structures provide you a way to decide which section of code is run based on some condition. Examples of control structures are: If Then If Then Else Case (or Switch) The If-Then lets you run a block of code only if some condition

So, what is programming?

Image
Well, that is a good question. And I think that it has a simple answer: Programming is the act of transforming a desired process into an algorithm and then implementing it. I don't know if anyone else ever said it that way - So I am going to pretend that I was the first 😀 But what does that even mean? If I want to be a programmer/coder what do I have to do? Well, there are two major steps there: Transforming a desired process into an algorithm (a defined set of steps to be followed) Implementing it The first step means that you have to figure out all of the little steps that are part of the process that you want the computer to perform. Doing this is usually harder than the actual coding. Here is an example to illustrate: add up the odd numbers between zero and 100 Well, for a person - that would be enough. Computers need a bit more detail. For example, what is an odd number? And, this is where pseudo-code makes its appearance. Pseudo-code is something that