1 / 28

INTRODUCTION AND HISTORY TO PROGRAMMING

INTRODUCTION AND HISTORY TO PROGRAMMING. Introduction. “The best way to learn programming is to type in code, make typos, fix your typos, and become physically familiar with the patterns of the language.“

Download Presentation

INTRODUCTION AND HISTORY TO PROGRAMMING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTRODUCTION AND HISTORY TO PROGRAMMING

  2. Introduction • “The best way to learn programming is to type in code, make typos, fix your typos, and become physically familiar with the patterns of the language.“ • “…programming in general much more pleasant if you know how to touch-type. Touch-typing, besides being much faster enables you to look at your screen and book instead of at the keyboard.” • “The life of a programmer is mostly a never-ending struggle. Solving problems in an always-changing technical landscape means that programmers are always learning new things.” Aaron Hillegass in Objective-C Programming

  3. History of Programming

  4. EVOLUTION OF PROGRAMMING

  5. Assembly Code • Very lowest-level programming language • Programmer describes every step that the CPU (the computer’s brain) must take • Assembler takes this code and transforms it into machine code • Code is tediously long-winded and CPU-dependent (must be rewritten if used on different type of computer)

  6. High-Level Languages • Developed to make code that could be easily moved from one type of computer to another • Express instructions in a general way • Program (called a compiler) would transform that code into highly-optimized, CPU-specific machine code

  7. C Language • The C language was invented at Bell Labs by Dennis Ritchie in 1972 to allow the writing of the UNIX operating system, then developed by Ken Thompson and Dennis Ritchie.

  8. What is C? • Called a compiled language—must run it through a C compiler to turn your program into an executable that the computer can run • Commercial compilers cost hundreds of dollars but there are free compilers available on the Web

  9. Objective-C Programming Language • Cross-platform language • Based on C Language but adds support for object-oriented programming

  10. Objective-Oriented Programming • Introduced when programs began to get very large and the structure of the code began to get in the way • Allows programmers to wrap whole sections of their code into easily handled, self-contained objects • Secret behind object-oriented programming: divide and conquer

  11. Program Basics Using C and Objective-C

  12. What Happens When You Run a Program? • File is copied from the file system into memory (RAM) • Instructions in that file are executed by computer • Instructions are hard to make out to humans • Humans write computer programs in a programming language

  13. Code and Comments • Two kinds of information in a program: code and comments • Code is the set of instructions that tell the computer to do something • Comments are ignored by the computer, but used by programmer to document code that is written • Designated by // at the beginning of line of code to end of that line • Designated by /* and */ to mark beginning and end of comment

  14. Main( ) • A function is a list of instructions for the computer to execute, and every function has a name • C or Objective-C programs must have one special function called Main—called when a program first starts • Main( ) is the point where execution begins when the program is running • Following the “main” program name is a couple of parentheses which indicate to the compiler that this is a function • General practice is to place main as the first function main ( )      {      }

  15. Two Curly Brackets • Statements defining the function are enclosed in a pair of braces { } called braces • Indicates the beginning and the end of a block of code • Each expression statement must end with a semicolon • Used to specify the limits of the program itself main ( )      {      }

  16. Library • A package of code that someone else has written to make your life easier • Standard I/O library • Read input from the keyboard called standard in • Write output to the screen called standard out #include <stdio.h> int main( ) { printf("This is output from my first program!\n"); return 0; }

  17. “printf” Statement • Allows you to send output to standard out (example the screen) • Portion in quotes is called the format string • Format string can contain string literals, symbols and operators as placeholders for variables • /n is symbols for carriage return • You can print all of the normal C types with printf by using different placeholders: • int (integer values) uses %d • float (floating point values) uses %f • char (single character values) uses %c • character strings (arrays of characters, discussed later) use %s #include <stdio.h> int main() { printf("This is output from my first program!\n"); return 0; }

  18. Return 0 • Causes the function to return an error code of 0 (means there were no errors) • When program ends, Objective-C will expect some indication of whether the function succeeded. #include <stdio.h> int main() { printf("This is output from my first program!\n"); return 0; }

  19. Variables • Used when you want your program to remember a value • Has a name and a type • Several standard types for variables • int—integer (whole number) • float—floating point values • char—single character values (such as “m” or “Z”) int amount = 1000000; type name value

  20. Scanf • The scanf function allows you to accept input from standard in, which for us is generally the keyboard • The simplest application of scanf looks like this:scanf("%d", &b); • You MUST put & in front of the variable used in scanf. • The scanf function uses the same placeholders as printf: • int uses %d • float uses %f • char uses %c • character strings (discussed later) use %s

  21. Example of Program #include <stdio.h> int main() { int a, b, c; a = 5; b = 7; c = a + b; printf("%d + %d = %d\n", a, b, c); return 0; } • Here is an explanation of the different lines in this program: • The line int a, b, c; declares three integer variables named a, b and c. Integer variables hold whole numbers. • The next line initializes the variable named a to the value 5. • The next line sets b to 7. • The next line adds a and b and "assigns" the result to c. The computer adds the value in a (5) to the value in b (7) to form the result 12, and then places that new value (12) into the variable c. The variable c is assigned the value 12. For this reason, the = in this line is called "the assignment operator." • The printf statement then prints the line "5 + 7 = 12." The %d placeholders in the printf statement act as placeholders for values. There are three %d placeholders, and at the end of the printf line there are the three variable names: a, b and c. C matches up the first %d with a and substitutes 5 there. It matches the second %d with b and substitutes 7. It matches the third %d with c and substitutes 12. Then it prints the completed line to the screen: 5 + 7 = 12. The +, the = and the spacing are a part of the format line and get embedded automatically between the %d operators as specified by the programmer.

  22. C ERRORS TO AVOID • Using the wrong character case - Case matters in C, so you cannot type Printf or PRINTF. It must be printf. • Forgetting to use the & in scanf • Too many or too few parameters following the format statement in printf or scanf • Forgetting to declare a variable name before using it

  23. Objective-C Programming • Based upon the concept of code representing real-life objects • Objects range from strings, to labels, to even people • Objects are members of classes • A single object, or representation of a class, is called an instance of that class • Each instance of a class has properties, things that define and characterize it • Each instance has methods, or things it can do

  24. Real-Word Example

  25. Class Hierarchy and Inheritance • Class hierarchy is the notion that a class can derive its properties and methods from its parent, or superclass, while being able to implement new properties and methods • A class’ inheritance pattern can be linear, or it can branch out infinitely.

  26. Linear and Branching Inheritance

  27. Resources • OBJECTIVE-C PROGRAMMING The Big Nerd Ranch Guide, by Aaron Hillegass • OBJECTIVE-C Visual Quickstart Guide, by Steven Holzner • http://www.cprogrammingexpert.com/C/introduction_to_c_programming_language.aspx • http://visual.ly/history-programming-languages • http://visual.ly/evolution-programming • http://computer.howstuffworks.com/c1.htm

More Related