Tuesday, June 3, 2008

What Is Programming?

I felt that this was a good point to start a tutorial on C/C++ programming because clearly we need to have some idea of what we are trying to achieve before we start out. I recently found this definition on the web which I rather like
"Programming is planning how to solve a problem. No matter what method is used -- pencil and paper, slide rule, adding machine, or computer -problem solving requires programming. Of course, how one programs depends on the device one uses in problem solving."

This is taken from the ROYAL PRECISION, Electronic Computer PROGRAMMING MANUAL for the LGP-30. For those of you that have not heard of the LPG-30 you may be forgiven because it was first made in 1956 and has long since gone out of production. But it has the rather auspicious claim of being the type of computer that Edward Lorenz was using when he first noted the chaotic nature of weather systems.

Anyway back to what is programming... "planning how to solve a problem", note we are not actually solving a problem, the computer is going to do that for us. If we could solve the problem ourselves we would have no need to write the program. The premise for a program is that we don't have the time, tenacity or memory capabilities to solve a problem but we do know how to solve it so can instruct a computer to do it for us.

A simple example of this is what is the sum of all integers from 1 - 10,000. If you wanted to you could sit down with a pencil and paper or a calculator and work this out however the time involved plus the likelihood that at some point you would make a mistake makes that an undesirable option. However I can write and run a program to calculate this sum in less than 5 minutes

Code: ( text )
#include "stdio.h"

#define MAX (10000UL)

int main(int argc, char **argp)
{
unsigned long sum = 0;
unsigned long number;

for(number=1; number<=MAX; number++)
{
sum += number;
}

printf("The sum of all integers from 1 - %lu is: %lu\n", MAX, sum);

return 0;
}

This gives the result 50005000. As it happens I can verify this because I know that the sum of integers from 1 - N can be calculated as

(N+1)*(N/2)(10000 + 1)*(10000/2) = 10001*5000 = 50005000So

I have solved the problem of how to calculate the sum of all integers from 1 - 10000 and the computer has solve the problem of calculating the sum of all integers from 1 - 10000.And this is the crux of all computer programs; you can not program a computer to solve a problem unless you know how to solve that problem. There is no point even sitting at your computer with the intention of programming until you have the knowledge, be that a formula from a text book or a design document or a print out from a web page, of how you are going to set about solving the problem.So programming is the production of a set of instructions that describe how a problem can be solved. There are many languages in which these instructions may be written, for instance on the back of a bottle of shampoo you will often find the instructions describing how to solve the problem of making dirty hair clean:
  1. Wet hair
  2. Rub in shampoo to create a lather
  3. Rinse Hair
  4. Repeat

Note that because this set of instructions is aimed at human beings it makes a couple of assumptions. In step 4 for instance it makes the assumption that normal English is in use and that the instruction will actually be read as “Repeat Once”. It is also likely that an human running these instructions will not repeat step 1 because their hair will already be wet so they will judge it unnecessary to repeat that step.And that is one of the major differences between humans and computers. Humans have judgement and free will and will not run any instruction they deem not required or nonsensical where as a computer will do exactly what it is told with no judgement on the need or sanity of the instruction. Give the instructions above to your computer and it will never get out of the shower.

Google: Android will be 100% open source

Contrary to some reports, everything that makes Android “Android”, including all the core platform components and libraries needed to port Android to new devices will be open sourced under commonly used, industry standard licenses, says Google.
What is openI confirmed with three different Google employees at the Google I/O conference in San Francisco that the core Android platform will be 100% open source. Even multimedia codecs, which historically are held close to the vest will be open. Except where noted, everything will use the Apache software license (ASL v2). This is the same open source license used by projects like the Apache HTTP server, Tomcat, Harmony, and many other large projects in the open source community.
There are two exceptions to the Apache license rule:
Software that is already covered by by a free/open source license will continue to use that license. Most notably, this includes Google’s enhancements to the Linux kernel. Linux uses the GNU Public License (GPL v2) so enhancements to the kernel will use the same license.
Any software that touches Eclipse, for example the Eclipse Android Development Tools plug-in (ADT) will be licensed under the Eclipse Public License (EPL), because that’s what Eclipse uses.
What is notGoogle chose the Apache license because it gives carriers, OEMs, and application developers the freedom to use whatever license they want for their own software. While Google encourages everyone to make their own code open if possible, it’s not required by the license. Even Google plans to make a few of their applications closed-source, including their GMail application. These programs are not part of the core Android system, even though they may be bundled with Android phones.
A Google employee I talked to felt the need to apologize for this. “We’re not holding it back for any nefarious purpose,” says Dick Wall on the Android team. “We’re simply not ready to publish the API that talks to the back end server.” This makes sense given Google’s extreme reluctance to be “stuck” with a poorly thought out API that they can’t support forever. This doesn’t preclude the company from opening up the source to those apps later.
Remember that up to now, all the software on your typical cell phone has been proprietary. With Android, carriers like Sprint and Cingular are free to use either open or closed source for any custom applications they install on their new Android phones. And of course, third party programs (like the ones you write) can be open or closed. It wouldn’t surprise me to see completely free/open distributions of Android which eschew any proprietary add-ons in favor of open source alternatives.
Ed Burnette has programmed everything from device drivers and compilers to video games and multi-user servers. He is currently writing enterprise software in a variety of languages including C, Ruby, Python, and Java. For disclosure of Ed's industry affiliations, click here.

read more digg story