Tuesday, October 19, 2010

Project 11 - Problems Solving Techniques (part 4)

http://jtf.acm.org/images/ProgramHierarchy.gif
The hierarchy method is simply demonstrated by the diagram on the right. Every component is dependent on one above it, with the exception of the highest component. Designing programs in this manner makes them easier to read, modify and extend. This style of planning is very common in engineering of all types, though one good example is the file systems provided by operating systems. File systems have a top-level (or root), and underneath that root are directories (like Program Files or Documents and Settings) and underneath those are more sub-directories. Properly defined levels in a hierarchy structure allow you to work with one level without necessarily knowing about any other level. Each level is a defined abstraction of some idea, concept or classification. With the abstraction and hierarchy a programmer doesn't need to know what any command does or what it is documented to do, just that it does it. This allows the programmer to build more and more complicated structures, one on top of the other.

For instance: you can make a program to draw a street, which is built off of a drawHouse class, which is built off of drawFront, drawRoof, drawDoor, and drawWindow classes. The only thing you need to know to modify the program is what the inputs to drawHouse are, you don't really need to know how the other classes underneath it function, as long as you know how to use them.

To use this goal in real life, you need to start out with some kind of ultimate goal. Once you have that, move down and figure out all the parts you would need to accomplish that goal. From here, you build down from whatever your goal is to smaller bits and parts and divide that up between people so they can each work on those parts and the work is a lot easier on each person than it would be making everything yourself.

