Thursday, May 12, 2011

Translating PDL – Program Design Language into QBASIC Code


In computer programming:

QBasic is a simple programming language used mainly for teaching beginning programming students.  Many of the commands are basic English terms, making the language simple and easy to understand for a beginner.  Program Design Language or PDL is similar in that it shares a common language (English).  Although the two are alike, they are not the same.  You cannot write a program using Program Design Language and enter it into a QBasic compiler and expect your program to work.  QBasic understands some English language commands but can’t comprehend full sentences in English.  Furthermore, QBasic needs some syntax common to the QuickBasic language in order to understand commands.

In order for a QBasic compiler to understand what you have written in Program Design Language, you must translate the PDL into QBasic by inserting its syntax and removing unnecessary words and phrases.  This is fairly easy to do because the languages are very similar.  Translating Program Design Language into other programming languages may pose a slightly more difficult task depending on your familiarity with the programming language you are translating it into.  With QBasic it is quite simple because of the common English words that QBasic uses as commands.  All that you need to translate is a knowledge of the English language, knowledge of QBasic programming language, and a program written in Program Design Language.  Much of what is written in Program Design Language will most likely have very similar if not the exact terms as what your result in QBasic will use as commands.

In the real world:

The translation of Program Design Language into QBasic code is similar to translating two different dialects of the same language.  Two people from different regions of the same country may speak the same language but their dialect may be different.  Although they speak the same language, pronunciation of certain words and the slang terms they use may differ.  Usually if you understand the language you can make out what someone with a different dialect is saying although it might take you a little longer to comprehend.

In English there are many different ways of saying the same thing.  When speaking to someone that is new to the language they may not understand a phrase you say that to you may be common or easily understood.  Translating Program Design Language to QBasic is like when speaking in plain English to another person who speaks English, but they don’t understand what you are saying.  You have to rephrase your sentence in order for them to understand you.  Usually when one does this they try to rephrase their sentence into the simplest form in order to make it easy for the other person to understand.  You omit unnecessary words, or words that are slang, and change words into a simpler form.   

This is much like the translation of PLD into QBasic because the commands in QBasic are short and concise.  But in the long run you are using commands that are borrowed from the same language that Program Design Language and QBasic both use (English).

Solving Simple Problems Using Algorithms and a Program Design Language



In computer programming:

When a computer programmer gets an idea for a program they would like to develop, the best way to begin writing the program is to get their ideas onto paper.  This is especially true if the program is complex and will require a group of individuals to write the code necessary for the program’s development.

Simple tools that programmers use to see their idea materialize are flowcharts, psuedocode, and Program Design Language.  Flowcharts are types of diagrams that represent an algorithm or process.  They show a step by step solution to a problem with each step in different shaped boxes and each box connected by arrows to show the direction of flow or control.  The different shapes used in flow charts depend on what type of action is happening.  A rectangle usually denotes a processing step or activity while a diamond shape usually denotes a decision.  Flowcharts help a programmer visualize the steps their program needs before any code is written, and in turn makes the code writing process easier.

Psuedocode is a description of an algorithm that uses the structural conventions of a programming language but is intended for human reading instead of machine reading.  Psuedocode makes code easier for humans to understand than a conventional programming language code.  It describes the key principals of an algorithm.  There is no standard syntax for psuedocode as it can’t be compiled.  Psuedocode acts as a program building tool, used between conceptualization and writing code.

Program design language is similar to pseudocode in the fact that it written in a human language but unlike psuedocode it does not contain any terms that would suggest the use of any particular programming language. 

All of these are devices used to create stronger code.  They are all used between having the concept of a program in the programmer’s head and the actual writing of code.  They help a programmer visualize what is needed to create a program and to create a strong structure before code is written.

In the real world:

Psuedocode, Flowcharts, and Program Design Language, are all tools to help a programmer visualize a program before any code is written.  A real world device that is very similar is storyboarding.  Storyboards are a series of illustrations that are displayed in sequence for the purpose of visualizing a movie, television episode, commercial, or animation.  It is similar to a comic book and is made before the film, commercial, or animation is done.  It conceptualizes the project for the director or cinematographer and provides a visualization making it easier to find potential problems before they occur.

