barbagroup / JITcode-MechE

Online learning modules to learn computing in a problem-based context within Mechanical Engineering
MIT License
7 stars 5 forks source link

Lesson 1 - Explanation of Static vs Instance Methods #25

Closed zwade closed 10 years ago

zwade commented 10 years ago

numpy.shape(T) Again, we've told Python where to find the function shape() by attaching it to the library name with a dot. But since the shape is also a property of any NumPy array, we can get the same result another way: T.shape

They way this is worded is a little confusing, it might be good to not mention both of them, since it reads as though all static methods of numpy should be available as instance methods (or fields) of T, which is not necessarily the case.

gforsyth commented 10 years ago

I agree that it might be a little confusing, but we do need a segue for students to grok the idea of methods (static or instance) belonging to a thing.

Did you have specific static methods in mind @zwade ? I know that we'll probably have them use transpose, shape, reshape, flatten, real, imag, but all of those will work as instance methods (I believe). As long as there isn't anything too glaring, this might be a little white lie that we can correct once they've got a stronger foundation in the language, but I'm open to ideas.

zwade commented 10 years ago

I would just rephrase it a bit, maybe like:

Again, we've told Python where to find the function shape() by attaching it to the library name with a dot. However, NumPy arrays also happen to have a property shape that will return the same value, so we can get the same result another way: T.shape

gforsyth commented 10 years ago

That sounds great -- can you submit a pull request and then close this out?