This would be a good way to plan things well in advance due to it's capability for additions and modularity. Planning a conference well out in advance, for instance, some new things may come up that you want to implement, but the basic idea would remain the same and you could add or remove as needed to achieve making the best possible conference. Say you had a speaker scheduled to speak on a certain topic, and they had to cancel. If you've laid out what you wanted, you can look back at this and take that particular talk out and see what you could replace it with as it pertains to other things. Like, say the talk was about courage, you could replace it with someone talking about integrity (assuming you didn't already have said talk, in which case you would know because you have everything laid out). If you define each part of what you want to do well, you can also split up the planning work between several people so that they can all take a part.

Project 11 - Problems Solving Techniques (part 3)

A common technique when working out a solution to a problem is to use systems and program mapping tools. These are visual representations of the problem and how to solve it. Planning out the program in this manner allows for relationships and functionality between parts of the problem and solution to be shown early on, so the programmer will know how things interrelate, which is crucial to know for larger programs involving several thousands of lines of code. There are a few different ways in which you can map out a problem. One way is to map out how the process or system flows. Using this method, there is a starting point, and from there you follow lines in a step-by-step manner through to the end of the program. A structure chart shows how each component relates. It looks similar to a systems flow chart, however, it really is more of a hierarchical representation of the problem. Program logic models detail out the logic behind the program. This is also a visual schematic, and is used to convey the process of logic inputs, factors, processes and outcomes. These are best used to manipulate the program to see how it will function under different conditions, which is helpful to improve the overall design of a complex program. Mapping out the program beforehand is good to convince someone that you have a good idea for a programmed solution to their problem. It is also well used to get a team working on the same project all on the same page as to how this program should run.

One could use a flow chart for many things outside of programming. Most commonly, it is used as a troubleshooting guide, the starting point is what the problem is and usually follows a methodology of trying one solution, than depending on what result you got, moving on to either one of two continuations. Usually one branch of is: okay it's fixed now, and the other is: try this thing next and see what happens.  This transitioning of solution to solution is good for new people trying to do basic troubleshooting, perhaps in mechanics or getting a computer to work. A good example of another use of a structure chart would be explaining the internal workings of a fairly complex machine, such as a car. Making a structure chart would be a good way to train people in showing them how each part connects and effects the others. This is a good way to troubleshoot, as sometimes the obvious problem is just a symptom of the actual problem, but you could only figure this out if you knew how that other thing may be related, as sometimes it seems to the novice to have absolutely no connection. A detail program logic model would best be used when in uncertain circumstances, such as a game of football. In this, you never perfectly know how the other team is going to play, so you need to have some ability to allow the quarterback to make decisions out on the field during the play. This way, he can compensate for different circumstances, and if the whole team knows the plan than you can all have a good idea of what the quarterback will do and therefore play well as a whole.

    Monday, October 18, 2010

    Project 11 - Problems Solving Techniques (part 2)

    Coupling and cohesion are measures of how much each program modules relies on each one of the other modules. Usually the two are contrasted, that is to say low coupling often correlates with high cohesion and vice versa.

    Coupling is how much one module is dependent on another module. If they have high coupling, that means one module modifies or relies on the internal workings of another module (e.g. accessing local data of another module), so if you were to change the way the second module processes data it would lead to changing the dependent module. Low coupling means they share little data and therefore changes in one module would not affect another module very much.

    Disadvantages of coupling:
    • A change in one module usually causes a ripple effect of changes in other modules
    • Assembly of modules might require more effort due to increased inter-module dependency
    • Particular modules may be difficult to test independently due to their dependence on other modules
    Cohesion is how strongly-related or focused the functionality of a single module is. If the methods that serve the given class tend to have many similarities, than the class is said to have high cohesion. In a highly-cohesive system, code readability and reuse is increased, whilst complexity is kept manageable. High cohesion would mean the parts of a module are grouped because they all contribute to a single well-defined task of the module. Low cohesion would be that they have been grouped arbitrarily, and that the only relationship between the parts is that they have been grouped together.

    Coupling is comparable to playing in a team sport where formation is important, such as American football. Every player needs to be in a certain position for a play to work out, but if you change one player's position, usually many players also change around to match him so you still have a unity in your formation and play. This same thing works with other sports as well, in baseball everyone needs to be in their position to cover all the areas the ball could be hit to and take it back into the center to achieve the out, and everyone has to turn based on who has the ball and where they're throwing it to in order to achieve the common goal of outs so they can take their turn up at bat.

    Cohesion would be like a relay race with different parts, like part one the competitors skateboard, part two they roller blade and part three they bike. Each member of the team is would be specialized for the section they'd be racing in, and have very little action with each other, just clapping hands or something to pass off lead. The only thing they share in common is being grouped together as land vehicle racers, because they all race on land with some mode of transportation. All fairly similar, but slightly different depending on the specific part. Low cohesion would be like a swimmer, a runner and a biker, they share very little in common, but have been semi-arbitrarily grouped together as a "race team".

    Tuesday, October 12, 2010

    Project 11 - Problems Solving Techniques (part 1)

    The top-down design for programming puts emphasis on planning and having a complete understanding of the system before you start to do any coding. It is particularly good for larger projects with many inter-connecting parts so that as you code you run into unexpected difficulties connecting pieces of the project together.

    When using the top-down method the programmers will write a main procedure that names all the major functions it will need. Than the team looks at the requirements for each of those functions and the process is repeated. As the coders get farther down the sub-routines will perform simple actions that can be easily and concisely coded, and once you have all the building blocks made up all the programmers need to do is work their way back up the design.

    The top-down approach:
    • Leads to a modular design
    • Modular design allows the development to be self contained
    • Illustrates clearly how lower level modules integrate
    • Work more easily spread between the programmers
    • Easy to maintain
    Two important things about top-down design:
    1. Stepwise refinement: The process of writing software where you gradually add in error checking and functionality. Often, you take the results to show the end user to see if experimenting with a the prototype changes their mind at all about the overall program specifications.
    2. Process Modules: Additional resources that are loaded into a running process (DLL's basically)
    Top-down design can be used in other aspects of your life. Just take a big idea, and brake it down into smaller parts until you have the base components of what you need. For instance, you want to plan a party, so that's the big thing. What else do you want? Decorations, food, guests could all be considered slightly smaller modules. So what decorations? Confetti? Balloons? From there you would go through all the other things asking the same kind of questions (what kind of food, which guests etc.) and see if anything could go together (matching cake colors with party color themes). Separating things out like this is also good to divide up the tasks, asking different people to go out and handle different things. Sending person A out to handle the cake, person B out to get party decorations, etc. Or, just building a good checklist of things for you to do yourself, making an otherwise large and daunting task seem simple by breaking them down into their simple base components.

    Monday, October 11, 2010

    Project 10 - Control Structures


    A. Four basic control structures and their sub-constructs

    The four basic control structures are:
    1. Conditional (if and else)
      • If statements check a condition
      • If else statements will be checked after the initial If statement
      • Else statements come last and will always be activity IF no other parts returned true.
    2. Iteration (loops)
      • While loop, continue doing an action until condition is false
      • Do-While same as while loop, only it will always perform the process once before checking the condition
      • For loop, same as a while loop, only provides specific locations to contain an initialization statement and increase statment
    3. Jump Statements
      • Break statements will leave a loop even if the condition for its end has not been fulfilled
      • Continue Statements will skip the rest of the loop in the current iteration as if the end block had been reached
      • Goto make an absolute jump to another point in the program
      • Exit terminates the currend program
    4. Selective (switch statement)
      • Check several possible constant values for an expression, similar to if and else if instructions

    B. Sequence 

    Sequence is a very basic control structure. It is simply a list of things to do.
    • Do this thing
    • Than this thing
    • Than this other thing.
    And so on. There is no decision-making, looping, or branching. It is just a series of statements, one after the other. For example:

    This would be an example of a sequence structure.

    double average = 0;
    int first = 8; 
    int second = 5;
    int third = 3;
    int fourth = 7;
    average = (first + second + third + fourth)/4;
    System.println(average);

    All it does is run through the code line by line until it reaches it's end and therefore has performed the function the programmer wanted it to. This is the simplest and least powerful control structure available and is usually used in combination with selection and loop structures.





    C. Selection (Decision, If Then/Else) - Case Statement Available in Some Language

    Selection is exactly what it sounds like, it selects something based on some condition.

    This is an example of the selection structure

    Selection statements come in if/then/else format. For instance:

    bool cake = false;

    if(cake){
       eatCake();}
     else{
       sleep();}

    The selection control structure takes the statement and decides wether it is true or false (Boolean logic comes into play here and if it's numbers you need <, >, or = for comparison) than depending on whether this statement is true or false it takes a certain action. In this case, since cake is always false the program will never run the method eatCake() and will always go to the else statement and run the method sleep().

    D. Loop (looping, iteration) - For Statement Available in Some Language

    Loop statements will continue to perform some function until some parameter is met.

    Example:

    int piecesOfCake = 10;

    while(piecesOfCake > 0){
        eatPiece();
        piecesOfCake--;}

    sleep();

    In this example the paramater is checking if there are any pieces of cake left, if there are it eats a piece then goes to check if there is another one again and so on until there is no longer cake, then it exits the loop and goes to sleep. Some languages also use do-while (execute statement, than check paramater) and for (so long as this condition is true, usually a counter of some sort) loops.

    E. Unconditional Branch (Goto)

    Goto statements are a one-way trip to another section of the code. Most languages use label to identify the place where the Goto statement jumps to, though some languages use line numbers. There has been a lot of criticism about Goto statements as bad programming habit, favoring instead the structured programming paradigm, though it has been argued that sensible programmers could use it to improve speed, size and code clearness. Whichever side one tends to agree with, it seems both can agree that newer programmers should stay away from the Goto statement until they are more familiar with the potential advantages and disadvantages involved.

    Friday, October 8, 2010

    Project 8 - Source Code Verses Executable Code

    Many people have some idea of what source code and executable code are, however, most only know the laymen terms for it. The differences between these types are not particularly well defined.

    In laymen's terms, source code is what is written by the programmer, which is human-readable, cannot immediately be executed by the machine, and usually has meaningful variable names and comments intended only for humans. Executable code, (or object code) is not human readable, must be compiled by a compiler, and is a sequence of bytes that give specific instruction to the computer.

    When you delve deeper, however, you find that executable code is readable by humans, it's just more difficult than high level languages such as Java or C, and that to be executed a program doesn't necessarily need to be compiled. An interpreter can be used  instead to communicate to the machine the source code as it is.

    When two people who speak different languages want to talk to each other, they need a third person, called an interpreter to speak in between them who knows both languages. Let's say persons A and B speak languages T and U respectively only, and person C speaks both T and U. As person A gives instructions to person B, person C relays them as they are spoken. This is like what an interpreter for computers does. In this example person A would be the programmer, person B would be the machine, person C would be the code interpreter, language T would be the source code and language U would be the executable code. A compiler on the other hand, would be more like person A writes a letter to person B in language T and gives it to person C. Person C than, takes that letter (source) and translates it into language U and makes sure everything is correct before than handing the now translated (compiled) letter to person B. Person B than follows the instructions (executes) laid out in the letter.

    In this example, person A is the programmer, person B is the computer and person C is the compiler or interpreter. So what does assembly language have to do with anything? Well assembly language is as close as you can get to binary language without actually using binary. It's very short commands (usually 3-5 letters long each) which directly translate into the machine language. Because of this it's very specific to each machine, like different dialects between tribes. While the languages are very similar, it must be spoken slightly differently depending on whom (which processor architecture) you're speaking to. Assembly language reduces the translation needed for the programmer to talk to the computer. So, person A would be able to say his bit, and person C would be able to take it to person B with little changes, sayings that exist in language T would translate effectively over to language U (If I said "he's pulling you across the table" you would look at me weird, but if I told a German-speaker this it would come across the same as "he's got you wrapped around his little finger" would to you).

    Saturday, October 2, 2010

    Project 9 - Data structures and Data Representation

    List of definitions as asked for in project 9. Sources will be numbered and placed at bottom.

    Global Variable - A variable that can be changed anywhere in the program. (1, 2, 3)

    Local Variable -A variable that is only available within some smaller scope or function (1, 2, 3)

    Elementary Data Types
    • Character - Any given symbol or letter, (a % Q ; could all be characters) (1, 3, 4)
    • String - A set of characters, usually a word but not necessarily, (America, $!@sadc, QWERTY could all be considered strings) (1, 3, 4)
    • Integer - Any whole number, so no fractions or decimals (1 16 72 would be integers, 1/2 5.7 .66 would not) (1, 4, 5)
    • Floating - Similar to an integer, only it may contain parts (such as 1/2, 5.7, or .66) (1, 4, 5)
    • Boolean - A true or false variable, often used with operands such as AND, OR, OF THEN, EXCEPT, and NOT (1, 4, 5)
    Data Identifier (name) - The classification of an element (1, 6, 7)

    Its Data Type -Classification of a particular type of information, such as int char or string (1, 7, 8)

    Its Memory Address -Place on the hard-disk that is referenced for where the data resides. (1, 9, 10)

    A Variable -Some symbol or name that stands for some value and is subject to change. (1, 8, 10)

    Literal -A value that has been written exactly as it is meant to be interpreted, and is not subject to change (1, 10, 4)

    Constant -A name or value that cannot be changed (1, 10, 4)

    Number Base Systems

    BASE 2 - Number Base System using 2 integers, 1 and 0m this is the language computers use, it's an on/off system (1, 4, 11)

    BASE 10 -Number Base System using 10 integers, 0-9 this is the one most people are familiar with (1, 4, 11)

    BASE 16 -Number Base System using 16 integers, 0-9 and A-F, used for memory location identifiers (1, 4, 11)

    Floating Point - The system used for representing numbers too large or small to be represented by integers, the number that can be represented is: Significant Digits * Base^exponent  (1, 12, 13)

    Decimal Data Representation -Data representation is the manner in which data (ints, strings, chars, etc.) are stored on the computer. (1, 18, 19)

    Relative Addressing- An addressing scheme which allows for a domain to be taken from one server and placed to another without changing the links, as the links are relative to your current position in the domain (10, 16, 17)

    Data Types and Data Abstraction
    • File - Block of arbitrary information (1, 4, 10)
    • Record - A group of fields of a single field treated as a unit. (1, 4, 10)
    • Array - A grouping or series of objects, usually in rows and columns. (1, 4, 10)
                1. Single Dimension - Just going in one direction (1 row and 1 column)
                                               Ex: [1, 0, 5, 10, 6, 6, 1, 10]
                2. Multi Dimension - Multiple rows and columns 
                                               Ex: [1, 5, 6, 7, 5
                                                      2, 7, 1, 0, 8]
      Language Statements 

      (all 1, 10, 20 for this section)

      A. Natural Language Statements/Grammar and Logic - The idea of making programming statements that uses the grammar of the human language.

      B. Artificial Language Statements/Syntax and Semantics - An artificial language designed to express the accounts that can be carried out by the device. Can be used for to create programs that control the behavior of the device, to express algorithms precisely, or a form of human contact

      C. Input/Output Statements - Part of the program that tells the computer how to take and use information from input devices or send that information out of an output device.

      D. Assignment Statements - Statement that sets a variable to a value

      E. Program Design Language (PDL) - Meta Language - Methodology of designing and documenting methods and procedures in programming. Written in plain language without any conditions that would indicate use of a language or library.

               1.Syntax Diagrams - Schemes such as flow charts for organizing the flow of programs.

               2.BNF - Formal way to describe the mathematical language devloped to describe the syntax of programming language.

      F. Elementary Language Statements and Structured Language Statement

               1.Assignment and Unconditional Statements - Assignment statements assign a value to something, unconditional statements allow you to direct the program to another part without an assessment of conditions.

               2.Selection and Looping Statement - Selection statements are used to determine what and when code should be executed, looping statements are used to run the same part of code a certain number of times.
       
      Expressions Components

      A.Operators, Operands and Results
      1. Unary- An operation with only one operand, (+, -. *, / etc.) (1, 4, 14)
      2. Binary- Having 2 operands (1, 4, 14)
      B. Simple Types
      1. Arithmetic -A mathematical equation (1, 4, 10)
      2. Logical - Equations regarding boolean (true/false) logic (1, 4, 10)
      3. Relational - An expression comparing 2 objects, usually returns a true/false value (such as x > y) (1, 10, 15)
      C. Result
      1. Unconditional (Not Boolean) - A result not pertaining to true/false logic (i.e. an integer or string) (1, 5, 10)
      2. Conditional (Boolean) - A result pertaining to true/false logic (1, 5, 10)
        1. True -Statement is correct
        2. False -Statement is not correct
      Sources:
      1. Wikipedia
      2. Web Developers Notes
      3. Linux-France.org
      4. Dictionary.com
      5. wordnetweb.princeton.edu
      6. europa.edu
      7. OCED glossary
      8. SQA Tester
      9. PC Computer Notes
      10. Wedopedia
      11. Tejat.net
      12. Princeton.edu 
      13. sun.com
      14. SGI
      15. Macs.hw.ac.uk 
      16. rxs-enterprises.org 
      17. wustl.edu
      18. osdata.com
      19. answers.com
      20. computerhope.com