Thursday, August 08, 2013

Object-Oriented Programming

I remember when Smalltalk first came out, with its new programming paradigm. I even took a course (in Watford! ) but never used it for real. After  narrowly avoiding brain damage through use of COBOL at the start of my programming career, I was actually paid to write code in ML and Lisp - elegant functional programs which used recursion, had functions as first-class values and eschewed side-effects in favour of returning values.

I am finding it hard to get my head around OOP in Python. I keep expecting methods to return values (let's say I have a strong ethical bias that they should! ) but it seems we're mostly about changing the values of instance variables by side effect or assignment. I struggle to suppress nausea.

My attempts to rewrite my simple resolution theorem prover in an object-oriented style have foundered under such continuing mis-expectations: after two hours I've just managed to get the 'clause' class with its methods defined correctly. Many minutes were spent staring at the screen in plain bafflement.  Why is it doing that???

However,  I do buy into the superior modularity and encapsulation so will persist with objects till they come naturally!