So you want to be a programmer? Part One
The first and foremost thing to realize about programming is that, like most things in life, if you try to tackle it all at once its going to appear to be impossibly hard. However, if you break it up and simplify the scope of what you are focused on, its much easier than it appears.
To begin with, in my opinion, to be a programmer you need to have a good solid grasp of logical concepts. True, False, And, Or, comparison operators, order of operations and all that goes with it. From my point of view, the best place to get this is in a Discrete Mathematics course. The classes that I took used a book called ‘A Logical Approach to Discrete Math’ by David Gries and Fred B. Schneider. As with all things, your mileage may vary when it comes to the usefulness of this book. In fact, I don’t even use it anymore, but I still own it from my college days because I found it to be that useful once, at least more useful that the twenty dollars I would have gotten selling it back to the student store. David Gries has another book called ‘The Science of Programming’ which I suspect would also be helpful, but I’ve never read it.
The next thing you need to do is to understand how you learn best. This isn’t always an easy task, expect it to take several hours of several days if you want to do it right. To me, programming isn’t about memorizing all the nuances of a single language; you’ll get more familiar with a language the more you use it. Programming is more about knowing where to find what you need. To that end, you’ll need reference books. For every programming language there are dozens, if not hundreds, of books on how to program in them. What I suggest you do is go to book store with a decent sized computer book section, pick one language (HTML, ASP or JavaScript are nice easy places to start), pick a dozen books on that language, find the same or similar chapter in each book and read it. Do this with a half dozen chapters. Then think about something you’d want to do with the language (for example, looping structures) and use the contents and index to find that section and see how quickly you can find the answer you need. Many of these books will have different layouts, and this is what you are testing; to see if the layout of a particular book melds with the way your thought processes work to make the subject easier to grasp and learn. For me, I prefer the O’Reilly ‘In A Nutshell’ books; the layout of them is good for me, I like they way they group topics and usually have no trouble finding what I need, plus they don’t waste time with a lot of flowery goofy examples that usually confuse me more than help. But don’t take that to mean you should use the same books I do, take the time to find the right series of books. The main reason for this is when you find yourself in a situation of needing to learn an all new programming language you can just go pick up the book you need in the series you like first and have a pretty good shot of having the right book off the bat without wasting a lot of money.
Now that you’ve chosen a book series, I’ll tell you that I’m not an advocate of owning lots of programming books. Most times, I use the book to get going, to have in my hand, and to find alternatives to something that’s not working (like if a ‘for’ loop isn’t working for me, I’ll look up the ‘for’ loop in the book and in the same chapter will be a few other looping structures, one of which might work better). The most useful tool that you will have is the Internet. Learn how to use Google and other search engines (I actually prefer Ask.com for programming searches), and how to select keywords for what you need to know. Lots of people have questions, and on the Internet everyone has an opinion. Surprisingly, in the programming forums at least, the majority of those opinions end up being helpful. There are even websites that are nothing but a reference guide to programming, like www.w3schools.com.
You have your logic, your book, and your search engines… now you are ready to program.
So you want to be a programmer? Part Two
In my time as a programmer, I’ve worked on several projects that wound up being millions of lines of code. If I were to show them to you, your mind would likely get stuck on the enormity of the project and not realize that the entire thing was written one function, one line at a time over a lengthy period of time.
Programs, in my experience, boil down to three kinds of statements:
1) Assignment Statement
2) Evaluation Statement
3) Containment Statement
Every line of code that you write will do one of those things. So let’s briefly take a look at each one.
Assignment Statement: If you aren’t assigning one value to another value, then you aren’t doing anything. Every line of code that isn’t an Evaluation or Containment statement in your program should be assigning a value. If you calculate the value of three plus five, who cares unless you store it somewhere to be used later? Now, my designation of an Assignment Statement is pretty broad, but that’s the point. Why bother making a dozen designations when one will do?
Every language is going to have its own syntax for everything, and that’s what your book, the Internet and the help files in your development environment (if there are any) are for. If you are assigning a value to a variable for later use, or assigning a length to a textbox, or a color to a background, or a table to a dataset, it’s all assignments.
Evaluation Statement: When you aren’t assigning values, chances are you are deciding if you should assign a value. These are the statements where most of that logic stuff comes in. As with the above, every language will have its own syntax, but in general these will be ‘if’ statements, ’switch’ or ‘case’ statements, ‘for’ or ‘while’ loops, that sort of thing. These are there to make logical branching in your program, if a condition is true execute one block of code but if its false execute another block, or execute the following block of code X number of times or until a condition is true (or false).
Containment Statements: These are the lines of code that keep all your other lines of code from running into each other and executing all at once. These can be as simple as brackets used to associate a few lines of code to an ‘if’ statement, or they can be the call name and structure for a function. These lines define boundaries and name blocks of code, basically any line you have to write to make the program work but don’t assign a value or evaluate to true/false.
There is one gray area here, and that is calls to functions. I always think of these as Assignment Statements themselves because undoubtedly the function called will be doing assignments. When I explain my programming theories to other people, some like to put function calls in the Evaluation area, some in the Containment, and others like to create a fourth type of statement just for them. Its up to you really, whatever makes the most sense to you is how you should think of it.
Another minor sticking point is Comments. Because comments don’t actually do anything at all for the program itself, I don’t think of them as a statement type. Comments are best used to describe how a section of code relates to the overall project so that anyone who follows in your footsteps isn’t walking blind.
Now, knowing that there are only three types of statements in a program makes working with a program easier. So let’s take a look at an extremely basic program using HTML and JavaScript:
<html>
<body>
<script type=”text/javascript”>
document.write(”Hello World!”)
</script>
</body>
</html>
You have three sets if Container Statements: html, body, and script. And you have one Assignment Statement that is a call to the ‘write’ function of the ‘document’ object and passes a phrase to be displayed on the HTML page.
Let’s take a look at one with an evaluation in it:
<html>
<body>
<script type=”text/javascript”>
var d = new Date()
var time = d.getHours()
if (time < 10)
{
document.write(”<b>Good morning</b>”)
}
</script>
</body>
</html>
Once again we have the Containers html, body and script, but we also have a container in the form on the curly brackets with the ‘if’ statement. There are three Assignment statements this time. The first declares a variable, ‘d’, and assigns in the value and structure of a Date, which by default is the current date and time. The next declares a variable, ‘time’, and uses the ‘d’ object’s getHours function to get the hour. The last is a call to the write function of the document object that will put the passed phrase on the screen. The Evaluation statement here, the ‘if’, checks to see if the time variable is less than 10; if it is the contained code will execute, if not the code will be skipped.
Just to show how something that looks huge is actually just as simple, below you will find a link to an example of code used to build a page in an ASP.NET/C# program that displays a transaction printout. Now, some chunks of code are missing, like the constructors for the various objects used, but you should still be able to go through this ‘Page_Load’ function and identify the statements and see that even though its long and in some places convoluted, its still just those three statement types being used to perform a much larger task in small steps.
So you want to be a programmer? Part Three
Honestly, I’ve covered most of what you need for programming in Part One and Part Two. Once you have your logic, your books, your websites and search engines, and an understanding of basic design of a program, everything else is gravy… with one exception: SQL.
Most programming jobs, especially at large companies, will be dealing with databases. In order to get data out of or put data into a database, you need SQL which stands for Structured Query Language.
First let’s take a look at a database. What is it? In its simplest form, a database is a collection of tables, and a table, to use a readily familiar substitute, is a spreadsheet. The only major difference between a spreadsheet and a table in a database is that you can force data integrity into a table. If you define a column as an integer, you won’t be able to put a string in there. You can also define ‘keys’ and force uniqueness in a database table. If you want every row to have a unique ID, then you can define the ID column as keyed or indexed, and unique; attempts to insert a value that already exists in the table will fail.
What SQL allows you to do is collect a subset or aggregation of the data. The basic parts of an SQL statement are the SELECT, FROM, WHERE, GROUP BY, and ORDER BY.
Let’s take an example table of kids with lemonade stands called ‘lemonade’:
| Name | Price | Fresh | CupSize |
| Joe | 25 | Yes | 8 |
| Sally | 30 | No | 8 |
| Betty | 25 | No | 6 |
| Eddie | 35 | Yes | 8 |
| Walter | 15 | No | 6 |
The columns defined are the name of the kid, the price (in cents) of a glass of lemonade, whether or not the lemonade is freshly squeezed, and the size of the glass (in ounces).
If we were to write an SQL statement, “SELECT Name, Price FROM lemonade” you would get a list of the Name and Price of all the rows in the table.
| Name | Price |
| Joe | 25 |
| Sally | 30 |
| Betty | 25 |
| Eddie | 35 |
| Walter | 15 |
If we modify that query to find only the kids with 25 cent lemonade, it would look like this: “SELECT Name, Price FROM lemonade WHERE Price = 25″
| Name | Price |
| Joe | 25 |
| Betty | 25 |
Or perhaps we only want the Name and Price of the kids with 8 ounce glasses: “SELECT Name, Price FROM lemonade WHERE CupSize = 8″
| Name | Price |
| Joe | 25 |
| Sally | 30 |
| Eddie | 35 |
Now, what if we wanted those names in alphabetical order? “SELECT Name, Price FROM lemonade WHERE CupSize = 8 ORDER BY Name”
| Name | Price |
| Eddie | 35 |
| Joe | 25 |
| Sally | 30 |
Let’s get crazy… how about the average price of an 8 ounce glass of lemonade? “SELECT avg(Price) as AveragePrice FROM lemonade WHERE CupSize = 8″
| AveragePrice |
| 30 |
And further craziness… the average price of each size glass? “SELECT CupSize, avg(Price) as AveragePrice FROM lemonade GROUP BY CupSize ORDER BY CupSize”
| CupSize | AveragePrice |
| 6 | 20 |
| 8 | 30 |
Now, let’s add a second table, call it ‘locations’:
| Seller | Address |
| Sally | 123 Contact Way |
| Walter | 28 Island Street |
| Eddie | 45 Cruiser Avenue |
| Joe | 1900 Volcano Road |
| Betty | 62 Crocker Trail |
Now, let’s suppose we are thirsty, and we’ve got 25 cents on us. We want the Name and Address of each stand where we can afford to buy a glass of lemonade. To do this, we have to associate one table to the other. In our case it’s going to be simple because we are using the Name as the key in one table and Seller as the key in the other and they are unique. (If you are dealing with two tables that have identically named columns, you will need to qualify those column calls by using the table name you wish to select from, for instance if in our second table we used ‘Name’ instead of ‘Seller’ we would need to use ‘lemonade.Name’ and ‘locations.Name’ to distinctively identify them.) There are two ways to accomplish this, implicit and explicit joins.
Implicit:
“SELECT Seller, Address FROM locations, lemonade WHERE Price <= 25 AND Name = Seller”
Explicit:
“SELECT Seller, Address FROM locations JOIN lemonade ON Name = Seller WHERE Price <= 25″
The difference between these two statements is going to largely depend on the database being used. Some databases will handle one faster than the other. In most databases, the default JOIN type is called an INNER join. This means that results are only returned when a row exists in both tables and satisfies the ON clause. When you explicitly state a join, you can specify other types, such as LEFT. A LEFT JOIN will give you all the rows of the left table (locations in our example) and the data from the right table when the ON conditions are met, for any rows without matching data NULLs will be returned. There are several other join types, some are even useful in certain situations, so I recommend buying a book on SQL. There are many great pocket SQL books that should be more than enough on syntax, just keep in mind that not all databases support all SQL clauses.
Now that you can get data out of a database, let’s look at putting data in and updating existing data.
For putting data in the commands will look like this “INSERT INTO tablename (column list) VALUES (value list)”. So, in our above examples, to add a new kid to the lemonade table it would be something like “INSERT INTO lemonade (Name, Price, Fresh, CupSize) VALUES (’Tom’, 25, ‘No’, 6)”. With inserts, and depending on the database, there are other tricks you can use, such as replacing the VALUES clause with a SELECT statement so that you are inserting items gotten from another table or tables.
To change some existing data, use an UPDATE statement. It should be in a form like this “UPDATE tablename SET column = newvalue WHERE column = keyvalue”. So, if we inserted Tom’s record above and then found out he’s using 8 ounce glasses, “UPDATE lemonade SET CupSize = 8 WHERE Name = ‘Tom’”. And of course, you can update multiple rows just by using an ambiguous WHERE clause, “UPDATE lemonade SET Fresh = ‘No’ WHERE CupSize = 8″, this would be saying that all people using 8 ounce cups have been found to be using non-freshly squeeze lemonade and setting them all to ‘No’.
As with the JOINs, there is alot you can do with INSERT and UPDATE (and in the right places even UPSERT, which tries to update first, then inserts if no records match), but I’ll leave that to you, your SQL book and your programming.
So, now you have your logic, your book, your websites, an understanding of basic programming layout, and an introduction to SQL, this should be more than enough to get you started, and if you are a fast learner always remember that any language you don’t know you can probably fake long enough until you do.
As a final note, let me just say that in programming there is no point in reinventing the wheel unless you are being paid to do so. The best way to program is using the OPC method … Other People’s Code. This doesn’t mean you should plagiarize, stealing whole modules and putting your name on them, but chances are something you are trying to do has been done before and its been posted on the Internet. There is no sense beating your head against the wall of a problem if a solution can be found in a few minutes of web surfing.

