Tuesday, August 11, 2009

What is Programming? Part II

Learning to programming takes time. No one just "knows how to do it." Programming demands that you plan ahead, think logically and creatively, be patient but persistent and pay close attention to details. Although, learning to program can be a challenge, it can also be a lot of fun!

All programming languages have 8 basic concepts you will need to master. Although, the techniques each language uses to deal with these concepts differs...slightly...once you have the basics behind these concepts down learning any computer language becomes easier.

  • Symbolic Assignment - All languages have named storage areas where the programmer can assign data. These symbolical storage areas can hold data that can vary - variables as well as data that will never change - constants. Different languages deal with these storage areas and how you assign values to them differently: some require that all storage locations be declared by name in a special area before being used, some require that the type of data that will be stored be defined in some detail when the variable/constant is declared, some are very strict about what can be stored in a variable and some are very lax. But all languages have user-defined, named, storage locations and all allow the program to assign values to those locations and retrieve the data stored in them.

  • Syntax - Syntax refers to the "grammar" of a programming language. Yes, programming languages have a grammar! Typically, you will use spaces to separate words, periods, commas and semi-colons will have meanings and how you lay out a "statement" will follow a format...like for example: verb noun . . . PRINT "Hello World"

  • Sequence - This is the order in which the statements will be read or executed. This is almost always from left to right, top to down in the source code, with statements separated by some sort of punctuation. In C type languages, for example, the semi-colon ";" is used to separate statements, while in CoBOL the period "." has the same purpose. Almost all languages allow you to "block" several statements together...think of this as being sort of like a paragraph. In fact, that is what it is called in CoBOL! In C type languages a block of code will be surrounded by curly braces " { statement; statement; }

  • Selection - This is how the programming language makes decisions. "Perform this statement if this is true, and that statement if this is false." Most languages use some variation on the If (true/false evaluation) block to do if true; else block to do if false.

  • Iteration - Often you will want a program to perform the same statements over and over until something is accomplished. To do this you create a loop using while, do/while, or for instructions. In a way these are like Selection, but rather than "do this block if true", it becomes "continue doing this block while this is true."

  • Input/Output - All programs will have ways to get data into a program and to get information back out of the program. Here the program is usually dealing with external hardware: the keyboard, the screen, the file-system on a hard drive or perhaps across a network. This sort of interaction tends to be pretty complex, so almost all higher level languages have extensive libraries already created to deal with this. In C++ you might write a simple: cout << "Hello World!"; to display Hello World on the screen, but what is really happening is that you are calling a library where maybe an entire page of code has already been written defining exactly how you get those two words to appear on a screen. As an aside, the majority of that code in the library is dealing with the <<>
  • Branching - Deprecated! Deprecated means you shouldn't use this, because it has been superceded and may go away in the future. While I don't expect branching to disappear from computer languages, you still shouldn't use it! Okay, having said that, what is branching? It means jumpping from one statement to another somewhere else in the program...in other words, not following the normal sequence. The reason this is frowned upon is that if a programmer does a lot of branching in a program it becomes harder and harder to understand what he was doing and why he was doing it that way. Where you can find branching you will find the goto statement.

  • Subroutines - This is what has taken branching's place! A subroutine, also known as a module, procedure or function, is a block of code with a name. As a program executes there is an "instruction pointer" that moves along letting the computer know what it is to execute next. When a program "calls" a subroutine's name the next "instruction pointer" points at the beginning of the subroutine's code. The computer executes the block of code inside the subroutine, and when it finishes the subroutine issues a return instruction which causes the "instruction pointer" to return to where it came from in the calling program. This sounds more complex than simple branching, but it reads much easier in actual programs. Subroutines have a number of other advantages over branching as well.
Once a programmer understands these 8 programming concepts he/she can pick up new "procedural" languages pretty easily.

