1 / 66

Programming experience Let’s get a feel for everyones’ programming experience.

Programming experience Let’s get a feel for everyones’ programming experience. Query languages known Query knowledge of looping constructs Query knowledge of conditional statements Query knowledge of subroutines. A.Honey (Oct 2003). S1-1. Program categorization

bruce-weiss
Download Presentation

Programming experience Let’s get a feel for everyones’ programming experience.

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. Programming experience Let’s get a feel for everyones’ programming experience. Query languages known Query knowledge of looping constructs Query knowledge of conditional statements Query knowledge of subroutines A.Honey (Oct 2003) S1-1

  2. Program categorization There are several ways to categorize programming languages, however the one I wish to discuss is relevant to scripting, interpreting, and compiling. Can anyone explain the differences and give examples? A.Honey (Oct 2003) S1-2

  3. Scripted language A scripting language is used to coordinate and combine components that are written in some other language and cannot usually itself be used for writing those components. The programs you create are read by another program which then executes the statements you created. (Perl, Tcl/Tk, HTML, XML) A.Honey (Oct 2003) S1-3

  4. Scripted language A scripting language is used to coordinate and combine components that are written in some other language and cannot usually itself be used for writing those components. The programs you create are read by another program which then executes the statements you created. (Perl, Tcl/Tk, HTML, XML) Interpreted language An interpreter is a computer programthat executes other programs. Most interpreted languages use an intermediate representation, typically called bytecode, which is then executed by a bytecode interpreter. The interpreter would most likely be written in a compiled language. There are more-or-less two programs involved, one to convert to bytecode and one to run that bytecode. (Basic, Java, Python) A.Honey (Oct 2003) S1-4

  5. Compiled language A compiler does not execute its input program (the source code) but translates it into executable machine code (also called object code) which is output to a file for later execution. The ‘executable program’ consists of a set of CPU instructions that run directly on the processor chip and, therefore the compiler must translate the source code into instructions for a particular CPU. Hence, a program written for a Pentium PC (Intel) will not run on a Mac (PowerPC)! (C, Fortran, Cobol) An interpreter or script program may run on both. Those types of programs are what is called platform independent. Which is fastest? So how many programming languages are there? A.Honey (Oct 2003) S1-5

  6. ABC Blue Constraint ABEL C Curl Ada C++ D ADL C-sharp Database Aleph Caml Dataflow Algol 60 Cecil Declarative Algol 68 CHILL Delphi APL Clarion Directories AppleScript Clean DOS batch ASP Clipper Dylan Assembly CLU E Awk Cobol Eiffel BASIC CobolScript ElastiC Befunge Cocoa Erlang BETA Compiled Euphoria Bigwig Component Pascal Forth Bistro Concurrent Fortran A.Honey (Oct 2003) S1-6

  7. FP Interpreted ML Frontier Java Modula-2 Functional JavaScript Modula-3 Garbage Collected LabVIEW Moto Goedel Lagoona Multiparadigm Hardware Description Leda Mumps Haskell Limbo NET History Lisp Obfuscated HTML Logic-based Object-Oriented HTMLScript Logo Objective-C HyperCard Lua Obliq ICI m4 Occam Icon Markup Open source IDL MATLAB Oz Imperative Mercury Parallel Intercal Miranda Pascal Interface Miva Perl A.Honey (Oct 2003) S1-7

  8. PHP Rexx SQL Pike Rigal Squeak PL RPG T3X PL-SQL Ruby Tcl-Tk Pliant S-Lang Tempo POP-11 SAS TOM Postscript Sather TRAC PowerBuilder Scheme Turing Procedural Scripting UML Prograph Self VBA Prolog SETL VBScript Proteus SGML Verilog Prototype-based Simula VHDL Python Sisal Visual REBOL Smalltalk Visual DialogScript Reflective snobol Visual FoxPro Regular Expressions Specification Water A.Honey (Oct 2003) S1-8

  9. Wirth XML XOTcl YAFL Yorick Z The above was NOT an exhaustive list! A.Honey (Oct 2003) S1-9

  10. Lcc-win32 Why lcc-win32 rather than IC4 for these sessions? Interactive C is truly interactive requiring that your computer be connected to a robot controller. If not then it becomes very tedious to write a program, as every time you press enter an attempt is made to send the statement to the controller and if it is not there then a delay of many seconds will occur. Also the lcc-win32 has a 300+ page tutorial, which will become very useful when you start training your team members in the C programming language. I intend to devote one of the later sessions to IC4. If for some reason this does not occur then the botBall workshop in Honolulu will be sufficient. A.Honey (Oct 2003) S1-10

  11. Learning a programming language So what does one need to learn in order to become proficient in a programming language? A.Honey (Oct 2003) S1-11

  12. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. A.Honey (Oct 2003) S1-12

  13. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. A.Honey (Oct 2003) S1-13

  14. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. The acceptable punctuation. A.Honey (Oct 2003) S1-14

  15. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. The acceptable punctuation. The structure of a program. A.Honey (Oct 2003) S1-15

  16. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. The acceptable punctuation. The structure of a program. Looping constructs. A.Honey (Oct 2003) S1-16

  17. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. The acceptable punctuation. The structure of a program. Looping constructs. Conditional statements and expressions. A.Honey (Oct 2003) S1-17

  18. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. The acceptable punctuation. The structure of a program. Looping constructs. Conditional statements and expressions. How to create subroutines or there equivalent. A.Honey (Oct 2003) S1-18

  19. Learning a programming language So what does one need to learn in order to become proficient in a programming language? The Syntax which is the arrangement of words and symbols to create a working statement structure. The acceptable words of the language. The acceptable punctuation. The structure of a program. Looping constructs. Conditional statements and expressions. How to create subroutines or there equivalent. How to declare and define variables and subroutines A.Honey (Oct 2003) S1-19

  20. Learning a programming language When learning a programming language the syntax has to be correct or, either an error will be generated (especially true for a compiled language) or the program will not behave as expected and/or the program will ‘crash’! A.Honey (Oct 2003) S1-20

  21. How is a C program organized? Tutorial pdf page 13, doc page 1 A C program consists of one or more source files called modules. So why would you break a program into multiple modules? A.Honey (Oct 2003) S1-21

  22. C modules A large complex program ‘needs’ to be broken into modules. Not only does this allow a team of programmers to work more-or-less independently, on various pieces of a large program, but also it allows the program to be more readily understood and maintainable. In addition, with judicious modularization, a module may prove to be useful in another program, thereby, reducing the amount of new code that is written for each new program. Of course if multiple programmers are working on different pieces of a program then they must agree, in advance, upon the inputs and outputs (parameters) to each smaller piece of the program (functions). A.Honey (Oct 2003) S1-22

  23. C functions In C, the equivalent of a subroutine is called a function. A C program may consist of an almost unlimited number of functions. However, at least one function must exist and it must be called ‘main’. Typically, if you find that there is a set of statements that you need to use several times, in various places in your program, then you would probably create a function for that code. Or perhaps to simply make the program more easily read/understood. Or if that code maybe useful in another program. A C function is typically a small piece of code that: has zero or more parameters; has zero or more declarations; contains zero or more program statements, which accomplish a desired task; and may or may not return a result. A.Honey (Oct 2003) S1-23

  24. C function parameters For now we will defer a discussion of function parameters. Suffice it to say the function parameters allow data to be passed in to and/or out of a function, such that the statements of that function can manipulate the data. We will return to this topic when the need arises. A.Honey (Oct 2003) S1-24

  25. C function declarations Declarations are the means by which we create variables and provide their specifications to the compiler. A variable allows us to ‘tell’ the compiler information about the data we want to manipulate or examine, within the statements of the program. So what is a variable? A.Honey (Oct 2003) S1-25

  26. C function declarations Declarations are the means by which we create variables and provide their specifications to the compiler. A variable allows us to ‘tell’ the compiler information about the data we want to manipulate or examine, within the statements of the program. So what is a variable? A variable is essentially the ‘name’ of a data value that is stored in a particular memory location. It is the compiler and linker which determine the exact memory location used for a given variable. A.Honey (Oct 2003) S1-26

  27. C variables Lets backup a little. Even though you may not know how to do this yet, assume you have created and compiled a C program. Where is that program? A.Honey (Oct 2003) S1-27

  28. C variables Lets backup a little. Even though you may not know how to do this yet, assume you have created and compiled a C program. Where is that program? Right it is on a disk drive. For a compiled C program what is on the disk drive? A.Honey (Oct 2003) S1-28

  29. C variables Lets backup a little. Even though you may not know how to do this yet, assume you have created and compiled a C program. Where is that program? Right it is on a disk drive. For a compiled C program what is on the disk drive? source code, object code, and executable program! Now you ‘run’ the program. What happens to the program? A.Honey (Oct 2003) S1-29

  30. C variables Lets backup a little. Even though you may not know how to do this yet, assume you have created and compiled a C program. Where is that program? Right it is on a disk drive. For a compiled C program what is on the disk drive? source code, object code, and executable program! Now you ‘run’ the program. What happens to the program? Right it is loaded into the computer’s memory. A.Honey (Oct 2003) S1-30

  31. C variables Lets backup a little. Even though you may not know how to do this yet, assume you have created and compiled a C program. Where is that program? Right it is on a disk drive. For a compiled C program what is on the disk drive? source code, object code, and executable program! Now you ‘run’ the program. What happens to the program? Right it is loaded into the computer’s memory. So what is memory? A.Honey (Oct 2003) S1-31

  32. C variables Computer memory can be visualized as a large set of switches that can be either on or off (in actual fact they are the equivalent of microscopic transistors which do function like switches). If we think of each switch as being numbered then the numbers are analogous to the addresses of the memory locations. Each memory address refers to… A.Honey (Oct 2003) S1-32

  33. C variables Computer memory can be visualized as a large set of switches that can be either on or off (in actual fact they are the equivalent of microscopic transistors which do function like switches). If we think of each switch as being numbered then the numbers are analogous to the addresses of the memory locations. Each memory address refers to… the equivalent of how many switches? A.Honey (Oct 2003) S1-33

  34. C variables Computer memory can be visualized as a large set of switches that can be either on or off (in actual fact they are the equivalent of microscopic transistors which do function like switches). If we think of each switch as being numbered then the numbers are analogous to the addresses of the memory locations. Each memory address refers to… the equivalent of how many switches? think win32 A.Honey (Oct 2003) S1-34

  35. C variables Computer memory can be visualized as a large set of switches that can be either on or off (in actual fact they are the equivalent of microscopic transistors which do function like switches). If we think of each switch as being numbered then the numbers are analogous to the addresses of the memory locations. Each memory address refers to 32 switches as that is the data width on the current generation of IBM type PCs. So why do we care about the data width? A.Honey (Oct 2003) S1-35

  36. C variables Computer memory can be visualized as a large set of switches that can be either on or off (in actual fact they are the equivalent of microscopic transistors which do function like switches). If we think of each switch as being numbered then the numbers are analogous to the addresses of the memory locations. Each memory address refers to 32 switches as that is the data width on the current generation of IBM type PCs. So why do we care about the data width? The speed of memory is typically much slower than the processor so, if you can get more information in a single memory read or write, then your the entire system becomes more efficient. And, you can update your video card faster  A.Honey (Oct 2003) S1-36

  37. C variables As we will eventually see, a C program may contain variables of practically any type imaginable. However, there are only a few basic variable types, from which all other variables are derived. Within this session we will only address two of those basic types, namely, integer and floating-point variables. So why do we need to tell the compiler that a given variable is of a specific type? A.Honey (Oct 2003) S1-37

  38. C variables As we will eventually see, a C program may contain variables of practically any type imaginable. However, there are only a few basic variable types, from which all other variables are derived. Within this session we will only address two of those basic types, namely, integer and floating-point variables. So why do we need to tell the compiler that a given variable is of a specific type? It basically comes down to the representation of integers and float-point values in memory. They are NOT the same! The compiler MUST know the type of the variable so it correctly interprets the data, in a given memory location. A.Honey (Oct 2003) S1-38

  39. Simple C programS1_pgm1 Lets create a simple program. I assume everybody has downloaded and installed lcc-wn32. You should have an icon on your desktop for wedit If not then try start->Programs->lcc-win32 If not then open the ‘bin’ folder wherever you installed LCC and the executable should be there. A.Honey (Oct 2003) S1-39

  40. Simple C program The program you created calls the function printf but where did that function come from? You didn’t create it. A.Honey (Oct 2003) S1-40

  41. Simple C program The program you created calls the function printf but where did that function come from? You didn’t create it. There are hundreds of functions in C that exist in either other source files or as object modules (the output from the compiler). A programmer may use those functions. It is the job of the linker to find those functions and include them in the compiled program. So how does the linker know which functions to include? A.Honey (Oct 2003) S1-41

  42. Simple C program The program you created calls the function printf but where did that function come from? You didn’t create it. There are hundreds of functions in C that exist in either other source files or as object modules (the output from the compiler). A programmer may use those functions. It is the job of the linker to find those functions and include them in the compiled program. So how does the linker know which functions to include? That word ‘include’ was the clue  as there was a preprocessor statement ‘#include <stdio.h>’ at the top of your program. That was a directive to include the module for standard input and output. Within the .h file there is information pertaining to the functions in the module. This also allows the compiler to determine if you have the parameters to the functions correct. A.Honey (Oct 2003) S1-42

  43. Simple C programS1_pgm2 So modify your program by adding another printf statement but without any arguments. Then recompile the program. What happens? A.Honey (Oct 2003) S1-43

  44. Simple C program So modify your program by adding another printf statement but without any arguments. Then recompile the program. What happens? You get a compiler error telling you that you used the printf function incorrectly. The compiler knows what to expect as there is information in stdio.h regarding the functions’ parameters. A.Honey (Oct 2003) S1-44

  45. Simple C program So modify your program by adding another printf statement but without any arguments. Then recompile the program. What happens? You get a compiler error telling you that you used the printf function incorrectly. The compiler knows what to expect as there is information in stdio.h regarding the functions’ parameters. It is the preprocessor which responds to the statements that are preceded with ‘#’. For the include directive, the preprocessor finds the .h file and feeds it into the compiler. The compiler then uses that information while parsing/translating the program. A.Honey (Oct 2003) S1-45

  46. Simple C program So modify your program by adding another printf statement but without any arguments. Then recompile the program. What happens? You get a compiler error telling you that you used the printf function incorrectly. The compiler knows what to expect as there is information in stdio.h regarding the functions’ parameters. It is the preprocessor which responds to the statements that are preceded with ‘#’. For the include directive, the preprocessor finds the .h file and feeds it into the compiler. The compiler then uses that information while parsing/translating the program. Subsequently, the linker will use that information to find the actual function code. A.Honey (Oct 2003) S1-46

  47. Simple C programS1_pgm3 So lets modify your program again to return to the subject of variables. Remove the faulty printf statement and add declarations for an integer variable and a floating-point variable. Anybody know what is needed? A.Honey (Oct 2003) S1-47

  48. Simple C program So lets modify your program again to return to the subject of variables. Remove the faulty printf statement and add declarations for an integer variable and a floating-point variable. Anybody know what is needed? int ivar; float fvar; A.Honey (Oct 2003) S1-48

  49. Simple C program So lets modify your program again to return to the subject of variables. Remove the faulty printf statement and add declarations for an integer variable and a floating-point variable. Anybody know what is needed? int ivar; float fvar; The declarations tell the compiler that there are two variables that may be used in the program and, that those variables have certain storage and representation requirements. The compiler does not necessarily allocate storage for variables until it encounters program statements which use them. A.Honey (Oct 2003) S1-49

  50. Simple C programS1_pgm4 Now we will modify the program to define the variables that we declared. For now we will just assign some constants. ivar = 1111.6; fvar = 1111.6; What do you think happens when these statements are compiled? A.Honey (Oct 2003) S1-50

More Related