Saturday, September 27, 2008

More than a beginner might need on classes

In an earlier blog I suggested that this tutorial might sometimes offer forks, with career programmers following one path and real beginners following another. And the More on Classes lesson perhaps represents the point on the current trail when the two paths might part. With what we've been told already, an enthusiastic beginner could create classes and objects and write some useful code.

For the sake of completeness, I'll continue on the trail, and perhaps make the occasional snide remark on the way.

Lets begin with Returning a Value from a Method. If I entitled a lesson thus, I'd open it with a statement about returning values from methods.

And if I wanted to open a lesson with the sentence: "A method returns to the code that invoked it when ... ", then I'd entitle the lesson something like "Code Execution Paths". Heading a lesson "Returning a Value" and then talking about paths through code is at best confusing.

Methods returning values are like functions in VB. To be honest I never used them, or at least, not home made ones. But I am sure there are others who did, and they might enjoy this page more than I did.

The next lesson on the "this" keyword was straightforward enough. There's something similar in VB; I've forgotten what it is now.

The lesson on controlling access is probably interesting to programmers working for large corporations, but it was deadly boring to me.

The lesson on class variables gives an interesting illustration of how to use a class/static variable in conjunction with the constructor to record the number of objects created from a class. It goes on to show how to use a class/static method to access the variable without creating another instance of the class. I'm not sure when I'd ever use this, but it was interesting, and quite clever.

The lesson on initialising fields gives an interesting insight as to when constructors work better than initialisation on declaration. This little titbit could have been put in the lesson which introduced the constructor, and the next one on the topic, and it would have made a lot more sense of those lessons.

The summary lesson is fine, but again, I was always taught the summary and introduction should contain similar components. If I were writing these tutorials, I'd include all the essential components of this summary in the very first lesson on classes, albeit perhaps with different colours for compulsory items (instance variables, methods), and optional items like constructors and static variables and methods, at at least a basic explanation of when and how to use them.

No comments: