How many constructors does the class have?

I’m preparing for an upcoming C++ exam and came across this question about classes and constructors: How many constructors does the class Fraction have?” class Fraction { //… public: Fraction(int numerator = 0, int denominator = 1); //… }; I thought it’s only one, but they suggested there are three: Fraction(); Fraction(n); Fraction(n, d); Or … Read more

What is the difference between inheritance and Categories in Objective-C

Can some one explain to me the difference between categories and inheritance in Objective C? I’ve read the entry in Wikipedia and the discussion on categories there doesn’t look any different to that of inheritance. I also looked at the discussion on the topic in the book “Open iPhone Development” and I still don’t get … Read more

Access parent’s parent from javascript object

Something like var life= { users : { guys : function(){ this.SOMETHING.mameAndDestroy(this.girls); }, girls : function(){ this.SOMETHING.kiss(this.boys); }, }, mameAndDestroy : function(group){ }, kiss : function(group){ } }; this.SOMETHING is what I imagine the format is, but it might not be. What will step back up to the parent of an object? Answer I simply … Read more

Hadoop on OSX “Unable to load realm info from SCDynamicStore”

I am getting this error on startup of Hadoop on OSX 10.7: Unable to load realm info from SCDynamicStore put: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/travis/input/conf. Name node is in safe mode. It doesn’t appear to be causing any issues with the functionality of Hadoop. Answer Matthew Buckett’s suggestion in HADOOP-7489 worked for me. Add the … Read more

Inheriting methods’ docstrings in Python

I have an OO hierarchy with docstrings that take as much maintenance as the code itself. E.g., class Swallow(object): def airspeed(self): “””Returns the airspeed (unladen)””” raise NotImplementedError class AfricanSwallow(Swallow): def airspeed(self): # whatever Now, the problem is that AfricanSwallow.airspeed does not inherit the superclass method’s docstring. I know I can keep the docstring using the … Read more

JavaScript: The Good Parts – How to not use `new` at all

Crockford’s book, JavaScript: The Good Parts, says (on page 114) that constructor functions should always be given names with an initial capital letter (ie. Point), and that function names with initial capital letters should only be used with constructor functions (everything else should be lowerCase). This convention helps us avoid forgetting to use the new … Read more