Archive for the ‘Functional programming’ Category

h1

Functional Programming as the Next Step from Procedural Programming.

July 11, 2014

Procedural programming languages hide goto underneath for, if and while. Functional languages hide for, if and while underneath filter, map and reduce.

Object orientated languages hide case/switch underneath method calls.

Advertisements
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

Functional Programming as the Next Step from Procedural Programming.

June 21, 2014

Procedural languages hides gotos inside if-then and looping constructs, for, while and so on.

Functional languages hide loops and selections inside map(), reduce() and filter().