Lec-01-S

Lec-01-S - ECE364: Software Tools ECE364: Software Tools...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE364: Software Tools ECE364: Software Tools Laboratory Lecture 1 August 24, 2009 1 Lecture 01 Lecture 01 Course Introduction Brief look at Subversion Brief look at Subversion Getting started with KornShell Data types Reading and writing Control loops Decision making making 2 Course Staff Course Staff Instructor Mark Johnson ([email protected]) Lecturer Ben Fogle ([email protected]) Fogle Coordinating Teaching Assistant Chenguang Sun ([email protected]) Teaching Assistants TBA 3 What are we doing here? What are we doing here? Rapid software development Automating simple tasks Prototyping applications/algorithms General development development 4 Scripting languages Scripting languages Unlike C, they are not compiled into machine code th Your code is run by another program called an interpreter Penalty in speed – usually still fast enough Penalty in memory usage – usually not an issue. So why not just use C? It's hard to write and hard to debug Scripting languages are easier and faster to write Scripting languages are easier and faster to write. RAM is cheap. CPU cycles are cheap. is cheap CPU cycles are cheap Your time is not. 5 What should you already know? What should you already know? The basics of programming You know what a variable is You know what a for loop is etc. The basics of *NIX command line Navigating a directory Listing directory contents Listing directory contents etc. 6 Office hours Office hours ENAD302E ENAD302E General questions Lab make-ups Redos Days/Times TBA. Check course website Since often no one shows up, the TA may often no one shows up the TA may leave after 15 minutes if the room is empty If you plan to show up later than empty. If you plan to show up later than that, just let the TA know via email. 7 Website Website http://cobweb.ecn.purdue.edu/~ee364/ Contains schedule, prelabs, lecture notes. Contains detailed course policies. 8 Newsgroup Newsgroup purdue.class.ece364 Most course announcements will be posted here. Instructions for getting set up are on the course website. Using the newsgroup is required. This is the best place to get help All the TA’s read the newsgroup You can see questions that other students have asked and their answers. 9 Newsgroup Newsgroup Do not post your code from labs, prelabs, or projects on the newsgroup Come to office hours if you want us to look at your code. Don’t use the newsgroup for questions that th th should remain confidential (i.e, grades) You can email [email protected] Please bring up concerns about course staff in person to the appropriate staff or faculty member. 10 Newsgroup Newsgroup 5 easy points on Lab 3 will be dedicated to successfully posting to the newsgroup. Reply to the thread titled "5 points on Lab 3." In the body, mention your ee364 login (i.e., the body mention your ee login (i ee364a01) 11 Textbooks Textbooks All texts are optional, but recommended. The Quick Python Book by Daryl Harms and Quick Python Book by Daryl Harms and Kenneth McDonald, Manning, 2000 ISBN 1-884777-74-0 Python Essential Reference by David Beazley, New Riders, 1999 ISBN 0-7357-0901-7 Hands-On KornShell93 Programming by Barry Rosenberg Addison Wesley 1999 Rosenberg, Addison Wesley, 1999 ISBN 0-201-31018-X Optional, for reference Optional, for reference 12 Course Outline Course Outline Lectures 1-3: Subversion and KornShell basics Lectures 4-6: Python basics Lecture 7: Ksh and Python comparison Lecture 8: Regular expressions 8: expressions Review for practical #1 Lectures 9-11: Advanced Python and GUI’s Review for practical #2 Labs1-4: Subversion and KornShell basics Labs 5-7: Python basics Lab 8: Ksh and Python comparison Lab 9: Practical #1 Labs 10-11: Regular expressions and advanced Python Labs 12-13: GUI programming with Python (Project) 12 programming Python (Project) Lab 14: Practical #2 13 Grading policy Grading policy 10 Lab exercises at 6 units each: 60% Of which 5% will be allocated to prelabs, lecture exercises, and quizzes quizzes 2 Project "phases" at 9 units each: 18% 2 Practical exams at 11 units each: 22% Practical exams at 11 units each: 22 Course Average >=87% >=78% >=69% >=60% <=60% and and and and or Course Outcomes =100% =100% =100% =100% <100% Letter Grade A B C D F 14 Grading policy Grading policy Laborator Laboratory exercises, project phases, and practicals project phases and practicals are out of 100 points For laboratory exercises, up to 85 points total throughout the semester may be allocated in the following manner: 5 – 15 points for completion of the corresponding prelab points for completion of the corresponding prelab Up to 10 points (per lab) may, without advanced notice, be awarded for participation in an exercise or quiz administered during lecture administered during lecture 85 points represents 5% of your final course percentage It will most likely end up being less than 85 points 15 Prelabs Prelabs Prelabs are due at the end of your lab period If you score 90% or above on a given lab, you automatically receive credit for the prelab It is probably a dangerous gamble for most is probably dangerous gamble for most people and is generally discouraged We don’t actually adjust scores until the end of don actually adjust scores until the end of the semester. Doing the prelab is the most helpful thing you the prelab the most helpful thing you can do to prepare for the lab itself. 16 Academic Honesty Academic Honesty “If you claim someone else’s work as your own, we call that you claim someone else’s work as your own we call that ‘cheating.’” Do not do prelabs, labs, or practicals for other students. Do not work with other students during the lab. At all. Do not even talk to them. Do not discuss lab material outside of your lab section until that week has passed. Do not look at other students work Do not look at other students' work. Protect your work - if your work is turned in by another student, you are both guilty. All work is subject to computer-based comparison and work is subject to computer comparison and analysis. 17 Academic Honesty Academic Honesty Th The minimum penalty for any incident of academic dishonesty will be a score of zero for the item in question. th it More serious or repeated infractions will result in an F for the course. All incidents will be referred to the Dean of Students, the ECE Academic Head for Education, and the ECE Undergraduate Office. Ask questions about this policy without risk 18 Make Make-ups You get one free make up of any lab that you missed No questions asked. Missing any more labs requires a good any more labs requires good reason Signed note from an instructor, PUSH, etc. If you know you going to have to miss If you know you’re going to have to miss a lab, let us know ahead of time. 19 Make Make-ups If you are experiencing flu-like symptoms Do not come to class or lab Let us know by phone or email (not in person) We will work with you to determine a schedule will work with you to determine schedule for you to complete your work. Campus emergency We send instructions via the newsgroup and email. 20 Redos Redos You may redo each lab one time You can only earn up to 50% If you get a worse score, you must keep it You may not redo practicals or projects. may not redo practicals projects 21 Course ABET outcomes Course ABET outcomes In addition to earning a passing grade in the class, you must also demonstrate satisfactory achievement of the following seven course outcomes. Failure to satisfy any of the seven outco outcomes will result in an F All course outcome remediation exercises must be completed the week before dead must be completed the week before dead week. 22 Outcomes Outcomes 1 & 2 An ability to use scripting languages to integrate the input/output of diverse software systems. Assessment: You must successfully write at You must successfully write at least one KornShell script and one Python program which interacts with the class program which interacts with the class operating system as part of the laboratory tasks and/or practical exams which passes all tasks and/or practical exams which passes all of the instructor's tests. 23 Outcome Outcome 3 An ability to apply modern testing tools to assess software reliability and correctness. Assessment: You must successfully test at You must successfully test at least one Python program for software reliability and correctness using the reliability and correctness using the techniques taught in class. These programs can be from the laboratory tasks or from the can be from the laboratory tasks or from the practical exams. 24 Outcome Outcome 4 The ability to design modern user interfaces. Assessment: You must successfully write at least one Python program which uses an least one Python program which uses an interactive user interface as part of the laboratory tasks or from the practical exams laboratory tasks or from the practical exams which passes all the instructor's tests. 25 Outcome Outcome 5 An understanding of regular expressions. Assessment: You must successfully write at least one Python program which requires the use of regular expressions as part of the laboratory tasks or from the practical exams which passes all of the instructor's tests. 26 Outcome Outcome 6 An ability to design, use, and incorporate Python classes in programs. Assessment: You must successfully write at least one Python program which requires the least one Python program which requires the design and use of Python classes as part of the laboratory tasks or from the practical the laboratory tasks or from the practical exams which passes all the instructor's tests. 27 Outcome Outcome 7 An ability to incorporate associative arrays into programs. Assessment: You must successfully write at least one Python program which requires the least one Python program which requires the design and use of associative arrays as part of the laboratory tasks or from the practical of the laboratory tasks or from the practical exams which passes all the instructor's tests. 28 In the lab In the lab Ch Choose your text editor We suggest "vi". Read chapter 16 of gg Rosenburg for information on command line editing with vi. You can use any editor installed on the elwom elwom machines. The default is vi. Emacs The default is vi Emacs is NOT usable during practical exams! You are encouraged to bring your text book(s) to lab 29 Subversion (SVN) Subversion (SVN) A revision control system Tracks changes to your code Facilitates collaboration between programmers You will be required to use Subversion in all of your labs. all of your labs. This is how you upload code for grading. If you didn’t use SVN, you didn’t turn anything you didn use SVN you didn turn anything in! 30 SVN SVN – terms Repositor Repository—a central store of data. Your work is central store of data Yo is ultimately stored here. Working copy—a local copy you keep of what’s in the repository. You make changes to your working copy just like any other file or directory, and you can add or delete things from your working copy delete things from your working copy. Checkout—the act of creating a new working copy Committing—the act of uploading changes to your working copy to the repository, i.e., synchronizing the repository to your working copy. Updating—the act of downloading any changes from act of downloading any changes from the repository to your working copy, i.e., synchronizing the working copy to the repository. 31 SVN SVN – basic usage usage Th The command svn checkout <url> creates a new working copy. Th The command svn add <file> will mark a file to fil be added to the repository when you commit. The command svn rm <file> will mark a file to be command <fil will mark file to be deleted* from the repository when you commit. The command svn commit will commit your command svn commit will commit your changes to the working copy. * Nothing is really ever deleted from the repository. 32 SVN SVN – backup copies copies SVN SVN makes a backup each time you ti commit. The command svn update –r<revision> <file> will retrieve an older version of a file from the repository. <revision> may be: A version number: 2312 version number: 2312 A date and time: '{2009-08-23 13:00}' 33 SVN Keywords SVN Keywords Certain keywords will be expanded when you commit a file. keywords will be expanded when you commit file $Author$ Username of the person committing $Date$ Wh thi fil When this file was committed $Revision$ The revision number of this file The revision number of this file $HeadURL$ The URL where this file lives in the repository $Id$ A combination of the above keywords 34 Shells Shells A shell is an interface between the user th and the operating system. Graphical shells You are probably most familiar with these You are probably most familiar with these because of Windows Text Text-based shells shells CLI or command line interface You've used these in ECE264, etc. used these in ECE264 etc These are the focus of the class 35 Shells Shells Shell commands can be stored in a script and run as program Shells scripts are a full-fledged language and can be quite complicated and can be quite complicated. 36 Shells Shells Th fi li The first line of a script is special in *NIX *NIX The first two characters of the file must be #! The rest of the line tells the operating system which rest of the line tells the operating system which interpreter to use. This lets you write scripts in any shell or language, and use another interactively, if you like. if lik Some common shells include: #! #! #! #! #! #! #! /bin/sh /bi /bin/csh /bin/tcsh /bin/ /bin/ksh /bin/bash Bourne Shell Shell C-Shell tcsh Shell KornShell Bourne-Again Shell 37 KornShell KornShell Created in 1982 by David G. Korn at AT&T Interactive and scriptable Interactive and scriptable A superset of sh and contains features from csh. Similar to bash (also a superset of sh) to bas (a supe 90% of the ksh scripts you write in this class will run under bash if you replace print with will run under bash if you replace 'print' with 'echo' 38 Versions of ksh Versions of ksh Th 88 The ''88 version A few ECN Sun machines have this The '93 version We will use this version exclusively pdksh – a public domain clone of KornShell A few ECN Linux machines still have this few ECN Linux machines still have this Use /bin/ksh --version to determine which /bin/ksh to determine which version you are using 39 Diving in Diving in - ksh variables variables Declaration and definition Declaration and definition NAME="whatever" no spaces before or after the “=” The type (number or string) depends on the context Access the variable with $NAME or ${NAME} When encountered in a script the variable name will be encountered in script the variable name will be substituted for its value in a sort of copy/paste. Examples: Var1=7 Var2="Hello!" Var3=3.14159 Var4=$Var1 40 Special variables Special variables These variables are always defined Variable $# $* and $@ $0 $$ $? $1 to $N to $N Description Number of command line arguments to the script All the command line arguments to the script The script name Current process ID number Return value from last executed command The Nth command line parameter (separated by Nth command line parameter (separated by whitespace.) 41 print print command print <options> <arguments> Writes its arguments, separated by a space to standard output (usually the screen) Ends with a newline If whitespace is important, use quotes. Data is left as is. I.e., it is not formatted. it Examples: $ print Hello, World! print Hello World! Hello, World! $ print Hello, World! Hello, World! $ print "Hello, World!“ Hello, World! 42 Common print options Common print options See pages 248-249 and 389 of Rosenberg 248 389 for more detail. -u1 print to standard output to standard output -u2 print to standard error -u# print to file descriptor # fil do not add a newline at the end -n -ignore options beyond this point -r do not treat backslash (\) character as special -R Same as using both -r and -43 Examples Examples print print print print -n ", -5 -"Hello“ World!“ degrees! degrees! -5 degrees! Results in the following output: in the following output: Hello, World! ksh: print: -5: unknown option Usage: print [-enprs] [-f format] [-u fd] [string ...]] -5 degrees! 44 printf command printf command See pages 250-254 and 389 of Rosenberg 250 389 Almost like in C: printf <format> <arguments> The format string is like that found in C The list of variables should be separated by spaces. Example: A=3.45 S="Big Deal“ printf "A: %5.2f, S: %s\n" $A "$S" 45 More ksh variables More ksh variables Untyped variables can be used to hold strings, integers, and floating point values Most of the variables you will use will be untyped untyped Script #! /bin/ksh A="Big Deal“ print $A A=3 print $A A=2.3 print $A Output Big Deal 3 2.3 46 Typed variables Typed variables Integers typset –i NAME integer NAME Floating Point Point Generic float float NAME Specify a certain number of decimal places certain number of decimal places typset -F# NAME Specify a certain number of significant figures typeset -E# NAME NAME Read only typset -r NAME="FOO" readonly NAME="FOO" Can combine with other typset parameters: typset -ri CONST_INT=30 47 Typed variable example Typed variable example Script #! /bin/ksh integer A A=2.4 # Will be truncated print "A: $A" A=3 print "A: $A" A="Oh Well" print "A: $A" exit 0 Output A: 2 A: 3 ksh: oh well: arithmetic syntax error 48 Typed variable example Typed variable example Script #! /bin/ksh float A typeset -E5 B typeset -F4 C A=2.1234567890 B=1234.56789 C=9.1234567 print "A: $A\nB: $B\nC: $C“ A: $A $B $C A=3 print "A: $A" A="Oh Well" Well print "A: $A" exit 0 Output A: 2.123456789 B: 1234.5 1234.5 C: 9.1234 A: 3 ksh: Oh well: arithmetic syntax error 49 for loops for loops Two different syntaxes in KSH diff KSH for VAR in LIST do commands done where LIST is a set of strings separated by whitespace for (( initial_expression; loop_condition; loop_expression )) (( initial loop loop )) do commands done In each case, the do must be on the second line. 50 Examples Examples for I in 1 2 3 4 5 do print -n ${I} Done for (( I = 1; I < 6; I++ )) (( )) do print -n ${I} Done Both result in the same output: result in the same output: 12345 51 More examples More examples #! /bin/ksh /bi for File in *.c File in do lp –dSOME_PRINTER $File done 52 while loops while loops In KSH, a command is ‘True’ when it KSH ‘T it returns 0, and ‘False’ otherwise. Completely backwards from C Most of the time the command in for loop Most of the time the command in a for loop is a test. while <command> do <commands…> done 53 Examples Examples #! /bin/ksh /bi # $RANDOM is a special variable. It returns a # different random integer each time it is different random integer each time it is # called. # The (( ... )) command is for numeric tests. while (( $RANDOM % 10 != 0 )) do print “looping!” done 54 read command read command Th The read command reads a line of input li from standard input (usually the keyboard) print –n "Please enter something: " read UserInput print "You entered $UserInput" It It can also be used to read from other streams, such as a file When looping, the redirection goes at the end of the loop. Everyone forgets this. 55 Example Example #! /bin/ksh /bi cat MyFile.txt MyFile print while read line do print “Read line: $line” done < MyFile.txt 56 Example Example #! /bin/ksh /bi cat DataFile.txt DataFile print while read A B C do print –n “A: |$A| ” print –n “B: |$B| ” print “C: |$C|” done < DataFile.txt Example Output Output This is Neat! EE 364 is Great 364 is Great 12345 Big Deal Deal 1234 A: A: A: A: A: |This| B: |is| C: |Neat!| |EE| B: |364 C: |is Great| |1| B: |2| C: |3 4 5| |Big| B: |Deal| C: || |1234| B: || C: || |1234| || || 57 KSH Math KSH Math All All built-in math is in double precision floating fl point in the new ksh. The old ksh only had integer math. Use let or (( … )) to isolate mathematical statements Read chapter 4 of Rosenberg for more details. Basic math operators include: addition (+), subtraction (-), multiplication (*), division (/), and modulus (%) 58 Integer math example Integer math example #! /bin/ksh /bin/ksh integer a=11 integer b=3 b= integer x (( x = a + b print print -R "(( "(( (( x = a - b print -R "(( (( x = a * b print -R "(( (( x = a / b print -R "(( "(( (( x = a % b print -R "(( )) x= )) x= )) )) x= )) x= )) x= $a + $b )) x = $x" $a $b )) $x" $a - $b )) x = $x" $a * $b )) x = $x" $a / $b )) x = $x" $b )) $a % $b )) x = $x" 59 Integer math output Integer math output #! /bin/ksh /bi (( (( (( (( (( x x x x x = = = = = 11 11 11 11 11 11 + * / % 3 3 3 3 3 )) )) )) )) )) )) x x x x x = = = = = 14 14 8 33 3 2 60 Floating point math example Floating point math example #! /bin/ksh /bi float X=10.34 float Y=2.54 float Z=0.0 (( Z = X + Y )) printf "Z = X + Y %5.2f = %5.2f + %5.2f\n" Z X Y (( Z = X - Y )) printf "Z = X - Y %5.2f = %5.2f - %5.2f\n" Z X Y ((Z = X * Y )) printf "Z = X * Y %5.2f = %5.2f - %5.2f\n" Z X Y 61 Floating point math output Floating point math output Z = X + Y 12.88 = 10.34 + 2.54 12 10 Z = X - Y 7.80 = 10.34 - 2.54 Z = X * Y 26.26 = 10.34 * 2.54 26 10 62 Branching Branching if command1 then commands... elif command2 then commands... else commands... fi Note: A command is true if it returns 0 63 Testing Testing These a special commands used for comparison When testing files and strings, use double bracets: bracets: [[ space whatever space ]] Example if [[ $A == “foobar” ]] ; then print “They are equal” fi 64 File Testing File Testing -a -d -f -r -s -w -x ! file exists is a directory is a regular file fil is readable has nonzero length is writable is executable … and lots more Invert the test (not) 65 Arithmetic comparison Arithmetic comparison When dealing with numbers: always use: (( whatever )) For example: if (( 7 <= 5 )) then print "The world is at an end!“ fi Arithmetic comparisons are the ones you remember from C (==, !=, >, etc.,): 66 String tests String tests Equality if [[ string1 = string2orpattern ]] if [[ string1 == string2orpattern ]] [[ ]] if [[ string1 != string2orpattern ]] Lexicographically ordering ordering if [[ string1 < string2 ]] if [[ string1 > string2 ]] Emptiness if [[ -n string1 ]] # string is not NULL st ]] st if [[ -z string1 ]] # string is NULL 67 Example Example #! /bin/ksh /bin/ksh if (( $# != 1 )); then print "Usage: $0 <filename>" "Usage: <filename>" exit 1 fi File="$1" if [[ ! -f "${File}" ]]; then print "File: ${File} is not an ordinary file" else print "File: ${File} is an ordinary file" fi exit 0 68 Output Output $ File_Check File Usage: File_Check <filename> $ File_Check x File File x is not an ordinary file $ File_Check File_Check Fil Fil File File_Check is an ordinary file 69 Single line if Single line if-statements A commonly used shorthand commonly used shorthand # Print debug message if debugging is turned on [[ $DEBUG == "YES" ]] && print "Executing program..." # Equivalent to: if [[ $DEBUG == "YES" ]] then print "Executing program..." fi # Create a directory if it doesn't exist [[ -e mydirectory ]] || mkdir mydirectory mydirectory ]] || mkdir mydirectory # Equivalent to: if [[ ! -e mydirectory ]] [[ ]] then mkdir mydirectory fi 70 Assignment for Lab Assignment for Lab 2 Do the prelab, it will be worth 10 points out of th it 10 your final lab score Go to the website and familiarize yourself to the website and familiarize yourself with all of the policies. There may be a quiz. Read over these lecture notes and the notes over these lecture notes and the notes for next week (lecture 2) Read chapters 1, 2, 3, 6, 7, 11 and 12 of chapters 11 and 12 of Rosenberg (if you need to) Read about the print Read about the print and printf commands printf on pages 222-226, and 248-254 (if you need to) 71 ...
View Full Document

This note was uploaded on 11/01/2009 for the course PSY 120 taught by Professor Donnely during the Spring '08 term at Purdue.

Ask a homework question - tutors are online