CS212 Spring 2002 4/24/2002 Lecture 13: Software Engineering Tools ------------------------------------------------------------------------------- [0] Announcements: + Part 1: The Last Hurrah + Part 2: The Legacy Continues + Part 3: A Nightmare on Babbage Street + Part 4: A New Hope ------------------------------------------------------------------------------- [1] Summary from last time: + Not DIS's view on programming + "other" engineering vs software engineering + Software engineering principles ------------------------------------------------------------------------------- [2] Overview + the nightmare explained + DIS spells it out your summer homework - languages to learn - UNIX, Linux - references/books - UML ------------------------------------------------------------------------------- [3] The Nightmare Explained + ASCII non-printing chars: 0 NUL 1 SOH 2 STX 3 ETX 4 EOT 5 ENQ 6 ACK 7 BEL 8 BS 9 HT 10 NL 11 VT 12 NP 13 CR 14 SO 15 SI + From the designer: "I just uploaded something and ran diff on it -- the Mac-to-Unix newline conversion is kicking in, and so all of the ASCII 13s become ASCII 10s (decimal)." + the fix to the Perl script: ... if( $_ && /\015[^\012]/ ) { $/ = "\015"; } # Mac newlines if( $regexp ) { ... became ... if( $regexp ) { if( $_ && /\015[^\012]/ ) { $/ = "\015"; } # Mac newlines ... + wait a minute... - what's "diff"? - what's a Perl script? |=================================| Page 1 |=================================| [4] Unix Operating System + Unix history: invented because of a _______________ _______________ + the gist: everything is a ______________ + commands: - Unix "tools" philosophy: _________________ - notion of path: _________________ - run things at the prompt and "stick" them together % ls % ls | more - diff? From "man diff": "display line-by-line differences between pairs of text files" + Unix at Cornell? - See http://www.csuglab.cornell.edu/ and look for UNIX Host: babbage.csuglab.cornell.edu - ACCEL: http://www.accel.cornell.edu/ - CS114, CS214 + books: - Introduction to Unix by ____ (see bookstore and other fine establishments) - booklist for CS114, CS214 - O'Reilly! www.ora.com ------------------------------------------------------------------------------- [5] (Shell) Scripts + take sequence of common commands and make a program out of them + Unix INTERPRETS the program + example: copy all file of a certain extension FOO to BAR with the same base name: eg) % cpall java txt copies *.java files to *.txt #!/bin/ksh # if [ $# -ne 2 ] then echo "Usage: cpall inital_extension changed_extension" exit [ 1 ] fi set -A "files" * i=0 while [ i -lt ${#files[*]} ] do basename ${files[i]} $1 | read newfiles[i] let i=i+1 done i=0 while [ i -lt ${#files[*]} ] do if [ ${files[i]} != ${newfiles[i]} ] then cp ${files[i]} "${newfiles[i]}$2" fi let i=i+1 done exit [ 0 ] |=================================| Page 2 |=================================| [6] Perl (http://www.perl.org/) + very versatile scripting language + Unix scripts, CGI, and more! #!/usr/local/bin/perl @a = (1, 2, 3); @b = (0, 2, 4); for ($i=0;$i<=2;++$i) { if(@a[$i] == @b[$i]) { print "yes!\n"; } else { print "no!\n"; } } # Output: # no! # yes! # no! ------------------------------------------------------------------------------- [7] Unix for Programming + compiling other languages + makefiles + version control ------------------------------------------------------------------------------- [8] Compiling Other Languages + first, why not Java for everything? - language/program as tool - different problems need different tools + other languages http://perso.wanadoo.fr/levenez/lang/ http://directory.google.com/Top/Computers/Programming/Languages/ + C/C++/C# discussion + UNIX and compiling + yacc: From "man yacc": "The yacc command converts a context-free grammar into a set of tables for a simple automaton that executes an LALR(1) parsing algorithm. The grammar may be ambiguous; specified precedence rules are used to break ambiguities." + Cornell courses: CS312 (ML), CS113 (C), CS213 (C++), CS??? (C#) ------------------------------------------------------------------------------- [9] Makefiles + suppose you're actually programming on Unix... + need to compile files in a specific way and in a specific order + need to keep track of dependencies... + use Makefiles! |=================================| Page 3 |=================================| [9] Makefiles (continued) # Inside file called main.c: int print1(void); #include int main() { if(!print1()) printf("Error"); return 0; } Inside file called sub1.c: #include int print1(void) { printf("Hello, world!\n"); return 1; } Inside file called Makefile: main: main.o sub1.o cc main.o sub1.o -o main main.o: main.c sub1.o: sub1.c At UNIX prompt: % make cc -c main.c cc -c sub1.c cc main.o sub1.o -o main % main Hello, world! ------------------------------------------------------------------------------- [10] Version Control + on Unix, see cvs, rcs, sccs + CVS: "just 5 commands" + of course, there's always a simple shell script or a "BACK_C"... /* written by DIS when he was in the midst of learning C */ /* thought you might get a laugh out of this :-) #include #include int main(void) { int i; char *d[10],COMMAND[100]; d[0]="0C"; d[1]="1C"; d[2]="2C"; d[3]="3C"; d[4]="4C"; d[5]="5C"; d[6]="6C"; d[7]="7C"; d[8]="8C"; d[9]="9C"; |=================================| Page 4 |=================================| strcpy(COMMAND,""); fprintf(stdout,"\n\nBacking Up *.c Files in Directories 0C-9C...\n"); for(i=8;i>=0;--i) { strcat(COMMAND,"cp "); strcat(COMMAND,d[i]); strcat(COMMAND,"/*.c ./"); strcat(COMMAND,d[i+1]); fprintf(stdout,"\n COMMAND: %s",COMMAND); system(COMMAND); strcpy(COMMAND,""); } fprintf(stdout,"\nDone!\n\n"); } ------------------------------------------------------------------------------- [11] UML (summarized from a few textbooks) + UML: unified modeling language + graphical way to depict semantics and structure of OO language + see links in CS211 Programming Resources + UML is a language: - tokens: pictures/icons - grammar: rules for writing the diagrams from the icons + types of diagrams: - class diagrams: OOP - use-case diagrams - sequence diagrams - collaboration diagrams - statecharts + class: - name - attributes - operations + attributes: - v:T or v:T = initial value (v=var name, T=type) - for public, private, protected, use +,-,# - static things are underlined - append {frozen} for final values - can leave out middle portion if no attributes + operations: - give method heading and return type as m:T - parameters use v:T format - underline static methods - use +/-/# system for modifiers - can leave out names of parameters ex) class Blah { public int x = 1; private static void do(int x) { } } + abstract class: - italicize name and entire listing for an abstract method + objects: - resemble class diagrams - topmost panel has objectname:classname (all underlined) - sometimes list class and instance variables with values |=================================| Page 5 |=================================| [11] UML (continued) + associations: - show logical rel between pairs of classes or objects - connect with lines and optional labels + inheritance - show subclass "pointing" to superclass with "open" arrowhead + aggregations: - has-a relationship - use solid line with open diamond at the "whole" end + interfaces - write <> above interface name, which italicized (why?) - dashed line with open arrow (recall inheritance) for class that implements ("realizes") the interface |=================================| Page 6 |=================================|