Tuesday, 17 February 2015

Week 6

Apologies for the late post! Reading week has begun quite busily and I did not get a chance to post until now.
Object-oriented programming now feels quite intuitive, as we have had a fair bit of practice already. Whenever we need a "thing" in our program, we create a class and an instance of that class that has all of the traits and abilities that we want for our "thing." So far, we have been told to include str, repr, init, and eq methods for any class we create, though I am not too certain why this is necessary. Danny, our professor, says that it is good etiquette to include such methods in a class, but sometimes it seems rather unnecessary. If programmers are "lazy," as Danny says, why should we include methods that are not of use to our program? This seems like an invalidated use of space. Another point I am not too clear on is what we want the output of our repr method to be - this seems like an alternate form of str, which is automatically used when no str method is present. To my knowledge, we could make the repr method output be whatever we wanted, as a representation of the object in a particular class. On my assignment, however, a note was that the repr should return something that can be pasted into the shell and have it create the specified object. I do not remember ever having learned this, nor having seen it in any examples. I would prefer to know in advance so that I do not make a similar mistake in any future assignments or in the rest of my career.

No comments:

Post a Comment