Docstoc

Programming___

Document Sample
Programming___ Powered By Docstoc
					Programming!!!
     Spring - 2011
Q: What are paradigms?
A: 20 cents
All programming falls into one of three basic
  paradigm groups: Imperative, Declarative,
  and Logic.
 For this class we will focus on the
  Imperative Paradigm.
     Split into two movements
       • Procedural (or sometimes linear), and
       • Object-Oriented (OOP)
But what is ‘programming’?
   Program - A sequence of instructions designed
    to accomplish a specific task.
   Programming - the act (/science/art/etc.) of
    creating a program.
       Not all programs are coded.
         • Ada Lovelace designed (and implemented) many programs
           without ever writing a single line of code.
         • The coding aspect of programming is really just one step in
           a many tiered process.
Programming Process /
Workflow
   Good programmers spend ~80% of their time
    designing a program.
   The other ~20% is spent writing, testing, and
    debugging code.
   Testing - the systematic act (/science/art/etc.)
    of finding faulty / incorrect code in a computer
    program.
   Debugging - the process by which a
    programmer removes faulty / incorrect code
    from a computer program.
Quick Review
 As good programmers what should you
  spend the majority of your time doing
  when creating a new program?
 What’s the difference between software
  testing and software debugging?
 Which programming paradigms will we
  explore in this class?
Quick Review
   As good programmers what should you spend the
    majority of your time doing when creating a new
    program?
       DESIGNING the program!!!
   What’s the difference between software testing and
    software debugging?
       Testing finds bugs, debugging removes them.
       Good programmers will test their code as they go, but as
        software projects get bigger more rigorous testing is required
        (usually by an outside source).
   Which programming paradigms will we explore in
    this class?
       The Iterative Paradigm, consisting of Procedural and Object-
        Oriented Programming techniques.
Important parts of a program
(written in a coding language)
   Typically the source code for a computer
    program can be split into several parts,
    regardless of the paradigm being followed.
       Outside Resources: header files, libraries to include,
        etc.
       Global Variable Declaration: Variables to be used
        through out the entire coding project (it’s good
        practice to minimize these on larger programs).
       Code Blocks: Where your design gets realized.
Outside Resources
   The wonderful part of Computer Science is that code
    can be reused in many different projects. Code
    specifically designed for this purpose is generally called
    a library. (In Windows, these files have the .dll
    extension)
   Almost all programming languages support the
    importing of library files for use in a separate program.
    Typically this is done by typing ‘include’ or ‘import’
    followed by the name of the library or resource to be
    used.
       C/C++/Ch example:    #include <iostream>
                                     or
                             #include “iostream.h”
Global Variable Declaration
   This is where all the variables used for the
    performance of the task are declared and/or
    initialized.
       Variable - “a location in memory, referenced by an
        identifier, that contains a data value.”
         • In English: Take the algebraic expression for Pythagoras's
           Theorem: x2 + y2 = z2
             • x, y, and z are the variables.
             • In order to use them, we need to store them in memory and
               give them a name, or identifier. If you knew exactly where in
               memory you put a value you could just use that memory
               location directly (ie:0x00af1c30 <- 32 bit mem address). But
               that would be hard, and they might need to move around so a
               programming language will keep track of that for you, via a
               variables name (ie: you can just type x = 2 instead of
               0x00af1c30 = 2).
(Regular) Variable Declaration
    Declaring - The act of reserving a location in memory for a variable
     without assigning a value to that location.
       • Use choose a variable data type that fits for the use of variable in
          question. (ie if you want to use a variable to store a monetary
          value, use a double or float data type.
       • Each data type saves a different amount of memory.
    Initializing - The act of reserving a location in memory while at the
     same time setting it to some initial value.
       • Sometimes refers to just the first time a variable is assigned a
          value, but only if the variable has already been declared first!
    The global variable declaration sometimes happens before the first
     code block, but not always. It depends on the rules of the specific
     programming language you are coding in.
       • In Ch it will be just inside the first code block.

 You must always reserve the memory for a variable before assigning
   a value to it. More on this later!
Code Blocks
   Segments of code typically grouped by function.
    Usually many are required for a complete
    program, but more are used in OOP than
    Procedural Programming.
   Typically noted by starting with a { symbol and
    ending with a } symbol.
   Usually are required by the programming
    language to keep everything in order while
    compiling.
   In Ch, we will mostly be using one large code
    block, called the ‘main’ function.
 And now your first program!
   The following is the basic setup for a C/C++/Ch
    program:

The first line is a         // Heath Carroll - code example for class
comment                      #include <iostream>
The second is a link        main()
to an outside resource
                             {
The third is the start of
the ‘main’ block
And the rest is the body
of the ‘main’ code block

                             }
Live Example
   Hey Professor, how about you show the class
    how to write a simple program?
       Let’s just do a simple math equation we’ve all seen
        before…Pythagoras's Theorem
         • Remember? (x2 + y2 = z2)
       Make sure you show them all the required pieces…
       And how to take user input…

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:16
posted:8/13/2012
language:English
pages:13