Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1 Part I: Compilers Part II: Pair Programming Most slides courtesy of Ms. Stephany Coffman-Wolph Many slides modified by Prof. L. Lilien (even many without explicit message). Slides added by L.Lilien are © 2006-2012 Leszek T. Lilien. Permision to use for non-commercial purposes slides added by L.Lilien’s will be gladly granted upon a written (e.g., emailed) request. 2009 Pearson Education, Inc. All rights reserved. 2 Part I: Compilers Outline: 1) Machine Languages, Assembly Languages and High-Level Languages 2) The Compiler and the Java Virtual Machine (JVM) 3) Java Software Editions (Versions) 4) Compiling a Java Program 5) The Complete Compilation Process 2009 Pearson Education, Inc. All rights reserved. 3 Part I: Compilers • From Chapter 1 of the textbook (p.12) • Plus many slides courtesy of Ms. Stephany Coffman-Wolph • Plus slides modified and added by Dr. Lilien 2009 Pearson Education, Inc. All rights reserved. 1. Machine Languages, Assembly Languages and High-Level Languages 4 • Programmers write instructions in various programming languages • Three general types of computer languages : – Machine languages – Assembly languages – High-level languages 2009 Pearson Education, Inc. All rights reserved. 1. Machine Languages, Assembly Languages and High-Level Languages (Cont.) 5 Fig. 1.1 | Comparing machine, assembly and high-level languages. 2009 Pearson Education, Inc. All rights reserved. ++READ LATER++ 1. Machine Languages, Assembly Languages and High-Level Languages (Cont.) 6 • A computer can directly understand only its own machine language – It consists of streams of numbers - Ultimately reduced to binary 1s and 0s • Machine-language programs - nearly incomprehensible to humans – Example machine-language program snippet: +1300042774 +1400593419 +1200274027 2009 Pearson Education, Inc. All rights reserved. ++READ LATER++ 1. Machine Languages, Assembly Languages and High-Level Languages (Cont.) 7 • Machine-language programming is slow and error prone • English-like abbreviations form the basis of assembly languages – Easier to program in them – Easier to understand them • A computer does not understand assembly languages – Until they are translated into computer’s machine language – Translation done by assemblers • Assemblers convert assembly-language programs to machinelanguage programs – Example assembly-language program snippet: LOAD BASEPAY or: LD BASEPAY ADD OVERPAY STORE GROSSPAY or 2009 Pearson Education, Inc. All rights reserved. ++READ LATER++ 1. Machine Languages, Assembly Languages and High-Level Languages (Cont.) 8 • Example: Assembly code and its machine code [ http://en.wikipedia.org/wiki/Assembly_language#Assembler ] NOTE: The “object code” of the assembler is the machine code Slide added 2009 Pearson Education, Inc. by AllL.Lilien rights reserved. ++READ LATER++ 1. Machine Languages, Assembly Languages and High-Level Languages (Cont.) 9 • To facilitate programming, high-level languages were developed • Keywords in English form the basis of high-level languages – Much easier to program in them – Much easier to understand them – Look almost like everyday English with math expressions: grossPay = basePay + overTimePay • A computer does not understand high-level languages – Until they are translated into computer’s machine languages – Translation done by compilers • Compilers convert high-level-language programs to machinelanguage programs 2009 Pearson Education, Inc. All rights reserved. ++OPTIONAL++ 1. Machine, Assembly and HighLevel Languages (Cont.) 10 • A typical compilation process [ Fig. from: http://en.wikipedia.org/wiki/Compiler ] – With more detail that you need to know Slide added 2009 Pearson Education, Inc. by AllL.Lilien rights reserved. 11 2. The Compiler and the Java Virtual Machine • See next page and Fig. 1-5/p.13 • A programmer writes Java programming statements for a program. • These statements are known as source code. • A text editor is used to edit and save a Java source code file. • Source code files have a .java file extension. • A compiler is a program that translates source code into an executable form. 2009 Pearson Education, Inc. All rights reserved. 12 The Compiler and the Java Virtual Machine Program Development Process Saves Java statements Source code (.java) Text editor Produces Java compiler Java Virtual Machine Results in Byte code (.class) Program Execution (JVM) 2009 Pearson Education, Inc. All rights reserved. 13 ++READ LATER++ The Compiler and the Java Virtual Machine • A compiler is run using a source code file as input. • Syntax errors that may be in the program will be discovered during compilation. • Syntax errors are mistakes that the programmer has made that violate the rules of the programming language. • The compiler creates another file that holds the translated instructions. 2009 Pearson Education, Inc. All rights reserved. 14 The Compiler and the Java Virtual Machine • Most compilers translate source code into executable files (executables) containing machine code. • The Java compiler translates a Java source file into a file that contains byte code instructions. • Byte code instructions are the machine language of the Java Virtual Machine (JVM) and cannot be directly executed directly by the CPU. 2009 Pearson Education, Inc. All rights reserved. 15 ++READ LATER++ The Compiler and the Java Virtual Machine • Byte code files end with the .class file extension. • JVM is a program – It emulates a micro-processor. – It executes instructions as they are read. • JVM is often called an interpreter. – And Java is often referred to as an interpreted language. • See figure on Slide 12 • See next slide and Fig. 1-6/p.13 2009 Pearson Education, Inc. All rights reserved. 16 Portability JVM = Java Virtual Machine Byte code (.class) JVM for Windows JVM for Linux JVM for Unix JVM for Mac 2009 Pearson Education, Inc. All rights reserved. 17 Portability • Portable means that a program may be written on one type of computer and then run on a wide variety of computers, with little or no modification. • Java byte code runs on the JVM and not on any particular CPU; therefore, compiled Java programs are highly portable. • JVMs exist on many platforms: •Windows •Mac •Linux •Unix •BSD •Etc. 2009 Pearson Education, Inc. All rights reserved. 18 ++READ LATER++ Portability • With most programming languages, portability is achieved by compiling a program for each CPU it will run on. • Java provides an JVM for each platform so that programmers do not have to recompile for different platforms. 2009 Pearson Education, Inc. All rights reserved. 19 3. Java Software Editions (Versions) • The software you use to write Java programs is called the Java Development Kit, or JDK. • There are different editions of the JDK: – Java SE - Java2 Standard Edition – Java EE - Java2 Enterprise Edition (for large business apps) – Java ME - Java2 Micro Edition (for cell phones, pagers, appliances, etc.) • Available for download at http://java.sun.com 2009 Pearson Education, Inc. All rights reserved. 20 4. Compiling a Java Program • The Java compiler is a command line utility. • The command to compile a program is: javac filename.java • javac is the Java compiler. • The .java file extension must be used. Example: To compile a java source code file named Payroll.java you would use the command: javac Payroll.java 2009 Pearson Education, Inc. All rights reserved. 21 5. The Complete Compilation Process • Complete compilation process I/O: – Input: high-level language (HLL) code – source code – Output: machine-code – object code 2009 Pearson Education, Inc. by AllL.Lilien rights reserved. Slide added 22 5. The Complete Compilation Process (Cont.) • Four basic steps performed by a typical compiler: 1) Preprocessing (a part of the compiler!) - To expand macros (details later) 2) Compilation (in the narrow sense) - Translates from high-level source code to assembly code -Not to byte code 3) Assembly (a part of the compiler!) - Translates from assembly code to machine code - When there are calls to external functions in the assembly source file, the assembler leaves the addresses of the external functions undefined, to be filled in later by the linker 4) Linking (a part of the compiler!) - Takes one or more objects and combines them into a single executable An executable requires many external functions from system and run-time libraries - Creates the final executable (<name>.exe in Windows) This and next 9 slides courtesy of S. Coffman-Wolph, a Pearson few modified (slightly) by L. Lilien 2009 Education, Inc. All by rights reserved. Slide modifieds L.Lilien 1) Preprocessing 23 • First stage of the overall compilation process • Preprocessor processes compiler directives • Directives – Allow for conditional compilations - To conditionally skip sections of source files, - To report errors and warning conditions - To have distinct regions of source code – E.g., in C#, always placed on their own line and begin with # • NOTE: – Java does not have a preprocessor. – See: – 2.2.1 in: http://java.sun.com/docs/white/langenv/Simple.doc2.html – http://www.javalobby.org/java/forums/t18116.html – Hence, Java does not provide the capability to communicate with the Java compiler using compiler directives 2009 Pearson Education, Inc. All rights reserved. 24 1) Preprocessing (Cont.) Example of C# Code w/Preprocessor Directives (lines starting with #) #define Debug // Debugging on #undef Trace // Tracing off class PurchaseTransaction { void Commit() { #if Debug CheckConsistency(); #if Trace WriteToLog(this.ToString()); #endif #endif CommitHelper(); } } 2009 Pearson Education, Inc. All rights reserved. 25 2) Compilation • The actual compilation — in the narrow sense • Input: preprocessed source code • Output: assembly language (for a specific processor) – ++OPTIONAL++ Major phases: - Scanner “Break up” the text/code into tokens Done via Regular Expressions - Parser Insures that the source code follows all the rules - Code generator Creates assembly language code 2009 Pearson Education, Inc. All rights reserved. ++READ LATER++ 2) Compilation (Cont.) Regular Expressions 26 • Regular expressions are from the theoretical side of computer science – Automata theory – Formal language theory – These fields study models of computation (automata) and ways to describe and classify formal languages • Regular expressions are used mainly for pattern matching 2009 Pearson Education, Inc. All rights reserved. ++READ LATER++ 2) Compilation (Cont.) Regular Expression Basic Examples 27 • Match any digit – \d or [0-9] • Match any non-digit – \D • Match exactly three digits – \d{3} or \d\d\d or [0-9][0-9][0-9] or [0-9]{3} • Match any sequence of letters in upper or lower case, but there must be at least 1 letter – [a-zA-Z]+ • Match any sequence of at least one word character – \w+ 2009 Pearson Education, Inc. All rights reserved. 28 3) Assembly • Converts assembly language code into machine code – Input (source file): assembly language code – Output (object file): machine code • Processes calls to external functions – They can be present in the source file (assembly language file) – Assembler leaves addresses of external functions undefined - To be filled in later by the linker (next overall compilation phase) 2009 Pearson Education, Inc. All rights reserved. 29 4) Linking • The final stage of compilation is the linking of object files to create an executable – Takes multiple object files and creates one executable file. – Among these object files are many external functions taken from system and run-time libraries • Linker complains if it can not link proper methods/functions – Earlier in compilation , if a method/function did not exist, it was assumed that it was in another file (to be linked later) – You can think of this phase as the one trying to fill-in any remaining “blanks” and “ties” it all together 2009 Pearson Education, Inc. All rights reserved. 30 The Complete Compilation Process (Cont.) • Summary: Four basic compiler steps: 1) Preprocessing (a part of the compiler!) 2) Compilation (in the narrow sense) 3) Assembly (a part of the compiler!) 4) Linking (a part of the compiler!) 2009 Pearson Education, Inc. All by rights reserved. Slide modifieds L.Lilien 31 Part II: Pair Programming • Slides courtesy of Ms. Coffman-Wolph • Plus minor modifications by Dr. Lilien 2009 Pearson Education, Inc. All rights reserved. 32 Pair Programming • Pair Programming = Two People, One Computer – A mechanism for real-time problem solving and real-time quality assurance – Helps developers to focus on the problem at hand • Two people work together at one computer to create code – Not simply dividing up the project… • … and working on them independently – The “pair” should be in the same room - Or in this day and age, communicating in real-time - E.g., via Video Chat, Shared Desktop, etc. 2009 Pearson Education, Inc. All rights reserved. 33 Tasks for Driver and Navigator • One person is a driver – Controls the keyboard and mouse - types the actual code – Leads the conversation and discussions through the process • One person is a navigator – – – – Pays attention to the driver Monitors code and design Makes relevant suggestions, Corrects errors - Stop holes in logic, provide debugging assistance, etc. • Communication between driver and navigator is the most important part of Pair Programming! – Without good communication, Pair Programming teams are ineffective • Switch the roles throughout the entire project – Nobody should always be the driver or navigator 2009 Pearson Education, Inc. All rights reserved. 34 Things to Avoid Things you should avoid: Interrupting every time your partner starts doing something in a way other than how you'd do it Once you wrestle the keyboard away, deleting your partner's last edit immediately Then doing what you were thinking of instead If your partner objects, ignoring it and talking over it Speaking non-stop, so your partner never has a moment of silence in which to speak, read code, or have a thought For further (humorous) reading: http://www.c2.com/cgi/wiki?HowToPissOffYourPair 2009 Pearson Education, Inc. All rights reserved. 35 But I Like Working By Myself… • Things to think about: – Writing software is a team activity - Large software is extremely rarely written by one person alone – You can learn from your partner’s feedback - To benefit from both your successful and less successful activities, techniques and habits – Pair programming studies have shown: - Pair programmers have greater productivity than solo programmers (most studies show double productivity) - Pair programming significantly improves design correctness - Pair programmers’ code has overall higher correctness - Pair programming decreases overall time required 2009 Pearson Education, Inc. All rights reserved. 36 ++READ LATER++ More Benefits of Pair Programming • Studies have shown the following benefits: – Better brainstorms – Better and higher quality code – Increased morale – Increased teamwork – Enhanced learning – Increased courage – Better and more effective debugging – Increased knowledge – Better time management 2009 Pearson Education, Inc. All rights reserved. 37 ++READ LATER++ Selecting your partner… • Suggestions: – Find a partner that is in your lecture and/or your lab - Makes things a little easier… – Find a partner who’s schedule can work with your schedule - Start by comparing schedules, if both of you only have 1 hour that you can meet up - this really will not work – Make sure you and your partner can easily meet in the same location - Schedule your first meeting to be very soon after the assignment comes out – Exchange contact information (names, email, phone numbers, etc) when you agree to be partners – Start your assignment early! - Things go smoother if you are not starting at 2 am the day before it is due…(trust me on this one) 2009 Pearson Education, Inc. All rights reserved. ++READ LATER++ How to they “pick” partners in “real” world? 38 • Alternatives: – People paired by managers - Mixing novice programmers with experts - Mixing “new” programmers with “older” programmers – People select their partners themselves – People pick tasks they want to work on, and the pairs result from task selections - Pair forming is especially easy if a large project is broken into very small tasks - People pair with lots of partners throughout the project 2009 Pearson Education, Inc. All rights reserved. 39 ++READ LATER++ Can I… • … work on the project without my partner? – Track down an error in between meetings, read the specs, ask the instructor clarification questions, think through the logic/design - yes – You should wait to do major design/coding only when you and your partner can meet • … not have a partner? – It is a requirement for CS1120. (Sorry) – If you feel you have a special case - see me • … change partners between assignment 6 and 7? – Absolutely • … come to you if I am having problems with my partner? – Absolutely 2009 Pearson Education, Inc. All rights reserved. 40 Good Reading Material on Pair Programming • “All I Really Need to Know about Pair Programming I Learned In Kindergarten” – http://collaboration.csc.ncsu.edu/laurie/Papers/Kindergarten.PDF • “Software Reviews and Pair Programming” – http://agile.csc.ncsu.edu/SEMaterials/ReviewsandPairProgramm ing.pdf • Many more – you can google it up 2009 Pearson Education, Inc. All rights reserved. 41 In-class Pair Programming Exercise • Get problem from our class web page 2009 Pearson Education, Inc. All rights reserved. 42 The End 2009 Pearson Education, Inc. All rights reserved.