Just as psuedocode provides a layout for the code that needs to be written, a storyboard provides a visual layout of events as they are to be seen through the camera’s lens.  Often storyboards include arrows or instructions that indicate movement.  Although it isn’t a direct relation it is somewhat similar to the use of arrows in flowcharts.

Not only is storyboarding used to foresee problems that might develop when shooting the film, commercial, etc., it is used to relate ideas of how the project will be developed to other people working on it.  This is very similar to how the programming tools described above are used when working on a big program in a project with many programmers working on it.

The key similarity between storyboarding and the programming tools described above is that it is done before actually making the project being worked on.  Both are tools to weed out any potential problems before the actual creation begins.

Tuesday, May 10, 2011

Elementary Program Design Structure Model



In computer programming:

When beginning to design a program you must identify the input stream, output stream and processing center.  The input stream is every logical process that reads and edits the input to your program.  The output stream is all of the logical processes that edit and write the output of your program.  The processing center is all of the logical processes that turn the inputs into outputs.  From there you would create the top level module of your structure chart.  This top level module usually controls and/or coordinates activities but does little if any processing itself.  It would ideally receive the input from the input stream and passes it to the processing center as well as receive the output from the processing center.

From there you would create all lower level modules.  These modules should process all input data and create an output to be sent back to the level above it.  From there you can refine the structure chart of your program so all modules are simple and efficient.  If a module is not efficient enough, break it down into more efficient modules that are easier to work with. 

You must then create data access and error handling modules.  These are created to read and write any data needed and to explain what error has occurred if any do occur.  You should then evaluate the quality of design you have created using the design principals that apply to structured design.  Your goal should be to decrease coupling and increase cohesion.

In the real world:

This process could relate to many things where planning is necessary to complete your goal and once completed refinement is needed for the future.  I think it is somewhat similar to the process of preparing for a football game.  The setup would consist of watching film on your opponent and constructing a game plan on the best way to defeat your opponent.  Knowing how to attack the problems of design is like knowing what defense is best to stop the style of offence your opponent uses.

The process would be practicing your game plan and getting better at your execution.  The more you practice the more you understand how your game plan will work in different situations.  You can also see your planning coming into being.  Finally you get to game day and you implement your game plan and see how well all of the planning you did works in the situation you planned for.  Hopefully it pays off.

Whether you win or lose the game, afterwards you talk about what happened.  You watch film of the game and see what worked and didn’t work so well.  You talk about what you could have done better and how you could have performed better if you did things differently.  Hopefully this will help you play better next week.  Fortunately in programming you can go back and make those changes that need to be made.  Then you can “watch game film” again and make any changes needed repeatedly until your program is perfect.

Program Hierarchy – Tracing Design Output to its Source



In computer programming:

Hierarchy is the arrangement of items where the items are given value in relation to each other.  All the items are either above, below, or at the same level as one another.  Computer programs with a hierarchical structure are organized into ranks where each item is subordinate to the item above it.  In a hierarchal structure there is one top level and a series of lower levels under it.  Hierarchy allows a programmer to build more and more complicated structures one on top of the other.

Hierarchy charts show how each item or task relates to each other.  They also show how the program manipulates input data.  Algorithms are used to determine a step by step process in which the input data is manipulated.  Algorithms are a list of instructions for the computer to execute, manipulating the input data to produce an output.  Once all steps in the algorithm are executed and an output is produced, the algorithm is terminated.

The input data to the algorithm can be a single input or multiple inputs depending on how the program and algorithm is written.  To make things easier to understand, a chart can be constructed explaining how the hierarchy structure is constructed and which algorithms will be used depending on the input data it receives.

Program hierarchy charts are organized much like a structure chart.  There are many levels, some higher than others and some below others.  Similar to when one constructs a structure chart, branching is a common practice when constructing program hierarchy charts.


In the real world:

Hierarchy exists in almost every facet of the real world.  Hierarchy is a structure that imposes a value on objects usually linking more valuable, bigger, or more powerful objects to lesser objects below them. 

