Archive for the ‘Object Orientation’ Category

h1

Orthogonality V: Fixed Message, Flexible Receiver, Fixed Receiver, Flexible Message.

July 10, 2014
h1

Whats Wrong with Object Orientation in PHP.

July 1, 2014

PHP copies the basic Implementation of OO from C++, a static language, and then , seemingly noticing that it is unnecessarily restrictive, allows escape means of magic methods.

h1

Classes versus Modules

June 29, 2014

A class is a module n the sense that it is a unit of code reuse, and indeed the only one in many languages.
A module is potentially much more.
A class defines a type.
A module may define a number of types, and interfaces.

The disadvantage: modules are even less composable.

h1

Object Orientation is Inherently Dynamic

June 29, 2014

Even in static and compiled languages, therefore the despatch of a method to an object needs to be decided at run time. This is true of C++, where the _vtable is used for runtime dispatch, and also if function oanguages, where variant types ……. a variable whose actual type is decided by its current value….are used for despatch.

This raises the question of whether the best way to add OO to a static language is minimally , as C++ does, or add a whole dynamic layer as Objective C does….and if you are going down the latter route, should the layers have different or .similar syntax? Id be inclined to go for a minimal difference.

How to glue a dynamic layer to a static layer? If static code is embedded in dynamic code, some kind of dynamic despatch will be needed based on runtime parameter values. ( I’m assuming the dynamic layer will have only duck typing)

Static types passed into an embedded dynamic call will have to have their values boxed. Returns from dynamic calls , including data fetched from dynamic storage, is tricked. It can’t .be reliably unboxed into a naturally typed value,….either a runtime error will have to be thrown, or iy will have to into a variant.

h1

Functional Programming is More Than one Thing.

June 29, 2014

1 Functions aren’t allowed to have side effects.

2 Functions are first class citizens that can be passed to other functions.

3. All data is immutable.

The third and strongest stipulation means that FP sidestep the encapsulation issue in OO, because if all data is immutable, none if it needs to be protected from incorrect update.

h1

Orthogonality III Functions, Objects and the Expression Problem.

June 29, 2014

“Object-oriented languages are good when you have a fixed set of operations on things, and as your code evolves, you primarily add new things. This can be accomplished by adding new classes which implement existing methods, and the existing classes are left alone.Functional languages are good when you have a fixed set of things, and as your code evolves, you primarily add new operations on existing things. This can be accomplished by adding new functions which compute with existing data types, and the existing functions are left alone.When evolution goes the wrong way, you have problems:Adding a new operation to an object-oriented program may require editing many class definitions to add a new method.Adding a new kind of thing to a functional program may require editing many function definitions to add a new case.”

h1

Orthogonality 2: Interfaces and Implementations, and the Question of what a Language is.

June 18, 2014

Prompted by a stack overflow questioner wondering whether Object and Class are orthogonal concepts. They’re not. What are orthogonal concepts are interface and implementation…indeed, allowing interface and implementation to vary independently, ie safe polymophism, is one of the aims of OOP.

One of my conclusions is that the OO languages most people are familiar with do not reveal the nature of OO clearly. The class-object system of C++, Java and smalltalk is a convience.. Classes define both interface and implementation, and allow re use of code through inheritance. It is convenient to have interface and implementation defined in the same place, since changes to interface generally require changes to implementation. The merging of interface and implementation has drawbacks too, such as causing unnecessary recompilation. The go programimg language is able to provide the bare bones of OO without classes.

My other conclusion is that people do not , but should. apply this desirable orthogonality to languages themselves. The language qua syntax is an interface to an engine that implements a compiler, interpret.er or whatever.