A struggle for a data paradigm
I’ve been contemplating the benefits of functional programming and object-oriented programming. There’s something beautiful about the mathematical purity found in most functional programming languages *theory*, but their lack of immediate readability has always made me feel ill.
A little disclaimer here is that I am not an experienced Haskell programmer. I’ve been reading up on it, but haven’t done much more than a few simple examples. So my opinions may be ill-formed about how things are best done.
In Haskell, there’s a lack of naming your data. For example, Point is defined as:
data Point a = Pt a a
Point doesn’t have “x” or “y”, it is just a pair of values with a constructor “Pt”. The example of Point isn’t really that bad though, is it? My concern with readability comes when we look at a typical OOP example class: a Person.
From my understanding, Haskell wouldn’t provide too much help to a newbie programmer inspecting a “Person” data, because Person wouldn’t have “FirstName”, “LastName”, or “Address”. Instead, it would be (String String String) with a hidden definition that the first string is the FirstName.
Comparing this with OOPs classes, where fields have names, I’m skeptical of losing this level of clarity when looking at code.
My main struggle has been trying to figure out for my language how I want to approach:
* Definition of structure of data
* Definition of functionality (ie, groups of related methods or functions)
* Allowing polymorphism in some regard for common practical use cases
I’m trying to stay away from compromises that yield a rule that takes the structure of “X except when Y.” For example, while I’m trying to avoid letting the performance characteristics of today’s processors influence me, I would love to let my extremely high-level language run nearly as fast as if it were written in C. Because of this, I find it a cop-out to say that Integers are a class, *but you can’t subclass them and add fields to them*.
This forms a problem, because once you subclass Integer, the compiler can’t know in some cases whether or not all Integer variables are truly *just Integer* or a subclass of Integer. Because of this lack of information, decisions must be postponed until runtime, and it slows down execution speed.
This has been a bit of ramble, and probably will not be that great of a read to anyone else. However, it’s been helpful to me to write out my thoughts, so hopefully I’ll come up with a good conclusion soon.
12 months ago