In government, a hierarchal structure is prominent.  At the top sits the president, below him is the vice president, below him is the speaker of the house, etc.  In school systems, the superintendant is at the top, with the school board below him, below them are the schools principals, followed by vice principals, and teachers. 

Even in something as big as our universe there is hierarchy.  In relation to where we reside (the planet Earth), the top of our hierarchy is the observable universe, below that are local super clusters, in which the Virgo super cluster resides, inside that is the local galactic group, in which is our milky way galaxy, inside the milky way is our solar interstellar neighborhood, which is where our solar system resides, where Earth is the third planet from our sun.

Even simple file structure in a computer has a hierarchal structure.  Each hard drive that contains any data has a file structure system.  When you open your main hard drive (C Drive) inside are folders (Program Files, System Files, Applications, etc.), inside those folders are other folders and/or files.  In this case the C Drive would be at the top of the hierarchy with every file in the drive below it.  The hierarchy branches out as files are created and stored.

Systems and Program Mapping Tools



 In computer programming:

Systems and Program Mapping Tools are ways to relay the inner workings of a program or system by means of a chart, diagram, or illustration so it can be better understood and/or planned.  These tools, which I will be discussing in this blog, are: system flowcharts, structure charts, and detail program logic.

System flowcharts use a diagram to explain how a system works.  They show all inputs and outputs of each module within a program as well as the processes in which data is manipulated by modules and how each module is connected.  System flowcharts are nontechnical, easy to understand, visual representations of a system that even a novice programmer can grasp.

Structure charts are charts that map out the design of a program.  They contain all modules of a program arranged in a tree like structure.  Each module is contained in a box labeled by the module’s name.  The tree structure represents the relationship between each module.  Structure charts are constructed during the design process and commonly referred to during development.  It is used as a master “blueprint” of a program.

Detail Program Logic
 is a chart showing the flow of logic throughout the program’s modules along with branching logic and where these branches go to and from in the program.  Detailed program logic helps explain the implementation of logic on different variables within the program.  It also shows how logic would flow based on different conditions within the program.

These three tools help aid a programmer in the design, development, and problem solving during the process of designing a program.

In the real world:

Diagrams are used for planning many different things in the real world.  When a businessman is trying to start a business and is looking for investors, they will draw up a number of diagrams to explain what the business is about, how the business will work, and how the business will turn a profit.  Using diagrams in a business proposal has the same goal as in computer programming, to simplify the message of what is going on and what the goal is.

Another real world example is when architects draft blueprints of houses, business structures, bridges, skyscrapers, etc.  When architects create blueprints, they work on many different levels to describe how the building will be constructed.  Blueprints explain what the exterior will look like as well as the interior workings of the building including: pluming, electrical, support structures, insulation, etc.

A family tree is a good example visually of how a structure chart is composed.  Like a structure chart, a family tree uses branching, resembles a tree like structure, and represents the relationships between each person.  Just as a structure chart represents the structure of a computer program and the relationships between modules of that program, a family tree represents the structure of a family and the relationships between people in the family.

Another great example of a diagram outside of computer programming that is similar to the diagrams used as systems and program mapping tools are wiring schematic diagrams.  Wiring schematic diagrams are created for all electronic components and describe how the flow of electricity is used in the electronic device.  It shows all of its components, how much power is flowing through the circuits, etc.

Cohesion and Coupling Concept



 In computer programming:

Coupling and Cohesion are two contrasting terms in computer programming.  Coupling is the degree in which each module inside of a larger program relies on each of the other modules inside the same program.  Cohesion relates to the degree in which each module is independent and how similar its functions are.  Low coupling often correlates with high cohesion, and high coupling often correlates with low cohesion.  Low coupling is a goal of a programmer because low coupling is a sign of a well-structured system with good design.  When a program has high coupling, it is more difficult to make any changes to individual modules.  The more modules rely on each other, the harder it is to go in and make changes to one module without affecting the rest of the modules.  Utilizing the top-down design method would be pointless if programmers did not strive for low coupling in their programs.  When a program has high cohesion, code readability is increased, complexity is kept manageable, and the ability and likelihood of reusing code is greatly increased. 

