A few students have been asking me about the difference between classes and modules, and when to use each. So I consulted the wise Dave Thomas @pragdave and found this definition:
"A module is basically a class that cannot be instantiated. Like a class, its body is executed during definition, and the resulting Module object is stored in a constant."
Modules are used to organize and encapsulate functionality, which makes them both portable and flexible. When you include a module in a class definition, it becomes an anonymous superclass of the class.
As an example, when you call the
ancestors method on the
String class, it will display the
Kernel modules, though when you call
superclass it will give you
Object and calling
BasicObject. Where did those modules go?
So if classes are structured like a family tree, modules are like benevolent godparents. They do nice things for their godchildren, but they have no biological dependency-relationship.
Name instance methods after what they return. — A nice guideline /slash rule (of the thumb variety). Thanks to Natasha, in the context of a lecture given my Shereef.
Just found the cheat gem, and I don’t know how I survived without it. It provides a suite of command line wiki references for all kinds of languages, platforms, apis, and other goodies.
A small sampling:
# most are really useful cheat unix # unix commands and information cheat spec # fairly comprehensive list of rspec expectations cheat vim # great for the noobs like m'self # some are quite strange and possibly useless... cheat averylongnamethatwecanfind cheat diet cheat foo
gem install cheat and run
cheat all to get a list of available pages.
How much should I refactor? -
The Rails community has been abuzz with object-oriented programming, SOLID principles, laws, design patterns, and other principles, practices, and patterns. We’ve (re)discovered new tools and techniques to separate and reuse logic, making code easier to test, understand, and maintain. Now that we’ve learned about all these new tools, when do we use them?
Ruby has two pattern match methods that can be used as comparison operators:
!~. The first returns the index of the first match or nil if no match is found. The second is the inverse of the first.
While both methods are defined in Object, the
=~ is overridden in String and Regexp to provide more meaningful functionality.
Including these methods in both classes allows for appropriate flexibility in syntactic style:
"string" =~ /ri/ is the same as
/ri/ =~ "string", for example.
This is a pretty, concise way to perform simple pattern matching operations without using explicitly method/argument syntax. Looking forward to making appropriate use of these in my code.
Thanks for dropping some wisdom on me, Mr. Pickaxe.
An asynchronous function is like a spy. The callback function is like a machine with a button that you give to the spy. Then you tell the spy to go to Russia and press the button. —
Btw don’t get all cynical and think the box is a bomb. It could be a listening device, or a communism-o-meter.
One of the differences between education as a structured, regulated, and standardized activity and learning as an inquisitive, analytical, and iterative process is the method of evaluating progress.
With standardization, it is simple: create a test. Whoever passes the test whittles another notch in their knowledge stick and moves on to the next stage of absorbing pre-digested information. Eventually, they may have sufficient notches to leverage their stick for a job or status or something else they may desire. Hooray. End of story.
Everyone is entitled to their opinion and preferred learning style. My opinion is that the above system alienates those for whom exploration and play is the engine of learning and not the motivation to accrue Knowledge Capital for its transactional value in the marketplace. My optimistic side would like to believe that there are a lot more of the first type than the second.
An essential dilemma of establishing and realizing learning institutions that function on the inquisitive/analytical/iterative model is that it is much more difficult to identify and credentialize “stages” of learning. In other words, it is much more difficult to create benchmarks for qualitative data.
I have been mulling over this concept a bit lately because it reflects and impacts my current status as a student/teacher. I learn through teaching, and my learning to time/energy ratio is greater now than it has been in a very long time. However, I doubt that I would be able to articulate in report-card form what I have learned and how much. Even if I could, that seems like an excessively pithy and reductive to represent it.
There is no one answer to this inquiry, so I’d like to pose some questions:
How do you know when you’ve learned something?
Can you put it into words?
When do you make a breakthrough and gain understanding about a new concept, what components propelled that change in state?
The new terrain I want to explore requires some creative thinking about how metrics can be devised to accurately express the state of a learning process without resorting to fixed-parameter comparative procedures. It would be a high-fidelity representation that is simultaneously communicable and translatable outside of its home context. Universally intelligible, not universally interchangeable. An emphasis on design over data. Specific and personalized over general and abstract.
Ideas? Anyone? I guess that deserves a different post.
I was intending to blog everyday about something I’ve learned, a tidbit of knowledge or skills earned. Not so much.
This week has been just as good as the last, but I do feel like the first five days were hyper speed and now I’ve got whiplash from the intense acceleration.
It is a good kind of exhaustion, though. Especially, the moving around between students/pairs and their separate projects requires is exercising some new muscles.
I’m discovering that being a good teacher requires an immense amount of both patience and stamina. Patience to work with students at their own pace when they are struggling and stamina to catch up to where they are when they are going full throttle.
The days feel like rapid-fire routines of interspersed relay sprints and Tai Chi. Repeated. At random.
I hope I’m becoming a better teacher in the process. We’ll see.
If only I had a shovel operator for the objects stored in my mind. Too bad learning new things is more akin to an infinite recursion of