Today in CS362: Stack Frames and More Admin Project, phase 1 graded Other homeworks not yet graded (sorry ...) Cool Enigma talks (extra credit) Overview About project, phase 1 Where we've been, where we're going Where do variables go? Stack Heap Stack Frames Non-Local Variables (maybe) Project, Phase 1 NO HAMMERS! Or .. try to choose the best tool for the job and be willing to switch tools. COMMENTS! (1) Use Javadoc /** * Simple pithy sentence that describes the following thing. * More information, if appropriate (e.g. special cases). */ /** * This is a class comment. * * @author Joe Smith * @verson 1.0 of October 2002 */ /** * This is a method comment. * * @throws HellFreezesOver * when sam actually makes sense */ (2) Explain each class, field, method, and constant. Particularly explain special values. (2a) Use the "six P's", if you're feeling particularly energetic. (3) Explain interesting parts of your code. (4) Optional: Explain steps of your code. (5) Somewhere give the "big picture" ENCAPSULATION! What should I reveal to the outside world? What should I reveal only to related classes? When is it appropriate to violate this? /** * A StringTokenizer that keeps track of line numbers. */ public class HelpfulStreamTokenizer extends StreamTokenizer { // +--------+----------------------------------------- // | Fields | // +--------+ /** Current line number. */ int lineno; // +--------------+----------------------------------- // | Constructors | // +--------------+ public HelpfulStreamTokenizer(xxx) { super(xxx); lineno = 1; } // HelpfulStreamTokenizer(xxx) // +---------+---------------------------------------- // | Methods | // +---------+ /** * Get the next token. */ public int nextToken() { int tok = super.nextToken(); if (tok == StreamTokenizer.TT_EOL) ++lineno; return tok; } // nextToken() /** * Get the current line. Wo hoo! */ public int line() { return lineno; } // line() } // class HelpfulStringTokenizer STYLE methods public whatever name(params) throws A,B,C { } public whatever name(params) { } conditionals if (xxx) { } else { } if (xxx) { } else { } while { } try { } catch { } try { } catch { } catch { } ELEGANCE Try to write efficient code. Convert between a keyword string and the corresponding integer constant. public String keyidToString(int keyid) { if (keyid < 0) throw new YouAreABozoException(); if (keyid > MAX_ID) throw new IAMABOZOException(); /* if (keyid == CONSTANT) return "constant"; if (keyid == BEGIN) return "begin"; ... */ /* switch (keyid) case CONSTANT: return "constant"; */ /* preliminary work String keywords[MAX_ID]; keywords[CONSTANT] = "constant"; later return keywords[keyid]; }