Showing posts with label computer programming. Show all posts
Showing posts with label computer programming. Show all posts

Monday, January 14, 2013

Computer Programming Styles

Computer Programming Styles

This article discusses top-down programming and modular programming styles that I have known. Although top-down programming ans modular programming are the same, there are different styles of programming that achieve the same end.

Computer Programming: The Basics of a Well Designed Program


Computer Programming: The Basics of a Well Designed Program

This article discusses all the elements of a well designed program that I learned during my 20+ years as an embedded systems software engineer.

Programming with Microsoft Small Basic

Friday, January 13, 2012

Basic Concepts of Computer Programming

 

I originally published this article on Yahoo Voices under the pen name John Mario.

This article is intended for those who have not had any exposure to computer programming and have no knowledge of electronics. This article does not define how to write a program in a specific language. It only covers the basics.

In order to write a computer program, you need a compiler. A compiler allows you to use a specific set of instructions to create a computer program and then convert that program into machine language.

Each compiler is for a specific programming language. A programming language is a specific set of instructions available for use in any program. Two very popular programming languages are Visual Basic and Visual C++. The modern compilers provide the user with an editor that allows the user to type in the program. You would type selected instructions in a specific order to perform a specific task. For example, you might want to collect information from the user and display that information on the monitor.

One instruction found in compilers is the print instruction.

If you wrote a program to display the phrase "Hello World," you would use the print instruction.

It would look like this:

print "Hello World!"

Each compiler may require a different syntax for the print instruction. For example: the C++ compiler requires a semicolon at the end of each instruction. Hence in C++ you would type

print "Hello World!";

There are other requirements for a complete C++ program to print "Hello World." But the exact contents of the complete program in C++ is beyond the scope of this article.

After writing and saving your program, you have to build your program. Building a program means converting the program to machine language. The resulting machine language file contains binary codes. When you build a program, the program may list syntax errors. These errors are instructions that are typed in wrong. They may be missing punctuation marks or they may contain unrecognized words.

When you execute the program, the binary code is converted into voltage levels that are applied to the electronics inside your computer to cause the computer to perform a specific action.

After you build the program, you have to test it. You start by executing the program. If the program does not run correctly, you have to examine the program to find out what is wrong. Debugging a program is an art by itself.

Learning programming is a challenging task that will consume a significant portion of your time. I highly recommend taking a course in school. However, if you prefer to learn on your own, you might join a programmer's forum on the web.Then you can ask questions in the forum about which is the best compiler for you and which books they recommend. Your best bet is to go to your local book store where you can read a few pages of the book to find out if you can understand it.

Reference:

My experience as an embedded systems software engineer.

A Generic Introduction To Computer Programming

I originally published this article on Yahoo Voices under the pen name John Mario.

This article does not focus on any particular computer language. It introduces computer programming by explaining some of the programming instructions that exist in all computer languages. It is directed toward those who are curious about computer programming, but have not yet decided to devote time and money to it.
 
Computer Programming is the art of using a set of instructions to force the computer to perform a certain task. The programming instructions described in this article will be written in plain english.
The following computer language instructions will be explained in this article:

The assignment statement
The PRINT instruction
The IF instruction
The ELSE instruction
The INPUT instruction
The WHILE instruction
The FOR loop
Instructions that perform math operations.

The Assignment statement
Any computer program needs to store temporary data provided by the programmer in memory. The programmer simply provides a name for the data being stored and the value of that data. The programmer does not have to know the exact memory location. The program automatically takes care of that.

For example: If you want to store the price of an apple, you could use the word apple_price as the name of the memory the price of apples is stored in. Then you store a price in the memory named apple_price. The instuction would look like this:

apple_price = 0.25

The statement simply states to store the value 0.25 in the memory named apple_price. This statement is known as an assignment statement. It assigns a value to the memory named apple_price.

The PRINT Instruction

The PRINT instruction can be used to display a value on the monitor. You can use the print instruction to display words, phrases and values.

Here is an instruction that displays the price of an apple.
print apple_price

Different languages will have different rules for typing the PRINT instruction. Some languages demand a set of parenthesis around the value to be printed.

print (apple_price)

You could also use the print statement to print a phrase. The instruction

print "Hello world!"

will display the message Hello world! on the monitor.

The IF Instruction

The IF instuction tells the computer when a specific action should be performed. For example, we want the computer to print the price of an apple if the price was less than one dollar:

If apple_price is less then 1.00, print apple_price.

The way to type less than is different for different languages.

The ELSE statement

The ELSE statement is part of the IF statement.
For example:

if apple-price is less than a quarter, then buy apples, else don't buy apples

The INPUT Instruction

The INPUT instruction tells the computer to read a value from a particular input. For purposes of this article, that input will be the keyboard. Not all programming languages name this instruction INPUT. The input instruction defines where it wants the input to be stored. For example

apple_price = input

tells the computer to input a value from the keyboard and store it in the memory named apple_price.

The WHILE Instruction

The while instruction commands the computer to keep doing something as long as specified condition exists. Here is a real life example of the WHILE instruction:

while tornado is near, stay in cellar

The FOR Instruction

The FOR instruction is used to repeat a something a specific number of times. The FOR instruction uses a counter to count the number of times the action is performed. Suppose we wanted to print apple_price five times. We would create a new memory name index to use as a counter.
For example

For index = 0 to 4, print apple_price

This instruction will set the value of index to 0 and prints the price of an apple, then it sets the value of index to 1 and prints the price of an apple. It increments the value of index and prints the price of an apple again. When the value of index is greater than 4, it stops printing the price of an apple. Hence, the price of an apple is printed five times: once for each value of index between 0 and 4.

Math
Math statements are also allowed in all programming languages. For example;

number_of_apples = 5
number_of_oranges = 3
total_number_of_fruit = number_of_apples + number_of_oranges

The memory named total will contain the sum of 5 and 3. Note that in this example, we wrote a short program containing three instructions. The first instruction sets the number_of_apples to 5. The second instruction sets the number_of_oranges to 3. The third instruction adds the number_of apples and the number_of_oranges to obtain the total_number_of_fruit. If we added an instruction to print the total_number_of_fruit, our program would look like this:

number_of_apples = 5
number_of_oranges = 3
total_number_of_fruit = number_of_apples + number_of_oranges
print total_number_of_fruit

References:

I have a Bachelor of Science degree in Electrical Engineering and I worked as an Embedded Systems Software Engineer. I designed and modified programs in several assembly languages and two high level languages.