There are many types of coupling and cohesion and they all have different levels of desirability.  The most desirable types of coupling are data coupling, message coupling or no coupling at all because they have the lowest level of coupling.  The most desirable types of cohesion are communicational cohesion, sequential cohesion, and functional cohesion because they have the highest level of cohesion.  Coupling also takes place between different levels of modules.  Subclass coupling is the description of the relationship between a parent module and its child module, where the child is connected to the parent but the parent is not connected to the child.

In the real world:

Just like top-down design, cohesion and coupling can be related to many things in the real world.  I will compare the concepts of coupling and cohesion to running a restaurant and how each entity interacts with each other.  To keep it simple, instead of talking about every person that works at said restaurant, I will just be discussing groups of employees such as servers, bussers, cooks, chefs, and managers.  Just as in programming, a restaurant desires an employee that can do his job on his own (low coupling or high cohesion), the restaurant runs well when employees can do their job without constantly needing help from others.  Although the ideal employee may be self sufficient, there are times when interaction between employees is necessary.  Examples of this could be when a server asks a busser to help refill waters, or when a server orders his table’s food with the kitchen, or how a chef times the cooking of entrees on the grill with the grill cook and the sides with the line cook.  All of these would be examples of coupling in the restaurant business.  Just as there are different levels of coupling and cohesion in programming, the same applies to a restaurant and its employees.  The examples I just gave would rank from low coupling first to high coupling last.  The manager couples with all other employees, so the manager’s level of coupling is high because of all the different employees that they interact with and they many different ways that they interact.

Top-Down Design – Unitizing a Problem into Modules



In computer programming:

Top-Down design is a strategy of designing computer software.  Top-Down’s approach is to focus on planning and complete understanding of a system before code is written.  Using this process, systems are divided into smaller sub-systems, which can then be divided into sub-systems of themselves, and so on.  This is done repeatedly until the entire program is reduced to its base elements. 

Top-Down design started being used as an interpretation of a process called Step-wise refinement.  Step-wise refinement is a similar process that connects objects to processes in a linear fashion.  In the Top-Down approach, design can use step-wise refinement but it can also branch out.  In other words, a single module could have multiple sub-systems when using the Top Down approach. 

Both Process and Control Modules are used in the Top Down approach to help interaction between different modules.  A Control Module contains code that enhances the functionality of the software.  It controls or sets rules on how modules interact with each other.  Process Modules perform calculations when modules interact with each other. 

The Top-Down design strategy aids when problem solving because a programmer can pinpoint where bugs are.  Programmers can fix bugs by re-writing code in only the modules with bugs in them, as each module is a small self-contained program.  Also if you need to go back and make modifications to a sub program, you can do so without searching through lines of code in an enormous program.  Top-Down design can take more time in the developmental stage, but overall, using the top-down method can save time.  Time is saved in the testing and debugging phases.

In the real world:

Top-down design can be and is used in a real world setting quite often.  When writing a research paper, one would normally start by deciding what the paper is about and a thesis.  From there the author of the research paper would normally devise an outline.  The paper’s outline is basically what top down design is.  It lays out the thesis, sub-points, and facts that back up your thesis, into a structured and organized form.  An outline is a skeletal representation of your research paper just as top-down design provides a skeletal representation of the program you’re designing. 

When running a big corporation there are many different jobs to be done.  Different duties are divided up into departments, each department has a boss, they in turn divide the work that needs to be done into different jobs, then the people in these jobs hire people underneath them and split up the work-load.  On top there is a CEO, underneath him is a few vice-presidents, underneath them are the managers, underneath them are salesmen, under them are assistants, etc.  This is a good example of branching and how the workload is split up in programs when using the top-down design strategy.

These are only two of the many things in life that the idea of Top-Down design can be applied to.  Virtually any big project can be broken down into smaller tasks, which can be broken down into even smaller tasks.  Top-down design is an intelligent way to plan anything that is large and hard to comprehend as a whole.