Learning to program with the help of interactive shells
Monday, August 18, 2008 at 10:48PM Many interpreted programming languages, such as Ruby and Scala, have interactive programs that serve as excellent learning tools. During the last few weeks, I have been reading about Ruby, but learning the language has taken me longer than expected, mainly because the languages I know best (namely Java and C) have syntaxes that differ greatly from that of Ruby.
To put my knowledge to practice, I used Ruby's interactive shell, irb. Here's a naive attempt at writing a method that prints "Hello":

Calling the method Hello yields this response in the interactive shell:

The response above indicates that the method call on line four isn't actually calling anything. Through trial and error, I was able to test syntactically different calls until "Hello" was printed on screen:

From the whole experiment, I have now learned two things about methods in Ruby:
- Calling a method with a blank parenthesis yields the desired result
- Not using a parenthesis treats line four as a reference to a constant
These two points, along with the information in the Ruby Quickstart tutorial (which states that methods that don't take parameters can be called with or without a parenthesis), tells me that using a capitalized method name is not the way to go: using lowercase methods names eliminates the possibility of this naive error from happening to me again. And it's something I figured out on my own - it wasn't mentioned in the otherwise excellent tutorial.
I heartily recommend using an interactive shell such as Ruby's irb, if your language SDK comes packaged with one. Learning by doing.
Keys in relational databases
Wednesday, August 13, 2008 at 01:10PM Learning the basics of relational database management systems (RDBMs) such as MySQL and PostgreSQL isn't altogether difficult with the help of a tutorial. But these beginner tutorials, such as the one explaining SQL on W3Schools are, although useful, not enough for any aspiring computer science professional, because they dot not explain the concepts of RDBMs in the more advanced and decidedly more theoretical level that is needed for advanced topics, such as database normalization.
The single concept that I struggled with at first is the concept of keys. There are many different keys, such as primary keys, candidate keys, foreign keys and superkeys - these terms are often used incorrectly or interchangeably. I've compiled a list that explains the different types of keys in a fashion that hopefully is easier to understand then the formal explanations on Wikipedia.
Superkeys
Superkeys are groups of one ore more attributes (also known as column values) that uniquely identify a single tuple (row) of a given relation (table). Consider the following example:
Person(Social Security Number, Name, Address)
In this relation, the attribute Social Security Number will identify a unique row or tuple, so { Social Security Number } is definitely a superkey. The other superkeys of this relation consist of more than one attribute: { Social Security Number, Name } is a superkey, as is { Social Security Number, Name, Address }. If we could be assured that no two or more people can ever have the same name and address, then { Name, Address } will also identify a unique row and is thus also a superkey.
Candidate keys
Candidate keys are essentially narrowed-down versions of superkeys: a superkey is a candidate key if and only if the said superkey doesn't have a proper subset of attributes that is also a superkey. The superkey { Social Security Number, Name, Address } is not a candidate key, because there exists a proper subset of this superkey that itself is also a superkey : { Social Security Number }. { Social Security Number } is therefore a candidate key in our example. If we assume that { Name, Address } is a superkey, then it's also a candidate key.
The easiest way to think of candidate keys is to remember their alternate name: minimal superkeys. Narrowing down the number of attributes in any given superkey as much as possible with the result still remaining a superkey will result in a minimal superkey or candidate key.
Unique keys / primary keys
Understanding unique keys / primary keys is straightforward if one understands the differences between superkeys and candidate keys. A unique key is simply a candidate key chosen to be the preferred candidate key for a particular table in a RDBM system. Superkeys and candidate keys are just concepts - unique keys are what are actually used in "real" relational databases.
Primary keys are exactly like unique keys except for the fact that most RDBM systems don't allow NULL values in the attributes that make up primary keys, whereas unique keys can typically have attributes with the value NULL. Primary keys exist mainly as a convenience to application programmers.
Foreign keys
Foreign keys are sets of attributes (one or many ) in a table that references the primary key in another table. The attribute values of a single tuple in the referencing table must occur in a single tuple in the referenced one (with NULL as a possible exception). With foreign keys, it is possible to store data into several different tables, while still being able to combine them when necessary. Using multiple tables and foreign keys is a fundamental part of database normalization.
Subversion clients, resources and tools
Tuesday, August 12, 2008 at 03:27PM A few links to services, tools and resources that helped me learn the basics of SVN (the SVN clients mentioned are for Mac OS X):
The Cornerstone Mac SVN Client
I requently use CLI programs, but for SVN, I prefer using a GUI client. For the Mac platform, I recommend Cornerstone by Zennaware. Apart from providing a graphical frontend for the SVN CLI tools, Cornerstone also includes a full version of Subversion, as well as administrative tools - no CLI required. If you are looking for a GUI SVN client and you run OS X version 10.4.11 or above, Cornerstone is a viable option. It's not free, however: a single user license runs $59.99. I've been using the 14-day free trial, and will probably buy it when the trial runs out.
Another good option for a Mac GUI SVN client is Versions - I just find the interface of Cornerstone more to my liking.
Beanstalk
Beanstalk is an hosted SVN solution. If you for whatever reason don't want to install SVN on your own system, Beanstalk offers and easy way to get your own SVN system up and running. The basic version, which allows for one repository, three users and 20 megabytes of storage space, is completely free, with additional options available for a price. A hosted SVN solution is great for accessing your repositories from anywhere using an SVN client such as the ones mentioned above (I'm currently using Beanstalk with Cornerstone as my primary SVN solution).
Version Control with Subversion
Version Control with Subversion is an online book that covers the basics of SVN as well as advanced topics. This is the primary resource I used for learning SVN, and it has the best price tag of all - free.