Object-Oriented Computer Languages (like Java, C++/C# and Smalltalk) use the above 8 programming concepts and add 4 more:
  • Abstraction
  • Data Hiding
  • Inheritance
  • Polymorphism
I'll write about those later.

What is Programming? Part I

Computer Programs are made up of a series of instructions that the computer executes to perform some desired task. The process of defining these instructions that the computer will execute is called programming. You normally store the instructions in a standard text file (ASCII file), also known as the source code, which is then either interpreted by a program called, appropriately enough, an interpreter into "machine language" (the binary codes a computer actually executes) or is compiled by a program...guess what, it's called a compiler. Interpreted code typically is executed instruction by instruction immediately by the computer. Compiled code is saved to a file in its binary format for later execution.

Compiled code, also known as object code, is then run through another program called a Linker to link it to any "libraries" of code the program referenced. Once a compiled program has been linked it is known as an executable and will often have a three letter extension of .EXE or .COM.

Keep in mind that programmers, not being stupid, don't want to re-invent the wheel every time they write a program, so they have created many, many, libraries of code over the last 50 plus years. Today almost all programs will link into code already written by those that have come before. Today's programs are often "frameworks" that provide calls to code in many of those libraries .

When we talk about a computer language we are generally talking about an English-like language that uses words and syntax to make up statements that we, humans, can easily read and understand. These English-like languages are called higher level computer languages. Higher level languages like Ada, BASIC, C, C++, C#, CoBOL, FORTRAN, Java, and Pascal...to name just a few...are how most programs are written today. The various languages have their own strengths and weaknesses, just as a carpenter won't try to use a single tool for every job, a programmer won't use a single language for every program. You should learn several!

There are also low level computer languages, called assemblers, that are much harder for us to read and understand. Assemblers typically allow a programmer to more finely detail exactly what they want a computer to do, so are used mostly to "tweak" programs rather than to write entire programs. Today, few programmers learn assembler, or for that matter how to work directly with machine code, however, if you plan to make a career of programming, you might want to consider learning how to work with these lower level languages.

Saturday, August 8, 2009

Visual Studio Express 2008

When talking about free C/C++ IDE's you can't ignore VSE2008 from Microsoft! VSE is a very big set of programs, must be installed on a hard drive, and isn't the easiest interface to work with, but it is a very good IDE!

An especially, neat thing about VSE is you can add the free Dark GDK to VSE. The Dark GDK is a very nice graphics and gaming library that was originally part of Dark BASIC, but was ported into a C++ library which can be easily added to the Visual Studio Express environment . I've seen true newbies to programming hack out a simple graphics game within a couple of weeks using Dark GDK and Dark BASIC, and it's just as easy with C++.

I highly recommend Visual Studio Express 2008, especially if you will be working on a simple computer most of the time. The learning curve for the Visual Studio IDE is steeper than several other IDE's, but in the long run it is worth it. Once you have a handle on the VS interface you'll find it easy to transfer your skills to Visual Basic, Visual C++, etc, etc, etc.

wxDev-C++

Speaking of Dev-CPP...

Although, you can develop windowed programs in Dev-CPP, it isn't really easy or convenient to do so. Unlike more modern IDE's Visual Studio Express, for example, there isn't a built in Form Designer, nor an easy way to add resources...like icons... to a project. Enter wxDev-C++!
wxDev-C++ is an extension of Dev-C++ by Colin Laplace et. al. This program helps you to create dialogs and frames for wxWidgets visually using a form designer. With all the wonderful features of Dev-C++, wxDev-C++ is still being actively developed. The main aim of this project is to provide the wxWidgets community with a free, open-source, commercial-grade IDE/RAD tool for development with wxWidgets.
Frankly even if you are just doing console based programs this newer version might be the way to go. I've been using the latest Release Candidates for Version 7.0 for the last six months with no problems at all for C and C++ console programs. There are still a few bugs with the form designer and sometimes windowed programs have some strange effects, but even then I haven't run into a "showstopper."

wxDev-C++
gets 5 stars from me!

Oh, and check out the tutorials at the wxDev-C++ site! There is also an almost complete book online with lots of help getting started on windowed programming. You will need to dig around on that site to find the actual PDF you'll need to download, though.

Dev-CPP

If you are looking for a good little C/C++ IDE (editor, compiler, linker, debugger all in one package) to run in the Windows OS you can do a lot worse than Dev C++ from Blooodshed Software.

Dev C++ is free, open source, and easy to set up and use. You can even install it on a USB drive, pop it into any computer you want to work at and run it, then pop it into your pocket and walk away leaving nothing behind. This is very handy for me because there are a half dozen computers I use during the week, and I might be working on programs on any of them at one time or another.

Friday, August 7, 2009

First Post

Programming can be fun, but it requires an ordered and creative mind...and a great deal of patience. I began programming in CoBOL 42 years ago, two years before I ever actually saw a computer. I found a teach yourself "programmed instruction" book in the local library during summer vacation between my junior and senior year of high school. It looked like fun, so I checked it out and . . . and, I've been programming ever since.

My first experiences with computers was at the University of Florida where I spent many a long hour writing, debugging, and rewriting programs. I remember the keypunch machines with a mixture of fondness and loathing. At UofF I took courses in CoBOL and FORTRAN, even though my major had nothing to do with computers. I continued to "tinker" with computers and programming when I transferred to the University of West Florida, but my major in Social Studies lead to middle-school teaching, not programming.

During my time as a middle-school teacher I did nothing with computers, nor programming. It was the early 70's and computers were still large expensive machines. The county office had a mainframe, but there were no computers out in the schools. The 12 and 13 year old kids eventually wore me out and I left for the quieter halls of academia.

Back in college I got an MEd, an MBA, neither of which I ever really used for anything, and then a degree in Computer Science. I had, again, begun to "tinker" with programming while getting the two masters degrees, teaching myself BASIC, Pascal, C and assembler. I finally decided that I liked computer programming, so why wasn't I actually studying computer programming, so I finally got my degree in CS.

The job I got coming out of college that last time was with Radio Shack. I was hired to teach teachers how to use Radio Shack programs on Radio Shack hardware. I didn't really want to go back to teaching, but once I started I discovered I like to teach. I really like to teach. I just don't want to teach in the public schools. :)

In 1986, I was able to secure a job as an instructor at Pensacola Junior College. I was assigned to a branch campus where I taught anything that had a computer involved with it...and several courses that did not. I'm still at PJC, though now the main campus, and teaching mostly programming language courses. One day, I'll retire from here and won't teach programming, but I'm pretty sure I'll still be programming for many years to come.