On Thu, Apr 15, 2010 at 11:39 PM, Derek C.
[email protected]wrote:
“def self.name” makes the method static, right?
Yes (in the Java sense of the word).
Is there any particular reason why it is best to do this than have the url
part in the constructor?
Then you can create objects of this class that are not based off of that
url. What if you decide you want to group courses together, under
different
controllers? Maybe the website isn’t updated, and you want to enter them
from the course catalogue instead of the website, or maybe you want to
bring
them in from a second site, or maybe store them locally rather than
querying
the web every time you run the program. This way the class gives you the
ability to create through that website, but doesn’t mandate it, or tie
the
class itself to this particular implementation of how to get it started.
What exactly is “modularity”?
Code that doesn’t know about, or rely on internals of other code. Thus
it
will not break if used differently, or in a different context. It does
not
rely on special knowledge of implementation, or details that may change.
When this happens it is called coupling, when your code is not coupled,
you
can take it and combine it together with many other pieces of code and
it
will operate as desired. For example, if you download the web data into
a
file, you can then use it to pull from the file rather than the page,
because it is modular enough to support a different source.
Think how unix commands are small with a specific function, but you can
combine them in powerful ways. These small programs are modular.
Or relative vs absolute file paths. When they are relative, you can
place
them anywhere, and they still work. Drag and drop that directory, give
it to
friends, etc. If they are absolute, you must go alter that file path
every
time you move it. The absolute file path is coupled to the file’s
location.
What do you gain from doing this?
On a program that will never change, or that is very small, you don’t
really
see the benefits. But when you have to go back later and make a change,
you
want to be able to only make it in the places that logically deal with
that
change. Everything else should still work fine.
If your file is big, and coupled, and you need to make a change, you
will
know, because you will have this scared feeling in your stomache that
you
may have just made a change that could break something completely
different
somewhere else that you can’t even conceive of. Or you may want to make
some
specific change, but then wind up going through every line of code you
have
in order to update all sorts of things all over the place. This
shouldn’t
happen.