Part 1 Introduction to Programming
Chapter 1 Understanding Program Logic and Programming
In this chapter, you will learn how to:
1. Define the meaning program logic and a computer program. 2. Describe the relationship between computer programming logic and computer programs. 3. Explain the process of solving a problem with program logic and a computer program. 4. Describe why program logic is modeled with pseudo code and flow charts before being transformed into a program. 5. Recognize the importance of program development methodologies like the program development process and the system development life cycle to develop computer 6. Describe the roles and responsibilities of programmers and the processes programmers use to create programs. 7. Differentiate between compilers, interpreters and virtual run-time machines in regards to building and executing programs.
Welcome to Computer Programming
I would like to officially welcome you to computer programming. I am excited that you have selected this eBookto learn how to develop your own computer programs. I will give you all the information and examples necessary to understand the basics of computer programming. I will use standardized programming techniques and tools which have long been used by programmers to create quality computer applications. I will incorporate common sense explanations with a variety of examples to make sure the theory is backed up with application of that theory.
Programming logic is the central focus in this eBookalong with how they are used by programmers to write efficient and effective computer programs. Every program should start with program logic, which is the blueprint, and end with the coding of programming language statements. The initial chapters of the eBookwill be dedicated to logic structures and specifically, structured programming. In later chapters, we will tackle more challenging programming techniques like object orientated and event driven programming.
As a programmer who has been writing programs for more than twenty years, I have always enjoyed the challenge of programming and I hope that my passion for programming will rub off on you also. For me, the next best thing to writing my own programs is helping a new programmer learn how to write their own programs. There is nothing more rewarding then to see the pride of accomplishment in a students face when they create their first computer program. Let’s get started…..
Computer Programming – Computer programming is an activity performed by a computer programmer. It always starts with a person. It includes a process of creating logic models which is converted into program language instructions that are later executed on a computer. The goal of the program is to solve a problem or perform a task. Like a recipe provides instructions for a cook, a computer program provides instructions for the computer. Program Logic – Program logic is used by programmers to model the programming language instructions carried out by the computer when the program is executed. Think of program logic as instructions you might give someone on how to make something or perform a task they have never done before. Program logic structure instructions might provide a program decision (i.e. if file does not exist, display message) or a loop through a series of repeated instructions. You might also think of your logic model as a blue print where you have mapped out the instructions but have yet to put them in a program as program language statements.
Programming Language Statements: Programming language statements are used to implement program logic by sending instructions to the operating system. is logic with a program built on program language statements. Programming Tip: Logic models are programming language independent which means logic writing concepts in the eBookcan be used across all programming languages.
Figure 1: A Computer Program and its Parts
A Disciplined Approach to Programming
When we learn about logic and programming, we will always examine WHY we are using that logic structure or programming methodology. Whenever a new topic is introduced we will stop to discuss WHY that topic best fits the situation we are trying to solve. We will follow this explanation with examples. The examples will include pseudo code, flowcharts, UML (Unified Modeling Language), PYTHON programs, illustrations and case studies. In this wiki, we will use a variety of approaches and different learning styles to provide real life solutions to real business problems. We will apply concepts to case studies and assess our progress to get feedback on in understanding how and why the topics of that chapter are important to becoming successful programmers.
There are many textbooks that teach you how to program. These textbooks cover the syntax and structure of how programs are constructed specific to a particular programming language. One of the more popular programming languages is Microsoft’s Visual Basic. In the typical introductory Visual Basic class, the student learns Visual Basic statements and keywords, how to implement programming logic and structures and finally, how to use the Visual Basic development environment to build and test his program. This approach to learning programming stresses how to create Visual Basic programs but not effective programming logic design. There is a weakness in learning programming with this approach. The emphasis is not on WHY it needs to work a certain way but instead what it will look like. As you’ll see in this wiki, the direction will in formulating efficient, flexible, reusable, high quality programs that follow accepted programming standards.
Since the logic is used to design the solution, you must also understand that construction of logic are key to good programming. Let me illustrate with an example. I think most of us would admit you probably don’t have to be an architect to design a house. After all, most of us have had some experience living in a house. Through this experience, we could design what you would find in your typical house (rooms, doors, windows, roof, etc.). I also think most of us would be able to assemble something that looked like a house if given the appropriate building supplies and tools. We could build a house that had at peaked roof, had some windows, had a front door and would have walls and ceilings that would make the house habitable. From a distance, the house might look like every other house on the street. However, would the house be structurally sound? Would the house meet the appropriate construction code regulations? If another plumber or electrician came to this house and had to make a repair, would they be able to? What this house we built meet the professional standards found in the work of professional builders, plumbers and electricians? I don’t think so. We know how to build it but not why a floor needs certain supports or why wall studs hold up the ceiling.
This same analogy holds true in first time programming classes. Many times because of time constraints and the amount of material that must be learned, entry level programming classes have to focus on the “HOW” and not the “WHY” of a programming language. “HOW” might get the assignment done and a compiled program but it does not necessarily make you a programmer. Once you know “WHY”, you can use the “HOW” to implement the solution. Once we know the “WHY” of programming logic and how to use structured and object oriented fundamentals, we will be able to build programs that follow professional standards for design, and maintainability. Knowing “WHY” we do things is what makes the practitioner a professional. In our case, knowing “WHY” is important in becoming an effective programmer.
The Process of Programming
The goal of this eBookis to teach you about programming. Programming is a process and made up of several activities. The program process starts with the modeling of logic. This is also where we will focus much of our instruction. It is often is the neglected piece of the programming processes but critical for new programmers. Once the logic is complete programming starts. A completed program must finally be tested before put into production. This eBookwas designed to provide instruction on programming for a variety of programming languages (language independent). The process of programming is the same no matter what programming language is used (i.e. Visual Basic.Net, C++, C# or Java).
Key Concept: A program is the implementation of your program logic with programming language statements. Program logic and programming come together like a pilot and his airplane. Each by themselves offers little but together, they can provide much more. In short, programming logic is your plan for solving a problem and the program is the implementation of our program logic with programming language statements.
Program Language Statements - Program language statements are English like statements that when executed in the correct sequence can instruct the computer to perform a series of tasks. There are many computer programming languages each having differences and similarities. The differences allow some programming languages to work with some computer applications better than others (i.e. the COBOL computer language has long been a favorite of business programmers.
A First Look: Understanding Programming Process
We must start our understanding of programming by dispelling a few computer myths. Many of us have grown up with a “Hollywood view” of computers. That view has presented the computer as some sort of super brain. A device that we need only ask questions of and it will return to us knowledge we don’t possess. A machine that can reason, learn or acquire intelligence on its own.
This could not be any farther from the truth. One of the difficulties in learning how to implement programming logic is the constraints the computer places on us in solving business problems. The human brain is far more complex and the brain’s ability to reason and learn far exceeds that of a computer. Computers are only as smart as the persons programming them and you must condition yourself into providing an instruction (logic) for everything a computer program needs to do. Planning or modeling program logic before we create programming statements is one way for the programmer to condition the solution into one the computer can perform. Without a logic model it is easy for the new programmer to assume the computer can perform more than it is able. We will learn more about logic structures in later chapters but first we will give you a first look.
I often use the example of making a peanut butter sandwich to illustrate the intelligence (or lack of) of the computer. Making a peanut butter sandwich is a task that any three years old could handle. Let’s see what we would have to tell the computer in the form of logic instructions to make a peanut butter sandwich. I will accomplish this by documenting the logic necessary with a programming modeling language called pseudo code to build the necessary instructions.
Pseudo Code: Pseudo code is a nonstandard English-like programming language used by programmers to model logic and instructions. Pseudo code is called a programming language even through it can not be excluded by a computer. It is designed for planning purposes only. By nonstandard, if you open five books on programming, all would have pseudo code examples but all of those examples would look somewhat different. Most computer languages have required standards that must be followed when creating programs. Pseudo code provides us with a way to concentrate on just logic structures without be constrained by the syntax rules of a particular programming language.
In Practice: Pseudo code for Creating Programming Logic - Pseudo code has long been used as a mechanism for modeling logic before the logic is implemented as source code statements in a program. We will formally introduce pseudo code later in the wiki. We use pseudo code because it is an excellent way to just concentrate on programming logic without being constrained by the rules of a specific programming language. The beauty of pseudo code is that since it is a list of English instructions, you can easily document the process steps and validate the steps with other...