340 likes | 469 Views
Lecture 3: Chapter 4.1 and 4.2. Discussion groups: Very impressed! Excellent job by class-wide discussion contributors Learning Goal: Technical analysis and communication skills Coaches help you “ask yourselves the right questions” Meet the Coaches.
E N D
Lecture 3: Chapter 4.1 and 4.2 • Discussion groups: Very impressed! • Excellent job by class-wide discussion contributors • Learning Goal: Technical analysis and communication skills • Coaches help you “ask yourselves the right questions” • Meet the Coaches
Click in every time!Or you are losing points! • Quiz Questions: • No negative points for wrong answer, try! • Discussion Questions: • You need to get >=50% of questions correct! • Reward for preparing for class • Being able to develop your analysis and communication skills • And you and your group must all CHOOSE THE SAME ANSWER after discussion • Encourage “good” and thorough discussions
How to Do Homework • Don’t read FIRST • Sit down, open Alice, and do the homework WHILE you are using Alice.
What do you get from this course? • Analysis skills – • Practiced and refined in your group discussions! • We learned in Alice that computers do exactly what you have them do. Using this knowledge, we can understand how programs like Excel and Numbers work and learn that when we are using these programs, we need to specify and be exact with what we are doing in order for the programs to meet our needs and plans.
Analysis Technique: • Begin at the beginning: • Are you reading the question the “same way”? • What is the question asking for? • TRY THESE: • “So what I think this is asking is” • “It seems like the idea here is whether we can identify the differences in these codes” • “We need to figure out how to correct this code to do X instead of Y”
Another reason this class is important • From CNN article* on SOPA – Stop Online Piracy Act • “But SOPA's critics say that say that the bill's backers don't understand the Internet, and therefore don't appreciate the implications of the legislation they're considering.” • The “basic” view • If your site links to a site which links to a site that might have pirated content… More about this next week! * http://money.cnn.com/2012/01/16/technology/sopa_wikipedia/index.htm
What is the best explanation of why we divide code into methods? • In order to be able to put a name on them • In order to break work into manageable pieces • So it can be stored more efficiently • So that each object can have “actions” they do
What term do we use to describe the indicated area below A. Method call B. Method definition C. Method action
If you created a new band member (“Juan” Beetle) would you need to create a new method to get him to play a solo? • Yes, you would need to make a copy where juan’s object would call methods • Yes, because otherwise juan wouldn’t know what to do • No, you wouldn’t be able to get him to play a solo – this would only work for 4 beetles • No, you can use the same method, passing in the juan beetle as a parameter
When you hit Play Alice will by default*: • Runs World.My first method • Starts by running whatever method you created first • Starts by running whatever method you created last • Runs all the methods in the order they appear in the methods tab • None of the above *Assuming you don’t modify any of the events in the upper right corner
Ways to demonstrate understanding of programming Writing Reading • Communication among people • Debugging • Produce a result/artifact
That was Writing, Now Reading • Given an Alice program (or part of a program) • Be able to read it and describe what code does (scenario) • In English, since we’re not making you draw or even give the storyboard
What does this code do? • Makes the eskimo girl say Hello, then jump up and down • Makes the eskimo girl say Hello WHILE jumping up and down • Makes the eskimo girl say Hello • None of the above
How would we change the code to make her say Hello while jumping up and down?
Note: Our intent in NOT to “trick you” • Computer programs are PICKY • Getting them to do what you want requires paying attention to a lot detail • In computing, getting the computer to do EXACTLY what you want is often very important • Flying planes: • A BIT too close is TOO CLOSE! • Red light cameras better not ticket me when the light’s yellow
Methods you might like to use(and you should play with) • move vs turn vs roll • The “as Seen By” modifier • Can make moving, turning or rolling behave differently • OrientTo • PointAt • Duration and Style modifiers (abruptly, etc.)
Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods 4.2 Parameters (up to page 107)
Did you watch the 8-min video? • You need to know • Step-wise refinement • How to decide what to put in a method • Who methods “benefit” • Various benefits of methods • Easy to repeat (or re-order) work
Below: what happens after the last instruction in the mystery method is finished executing? • The program starts the World.my first method • The program goes back to my first method and calls method XXXXX • The program goes back to my first method and calls method YYYYY • We can’t tell, we need to know more about the storyboard to be able to say
Methods: Why again? • Break complex things into smaller, more manageable pieces (step-wise refinement) • Do something more than once… • Do something more than once, but not exactly the same each time • Parameters allow you to write code one time but have it be useful in various circumstances • where the “thing” involved could be different each time
Parameters: Controlling variation • We wanted to make the beetles be able to do identical solos • But we didn’t want to have to write it out 4 times. • So we passed a parameter that told which beetle to move • The challenging issue is often figuring out what parameters a given method could have
If we write a method called drive, which would not make sense as a parameter to control how drive occurs? • Destination • How fast • Which car • Car color *Green ringed slides: exploratory – any answer will “count as” correct Even though some ARE NOT correct
If we write a method called drive, which would not make sense as a parameter to control how drive occurs? • Destination • How fast • Which car • Car color
If we write a method called beat (as in a cooking context) which would not make sense as a parameter • Temperature of ingredients • How long • Finishing state (soft/medium/hard peaks) • Ingredients to beat • Container to use *Green ringed slides: exploratory – any answer will “count as” correct Even though some ARE NOT correct
A parameter • Has a “type” such as a Number, Object, or Other (e.g. Color, Sound) • Is something you must have for every method • Allows you to send information to a method when it is called • A and B • A and C
Which of the following is the best explanation of what makes a good parameter • It’s something that supports common variation in how the method is done • It’s got a meaningful name • It can be either an Object or a number • It’s helps manage complexity in large programs
A parameter • Has a “type” such as a Number, Object, or Other (e.g. Color, Sound) • Is something you must have for every method • Allows you to send information to a method when it is called • A and B • A and C
Which of the following is the best explanation of what makes a good parameter • It’s something that supports common variation in how the method is done • It’s got a meaningful name • It can be either an Object or a number • It’s helps manage complexity in large programs
Just vocabulary: Parameters • Always come “after” the method name on a tile
Alice: It’s REALLY close to Java(and most every programming language today) public class Demo { public static void main (String[] args) { World w = new World("Chapter04Example"); //x, y, and z coordinates) Skater iceSkater = new Skater(w, 100, 200, 0); iceskater.move("forward", .5, 2); //where 0 is forward, 1: backward, 2:left,etc. //iceskater.move(0, .5, 2); } }
How did it go? • Did you get 50% right? • Yeah, you might need to read more • Slowly • Deeply (?) • Do the homeworks • With someone else • Talk about them with someone else (or me!)
Which best describes what happens when my First Method is run? • The helicopter moves down to the rabbit’s location • The rabbit moves up to the helicopter’s location • The helicopter and the rabbit move to meet each other (halfway between) • I don’t know