320 likes | 780 Views
Principles of Software (CSCI 2600) Fall 2014. www.cs.rpi.edu/~milanova/csci2600/ Ana Milanova Lally Hall 314, 518 276-6887 milanova@cs.rpi.edu Office hours: Tuesdays and Fridays 4-5pm. Outline. Logistics Goals and topics Java (for a C++ programmer). Logistics. Course webpage
E N D
Principles of Software (CSCI 2600) Fall 2014 www.cs.rpi.edu/~milanova/csci2600/ Ana Milanova Lally Hall 314, 518 276-6887 milanova@cs.rpi.edu Office hours: Tuesdays and Fridays 4-5pm
Outline • Logistics • Goals and topics • Java (for a C++ programmer) Fall 14 CSCI 2600, A Milanova
Logistics • Course webpage http://www.cs.rpi.edu/~milanova/csci2600 • Announcements – check regularly • Schedule, Notes, Reading • Schedule, lecture slides and assigned reading • Homework • Homework assignments posted there • RPILMS • Discussion board, your grades Fall 14 CSCI 2600, A Milanova
Logistics • Required textbook • Effective Java, 2nd Edition, by Joshua Bloch, Addison Wesley, 2008 • Recommended books/resources • Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison Wesley, 1995 • Refactoring: Improving the Design of Existing Code by Martin Fowler, Addison Wesley, 1999 Fall 14 CSCI 2600, A Milanova
Logistics • Java Resources • Main Java website by Oracle: http://java.com • Java documentation: http://docs.oracle.com/javase/ • 1.7 JDK: http://docs.oracle.com/javase/7/docs/api/ • Java tutorial: http://docs.oracle.com/javase/tutorial/ • Java language specification: http://docs.oracle.com/javase/specs/ • Café au Lait: Java FAQ, News, and Resources
Logistics • Syllabus www.cs.rpi.edu/~milanova/csci2600/syllabus.htm Topics, outcomes, policies and grading • 2 midterm exams and a final exam: 50% • 10 homework assignments: 50% • 5% extra credit for attendance and participation Fall 14 CSCI 2600, A Milanova
Logistics • Programming assignments must be be completed individually! • Principles of Software builds individual skills • Carry these skills to collaborative projects Fall 14 CSCI 2600, A Milanova
Logistics • Homework will be submitted and released through Subversion (SVN) • Checkout repository to obtain csci2600 project and first homework, hw0 • To submit a homework, commit into repository • To obtain next homework, update repository • Install Eclipse and Subclipse (plugin that interfaces with SVN) • More on SVN, JUnit and Javadocs next time
Academic Integrity • Homework assignments must be completed individually • Discussion is allowed, but carrying material out of a discussion is not allowed • I trust you. • But…, cheating is extremely easy to catch • I will not tolerate it • Policy does not apply to HW0. Ask anyone! Fall 14 CSCI 2600, A Milanova
How to Study • Read textbook in advance of lecture • I will assign reading ahead of class, whenever possible • Read lecture notes and textbook (again) right after class • I will post lecture notes about an hour after class • Form study groups • ASK QUESTIONS – in class, after class, etc. Fall 14 CSCI 2600, A Milanova
Goals • Principles of Software teaches you to write correct and maintainable programs • What does it mean for a program to be correct? • Specifications • What are ways to achieve correctness? • Principled design and development • Abstraction and modularity • Documentation Fall 14 CSCI 2600, A Milanova (based on a slide by Michael Ernst, UW)
Goals • What are ways to verifycorrectness? • Reasoning about code, verification • Testing • Debugging Fall 14 CSCI 2600, A Milanova
Goals • What does it mean for a program to be maintainable? • Well-documented and understandable • “Open for extension but closed for modification” • Canonical example: We have an editor that manipulates shapes. We have coded Square and Circle and have written tons of client code that manipulates them. It should be “easy” to add a Triangle Fall 14 CSCI 2600, A Milanova
Goals • What are ways to achieve maintainability? • Object-orientation and polymorphism greatly facilitate maintainability • Principled design and development • Abstraction and modularity • Documentation • Ultimately, correctness is most important! Fall 14 CSCI 2600, A Milanova
Goals • Building good software is incredibly hard! • Large software systems are enormously complex. Lots of “moving parts”! • Software is constantly put to new uses sometimes without relevant experience • Software engineering is about: • Mitigating and managing complexity • Managing change • Dealing with software failures Fall 14 CSCI 2600, A Milanova (based on slide by Michael Ernst, UW)
Topics • Reasoning about code • Invariants • Specifications • Polymorphism, abstraction and modularity • Design patterns • Testingand debugging • Refactoring • Tools: Java, the wealth of Java libraries, Eclipse IDE, Subversion, JUnit, debuggers, Javadocs and other • Principles are more important than the tools!!! Fall 14 CSCI 2600, A Milanova
Topics • You will learn a lot! • You will carry what you learn into • SD&D - 4000-level software engineering class • Focuses on teamwork, software process, requirements • Other programming-intensive classes • RCOS • Research projects • Internships and jobs
Outline • Logistics • Goals and topics • Overview of Java (for a C++ programmer) Fall 14 CSCI 2600, A Milanova
Java • Java is a prerequisite • I expect you to have experience with Java • … If not, you can pick it up • ASK Questions! • What are most important differences with C++? Fall 14 CSCI 2600, A Milanova
Java: Differences with C++ • Model for variables • Type safety • Compilation vs. interpretation • Reflection • Classes and inheritance • Other Fall 14 CSCI 2600, A Milanova
Models for Variables • Value model for variables • A variable is a location that holds a value • I.e., a named container for a value • a := b • Reference model for variables • A variable is a reference to an object which has value • Every variable is an l-value • Requires dereference when r-value needed (usually, but not always implicit) l-value (the location) r-value (the value held in that location) Fall 14 CSCI 2600, A Milanova
Models for Variables: Example b := 2; c := b; a := b + c; • Value model for variables • b := 2 b: • c := b c: • a := b+c a: • Reference model for variables • b := 2 b • c := b c • a := b+c a 2 2 4 2 4 Fall 14 CSCI 2600, A Milanova
Questions • What is the model for variables in C/C++? • Value model • Python? • Reference model • Java? • Mixed. Value model for variables of simple type, reference model for variables of class type! Fall 14 CSCI 2600, A Milanova
Models for Variables • This code has different meaning in C++ and in Java …Foo p; // p is a local variable double d = p.bar(); … Fall 14 CSCI 2600, A Milanova
Equality Testing: == and equals() • Java uses the reference model for class types class Point { int x; // x-coordinate int y; // y-coordinate Point(int x, int y) { this.x = x; this.y = y; } } ... x = new Point(2,5); y = new Point(2,5); z = y; x y 5 2 5 2 z true or false?x == y ? true or false?y == z ? true or false?x.equals(y) ? true or false?y.equals(z) ?
Equality Testing: == and equals() • In Java, == tests for reference equality. This is the strongest form of equality • Often, we need a weaker form of equality, value equality • In our Point example, we want x to be “equal” to y becausethe x and y objects hold the same value y z x y 5 2 5 2 Fall 14 CSCI 2600, A Milanova
Equality Testing: == and equals() • What happened in our Point example? • Point inherited Object.equals: public boolean equals(Object o) { return this == o; } • OverrideObject.equals to get value equality! • Much more on this later in the class x y true or false?x == y ? true or false?y == z ? true or false?x.equals(y) ? true or false?y.equals(z) ? 5 2 5 2 z
Equality Testing • In languages with reference model for variables we have two equality tests • One tests reference equality, whether two references refer to the same object • == in Java. E.g., x == y • is in Python. E.g., print x is y • Other tests value equality. Even if the two references do not refer to the same object, the objects can have the same value • .equals() in Java • == in Python
Pointer Types • In C/C++, we need pointers • Allocate dynamic memory on the heap • Define recursive types (types defined in terms of themselves) such as linked lists. Think why. • In Java, references are essentially pointers • The reference variable (the address) may be on the stack, the object is always on heap • We cannot have an object on the stack! • Defining recursive types is easy
Java: Differences with C++ • More on Type safety, Compilation vs. interpretation, Reflection, and Classes and inheritance on Friday! Fall 14 CSCI 2600, A Milanova
Homework 0 • Setup Eclipse and Subclipse • You should be receiving an email from CS Labstaff regarding authentication • If you don’t receive it today, let me know ASAP • Checkout the csci2600 repository • Text of HW0 comes with it • Practice of basic Java, use of Java libraries, Eclipse and JUnit • LET ME KNOW IF YOU HAVE ISSUES! Fall 14 CSCI 2600, A Milanova
Next Class • Will finish discussion of Java vs. C++ • Will discuss Eclipse, SVN, Junit and Javadoc • Will discuss UML and UML Class Diagrams Fall 14 CSCI 2600, A Milanova