Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 22 Online
OpenStudy (anonymous):

can someone explain why prof guttag used four classes in lecture 17. i watched it a few times and still cant figure it out. i mean, i know there is a good reason for that, i just cant see it. i even wrote my own implementation of random walk and i make only one class - drunk. result is the same, but it looks simpler, to me at least. after that i even tried to make things "more complex" with trig functions, but result remains the same and code became simpler again. randWalk: http://codepad.org/VdNfDfEK rndWTrig: http://codepad.org/aBOIZSDA I'm not sure i understand OOP at all :(

OpenStudy (anonymous):

I hated hated hated his Field class. It is totally unnecessary. He included it because of how you do OO design: nouns become classes, verbs become methods. A Drunk walks around a Field in random Directions to Locations. Hence he put in a Field class. But if you just phrase the problem as a Drunk walks around in random Directions to Locations, then the Field is unnecessary. If I'm in a field I don't have to ask the field where I am. *I am* where I am. My implementation had 3 classes: Location, Direction, Walker (I didn't like the name Drunk). I also had some subclasses to make walking in cardinal directions easier, and to handle walking in arbitrary directions. Your code looks pretty good. I would change it a little bit to make it a little more object-oriented, and change some of the behavior of some of the Drunks methods (or change their names). But it's small and clean and readable. I liked viewing the actual RW paths. Load my file and do plotSingleWalk(singleWalk(StraightWalker(Origin), 1000)) or plotSingleWalk(singleWalk(Walker(Origin), 1000)) Increase the 1000 to get a longer walk.

OpenStudy (anonymous):

And if you really want I can post more vitriol about his Field class. ;)

OpenStudy (anonymous):

thanks for answering, but i still don't get it. what confusing me the most is what you wrote: "He included it because of how you do OO design: nouns become classes, verbs become methods. He included it because of how you do OO design: nouns become classes, verbs become methods." i really cant see any advantage of writing four classes. it certainly works, but why to make it complicated!? why we cant look at direction and location as kind of properties of drunk? he decides, or trying, where he want to go, and we don't have any restrictions related to field, x -> infinity, y -> infinity, no obstacles... i still don't know why professor gave very complicated answer to very simple question: how far from the start drunk will be after 500 random steps? your graph is amazing, great job. now i have to study your code too :)

OpenStudy (anonymous):

it is an intro class. in the first lecture he provides a caution for ppl who already know how to program - that maybe this isn't the right class for them. if you already know all about oop maybe you should find a different course to take.

OpenStudy (anonymous):

Rodic, you're right about his Field class. Put the location in the Drunk and the Field becomes pointless. But there are definite advantages to creating at least a Location class. Slightly fewer advantages for the Direction class. One of the earlier lectures (I don't remember the number) talked about using a list or tuple to store a point, and referring to them as point[0] and point[1]. He then went on to define cartesianPoint and polarPoint classes, and explained why they were better than just using a list of two values. It's an important concept, and I think he did a good job explaining it. The benefits of OO are many and varied. Too many to list in an openstudy post. Probably thousands of books have been written on the subject. Large books. If you continue programming and have to start writing larger projects you'll definitely start appreciating classes more. When I first started learning C++ I wasn't really sure what should be a class. It wasn't until I took a Data Structures course that I really understood the OO concept. I can see why you might think more classes is more complicated. But just like using functions can simplify your code, using classes can simplify your code, too. They hide details away from code that needs to use them. They also provide a single place for code that might be used in many different places in a program. The Random Walk example is not the best example to use to extol the virtues of OOP. But definitely the Location class is a useful class to create for it. I'd suggest that you take your current code and extract a Location class from it, and rework the Drunk class to use that Location class, just to see what it does to the code. Start by creating the Location class, and moving your existing list of values into it. Then change Drunk to use that class. Then add a method called getMagnitude(), and another one called move(xOffset, yOffset). It probably won't make you an OO expert or believer, but I think seeing your code before and after will be very instructive.

OpenStudy (anonymous):

Lecture 15 had the cartesianPoint/polarPoint example.

OpenStudy (anonymous):

@dmanice thanks. i'll take your advice and experiment for a while. as i said, there is a reason, but i just cant see it. maybe spending more time on this and playing with code will help me. @bwCA one of the reasons why i took this course is oop. i don't know anything about it.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!