Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
One more year to go at Tech.
Coweb Assignment 2:
Tracing Code (1 Point)
1 + 2 * 3 - 4 factorial -15
a := #(1 2 3 4 5)
#(1 2 3 4 5)
a select: [:i | i odd]
#(1 3 5)
b := a
#(1 2 3 4 5)
a := a reverse
#(5 4 3 2 1)
b collect: [:i | i i]
#(1 4 9 16 25)
a perform: #at: withArguments: #(4)
Refactoring (1 point)
- Briefly, describe what refactoring is and why would you do it. In your description, include two signs that code should be refactored and how you would go about refactoring the code.
- How can unit testing be useful when refactoring code?
- Refactoring is when you want to improve how reliable or readible code is, without adding or removing functionality. Refactored code should appear to have had no changes made to it at all during execution. Code should be refactored when it is difficult to maintain or understand. A simple type of refactoring is changing variable names to words that are more useful or intuitive to code maintainers. Removing dead or unused legacy code is a type of refactoring.
- Unit testing is a very useful tool for refactoring. With Unit Testing, one can be sure that bugs and errors were not inadvertantly added to code. By running unit tests periodically during the refactoring stage, programmers are able to test all changes to the code as they are made to be sure that a programs functionality remains intact.
Coweb Assignment 3:
History of OO (1 point)
- What was the first object-oriented language? simula
- What two elements, kept separate in structured programming, did it combine? procedures and data
- Name three contributions to computing that were made at the learning research group at Xerox PARC? Overlapping windows, ethernet, the Mouse
Virtual Machines (1 point)
- What is bytecode and why is it useful? Bytecode is source code compiled to run on a virtual machine. This is very useful because it allows us to use the same program on multiple platforms. The virtual machine is the only difference, and it translates the bytecode into machine code for the computer.
- Give an example of Smalltalk code and its translation into bytecode.
This is an instance method called score from the Simon Game
| myLabel contents |
contents:= game score asString.
myLabel := StringMorph new.
myLabel color: Color white.
myLabel contents: contents.
Here is what it looks like in Bytecode
33 <01> pushRcvr: 1
34 send: score
35 send: asString
36 <69> popIntoTemp: 1
37 <42> pushLit: StringMorph
38 send: new
39 <68> popIntoTemp: 0
40 <10> pushTemp: 0
41 <45> pushLit: Color
42 send: white
43 send: color:
44 <87> pop
45 <10> pushTemp: 0
46 <11> pushTemp: 1
47 send: contents:
48 <87> pop
49 <10> pushTemp: 0
50 <7C> returnTop
Programming (1 Point)
This is an instance method placed in the String class
| retString startCharNum endCharNum temp |
(self size < aNumber) ifTrue: [^self]
ifFalse: [aNumber <= 3 ifTrue: [^'...']
ifFalse:[temp:= (aNumber - 3).
startCharNum:= (temp // 2) + (temp \\ 2).
endCharNum:= (self size) - (temp // 2) + 1.
1 to: startCharNum do: [ :i | retString:= retString asString, ((self at: i) asString)].
retString:= retString, '...'.
endCharNum to: (self size) do: [:j | retString:= retString asString, ((self at: j) asString)].
Links to this Page
- Summer 2006 Who's Who last edited on 3 September 2007 at 8:57 pm by adsl-215-134-227.aep.bellsouth.net
- Minimax last edited on 10 June 2006 at 10:42 am by c-69-180-27-207.hsd1.ga.comcast.net