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
Python Plus Java in a Three Course Sequence David Ranum Brad Miller Luther College We’d like them to look like this But many look more like this Want To Avoid This Why do they end up this way? ! Taxonomy of Problems in Teaching Java -- The Java Task Force Difficulties Teaching Java in CS1 and How We Aim to Solve Them ! Taming the Tiger -- Teaching the next generation of Java ! The Dream of a Common Language: The search for Simplicity and Stability in Computer Science The original Pascal book by Wirth had 266 Pages, Dietel and Dietel has 1536 There are more public methods in the java and javax package heirarchies than there are words in Wirth's book. ! Taming Java for the Classroom ! Java is the Canonical Lanuage for teaching introductory programming, but... ! Lots of Papers on help for teaching objects early ! BlueJ ! ObjectDraw ! Karel J Robot ! Java Task Force Libraries Why do they end up this way? ! Taxonomy of Problems in Teaching Java -- The Java Task Force ! Taming the Tiger -- Teaching the next generation of Java ! The Dream of a Common Language: The search for Simplicity and Stability in Computer Science The original Pascal book by Wirth had 266 Pages, Dietel and Dietel has 1536 There are more public methods in the java and javax package heirarchies than there are words in Wirth's book. ! Taming Java for the Classroom !Java is the Canonical Lanuage for teaching introductory programming, but... ! Lots of Papers on help for teaching objects early ! BlueJ ! ObjectDraw ! Karel J Robot ! Java Task Force Libraries Why do they end up this way? ! Taxonomy of Problems in Teaching Java -- The Java Task Force ! Taming the Tiger -- Teaching the next generation of Java ! The Dream of a Common Language: The search for Simplicity and Stability in Computer Science The original Pascal book by Wirth had 266 Pages, Dietel and Dietel has 1536 There are more public methods in the java and javax package heirarchies than there are words in Wirth's book. ! Taming Java for the Classroom ! Java is the Canonical Lanuage for teaching introductory programming, but... ! Lots of Papers on help for teaching objects early ! BlueJ ! ObjectDraw ! Karel J Robot ! Java Task Force Libraries The Java Magic Spell? Increasingly, people seem to misinterpret complexity as sophistication, which is baffling the incomprehensible should cause suspicion rather than admiration. (Niklaus Wirth) What Can We Do? Join the folks trying to fix Java or... Use a Language that encourages students to focus on problem solving and computer science As Moti-Ben Ari put it in SIGCSE 2005 Keynote: “Its OK to teach introductory Physics students about levers and pulleys” Its OK to start out on the Green Runs Hello World public class Hello { public static void main(String[] args) { System.out.println("Hello Java World"); } } Hello World >>>print "Hello Python World" Hello Python World Hello World >(print "Hello Scheme World") “Hello Scheme World” > Our Courses and Goals Our Students: Very little programming experience Bright Enthusiastic Our Courses and Goals Learn Computer Science Problem Solving Patterns Techniques Algorithms Data Structures Prepare for Upper Level Courses CS-1 Basic problem solving approaches. Programming is presented as a notation Want to encourage not frustrate Practice Practice Practice CS-2 Students are still beginners! Classic Algorithms and Data Structures Problem solving patterns Analysis CS-3 Software Design and Development 2 Parallel Tracks Java Exceptions Interfaces Inner Classes. GUI and Event Driven Programming Threading Preparing Students for Upper Level CS CS1 Case Studies Accumulator Iteration Over a Collection of Objects Nested Loops and Functions Conditionals Classes Python Data Model Consistency! 1 + 2 == 3 A=1+2 (1).__add__(2) == 3 A 3 CS2 Case Studies Insertion Sort (Pseudocode) Insertion-Sort(A) for j 2 to length[A] key A[j] i j - 1 while i > 0 and A[i] > key A[i+1] A[i] i i - 1 A[i + 1] key Insertion Sort (Python) def insertionSort(A): for j in range(1,len(A)): key = A[j] i = j while i>0 and A[i-1]>key: A[i]=A[i-1] i = i-1 A[i]=key Comparing Python to Pseudocode Insertion-Sort(A) for j 2 to length[A] key A[j] i j - 1 while i > 0 and A[i] > key A[i+1] A[i] i i - 1 A[i + 1] key def insertionSort(A): for j in range(1,len(A)): key = A[j] i = j while i>0 and A[i-1]>key: A[i]=A[i-1] i = i-1 A[i]=key Running and Testing cray:MICS2005> python -i insertion.py >>> A = [9, 4, 2, 10, 7, 22, 1] >>> insertionSort(A) >>> A [1, 2, 4, 7, 9, 10, 22] >>> B = ['dog', 'cat', 'ape', 'eel'] >>> insertionSort(B) >>> B ['ape', 'cat', 'dog', 'eel'] >>> C = [3.14, 2.78, 9.80, 3.8] >>> insertionSort(C) >>> C [2.78, 3.14, 3.8, 9.8] >>> Sorting Objects class student: def __init__(self,lname,fname,gpa): self.fname = fname self.lname = lname self.gpa = gpa def __cmp__(self,other): if self.gpa < other.gpa: return -1 elif self.gpa == other.gpa: return 0 else: return 1 Knights Tour 20 21 22 23 24 15 16 17 18 19 21 23 15 19 12 10 11 5 6 7 13 14 8 9 5 9 1 0 1 2 3 4 3 Graph class Graph: def __init__(self): self.vertList = {} self.numVertices = 0 def addVertex(self,key): self.numVertices = self.numVertices + 1 newVertex = Vertex(key) self.vertList[key] = newVertex return newVertex def addEdge(self,f,t,cost=0): if not self.vertList.has_key(f): nv = self.addVertex(f) for node in graph: if not self.vertList.has_key(t): print node.color nv = self.addVertex(t) self.vertList[f].addNeighbor(self.vertList[t],cost) def __iter__(self): return self.vertList.itervalues() Vertex class Vertex: def __init__(self,num): self.id = num self.adj = [] self.color = 'white' self.dist = sys.maxint self.pred = None self.disc = 0 self.fin = 0 self.cost = {} def addNeighbor(self,nbr,cost=0): self.adj.append(nbr) self.cost[nbr] = cost Depth First Search def knightTour(n,path,u,limit): u.setColor('gray') orderByAvail(u) path.append(u) if n < limit: nbrList = u.getAdj() i = 0 done = False while i < len(nbrList) and not done: if nbrList[i].getColor() == 'white': done = knightTour(n+1,path,nbrList[i],limit) i = i + 1 if not done: # prepare to backtrack path.remove(u) u.setColor('white') else: done = True return done Complete Tour CS3 Case Studies First Few Weeks 2 weeks Java Basics (Using Collections) Command Line then IDE Building Classes Testing -- jUnit Interfaces and Inheritance River Crossings Graph class Graph: def __init__(self): self.vertList = {} self.numVertices = 0 public class Graph implements Iterable<Vertex> { public Graph() { this.vertList = new HashMap<Integer,Vertex>(); this.numVertices = 0; } private HashMap<Integer,Vertex> vertList; private int numVertices = 0; addVertex def addVertex(self,key): self.numVertices = self.numVertices + 1 newVertex = Vertex(key) self.vertList[key] = newVertex return newVertex public Vertex addVertex(int key) { this.numVertices = this.numVertices + 1; Vertex newVertex = new Vertex(key); this.vertList.put(key,newVertex); return newVertex; } Iteration def __iter__(self): return self.vertList.itervalues() for (Vertex v : g) { System.out.println(node.color); } public Iterator<Vertex> iterator() { return vertList.values().iterator(); } Event Driven Programming Java Swing Java 2D Graphics Programming Model View Controller Pattern Listeners and Event Handling Pong What is left? Swing components Threading Simple Network Programming Source Control Database Access (JDBC) XML Next Project jPhoto Summary Put the focus back on Computer Science and Problem Solving By Using Python early we can: Solve interesting problems that motivate Learn important problem solving patterns By Moving to Java at the right time we can: Prepare students for success encourage good software development habits [In a programming language] Simple things should be simple and complex things should be possible. (Alan Kay)