An outlet for the observations, anecdotes, and other random bits of a computer programmer.

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.

Tagged with:

The Ideal Architectural Paradigm

I’ve been pondering the subject of my previous post more: creating the ideal language and environment. I realized that the Model-View-Controller paradigm is really quite ideal more than I had ever realized it. But Model-View-Controller isn’t as descriptive as I need to be to express my vision.

Now what’s so special about this? Not too much actually. Model View Controller abstracts Data (Model) from View (interface) and Controller (your program logic). However, the ideal way to implement this I realized needs a little more separation, which I’ve classified as Controllers as well.

In my ideal paradigm, I have these distinctive sets of code:

Controller

The Controller acts as your program’s main logic. This is where the interaction between Model and View resides. This is where most of the initial work of a program usually resides: the prototype has a logically functioning program, and from that initial logic grows a better interface and perhaps better data model.

Model

The Model is your data structure, and minimal data integrity methods or “floodgates.” For example, putting code in the model that ensures a Person has a positive Age is perfectly valid. On the other hand this is not the place to put code to load and save a Person to disk.

This initially sounds counter-intuitive compared to what you would expect in an object-oriented programming world. However, stealing from the ideals of the SOLID principles, the Single Responsibility Principle states that each class and method should only have one responsibility.

People have argued about whether or not this is a good idea. Anecdotally, I’ve seen complicated applications turn core classes into horrible pieces of code. I’ve seen an object start as loading from one source, adding another source, adding more and more logic, and what you end up with is a huge class that is hard to navigate, debug, and understand dependencies.

Instead I like to envision separate controllers to handle IO, which I will come to next.

Model Controller

The Model Controller is the code that takes care of the IO action of the program. For example, you may have a PersonXMLController which knows how to turn a Person into XML. The idea is to create distinct controller which know how to serialize/deserialize your Model into various formats. The Controller (aka your program) would ultimately be in charge of what bits of code to depend upon to function.

This separation has a big benefit of understanding code flow. In the former understanding of data encapsulation, the Person class would maybe start out having a ToXML method. Later we may realize we want to support JSON, so we add a ToJSON method. Turns out that this is all we need, so we stop calling the ToXML method.

This isn’t immediately apparent when looking at the Person class. It has a ToXML method, but it isn’t being used. These sorts of dependencies are at a level that developers don’t usually think about. We like to think about how classes interact, but not really how individual methods are utilized. When we see a class diagram, we’ll see that the Person class is used, but won’t notice that we have an unused method ToXML.

Not only do we not know it’s unused, we have to look at it all the time while looking at our Person class. If the XML logic were held somewhere else, we wouldn’t be looking at it unless we went to it! Additionally, if the XML logic were in its own class, class diagrams become much more useful to look at.

Additionally, I would argue that this doesn’t really prevent data encapsulation. Rather, it promotes the use of a design pattern that is useful when dealing with polymorphic types and IO: the visitor pattern.

View

The View is a representation of what your controller will do at runtime to interact with the user. For a desktop application, this may mean a window. For a web application, it may mean an Ajax-based website. For a mobile phone, it may mean a table view. For a console application, it may mean a set of input/wait scenarios with printing the result of a computation.

The idea of the View is not to actually create the user interface, but to abstract the user interface to a specific task. For example, I wouldn’t want to describe the interface at this level as being a blue, pulsating push button with width of 80 pixels and height of 20 pixels located at 14 pixels from the right, and 20 pixels from the bottom of the window. Instead, I would describe that I want a button that is the default button that is connected to a specific action.

The grunt work of actually taking this representation and turning it into actual controls with proper metrics is the work of the view controller.

View Controller

The View Controller takes a View and turns it into the most appropriate interface for the platform the application is running under. The idea behind a view controller is that this is the area that the platform specific details are sorted out: metrics to follow the platform’s UI guidelines and specific controls and colors that match the user’s theme.

The only reason to abstract the View Controller from the View is when you’re targeting multiple platforms. For example, a pushbutton on Mac OS X has a height of 20 pixels, while on Linux it is based on the theme and font.

Putting it all together

At first glance, all of the above seems like additional work over what we call the MVC architecture today, and I will admit that if you hand-code each of these elements, it is more work.

However, my vision is for the ideal language and platform, and upon contemplating what parts of programming aren’t fun, I focused on two major aspects: IO and pixel pushing.

Ideally what I’ve described as View Controllers and Model Controllers would be pre-coded and ready to use. Need your object in JSON? Just use the JSONController. Need you object in XML? Just use the XML controller? Need it in a SQL Database? Just use the SQLController. Need to customize something about that output? Put some annotations on the model or implement some events off the model controller.

Want to tweak the interface? Implement some events off of the view controller.

The idea is that writing a program shouldn’t be about agonizing over the little bits of how to store the data or how to make your window look right on both Windows and Mac OS X. It should be about solving the problem that your program is out to solve. After all, that’s where the most fun remains.

Rethinking Programming Languages

My thinking around a new programming language for the last two years has been to find a way to make a living creating development tools that I was passionate about. A few weeks ago, I met a fellow iPhone developer and during our chats, I mentioned my passion of dreaming up and working on programming languages and development tools. Our discussion turned to the theoretical idea of, “what if you could create programs by just connecting the dots?”

Initially I raised my skepticism towards the idea; it has failed so many times, and I just didn’t think any real programmers would actually want to use a system like that.

But I realized something. My goal of creating a programming language to make a living made me focus on practicality, not innovation. It narrowed my sights onto what was familiar, and was a constant tendency to steer towards the normal axioms and arguments that existing languages have defined. Is it static typing or dynamic? Is it purely functional? Is it object-oriented? Multiple inheritance? Prototype based?

The thing is I have a great daytime job, and I don’t need to focus on what I feel would make a great business. Instead, I should have been dreaming about what might allow me to actually create a unique language that might offer some innovation.

I remember back to a discussion at Evening at Adler that took place. The question was what their vision of the future was for development tools.

Wolf fielded the question first (at roughly 58 minutes in), and stated that Objective-C was a dead end unless they could remove pointers. Wil Shipley then retorted that new languages come by with the goal of getting rid of pointers, and then C [based languages] still win out. His conclusion is that the miracle language isn’t coming.

A little later in, Eric Peyton added the observation that every language that gets rid of pointers eventually adds an extension that allows interaction with C or pointers, and he rightly concludes that is the moment you know that the language did not fulfill the original requirement needed to live without C or pointers.

Originally this comment irked me, as an employee of REAL Software and naively believing that REALbasic was a great compromise; I always felt it to be a great power to be able to call directly into OS libraries. But the real reason for doing that wasn’t because I really wanted to call into system libraries from REALbasic; It was to fill in a gap that the framework didn’t provide, or a 3rd party didn’t provide. REALbasic was not a pretty language to interact with the system.

So I believe my development efforts will be devoted towards a new system. Inevitably I think each new language can be described as “like X, Y, and Z.” Hopefully my blend will be something interesting, unique, and useful.

Tagged with:

OK is OK, not Ok, or Okay

I’ve seen this error cropping up more lately. OK is meant to have both letters capitalized.

Tagged with:

Obligatory post describing the blog name

Ever since working on REALbasic at REAL Software, I’ve been off and on scheming about a new programming language and associated tools. What in the world would someone want with Yet Another Programming Languageā„¢? To me every language is presented as a balance of principles, and every language I’ve played with has yet to offer the balance for which I’m looking.

There are a series of “X but also Y” statements that I will list in the coming posts that will provide a vision of where I want to take my language. As a pet project, these goals may change over time, and there may never be a public release. Yet I love thinking about language and tool design, and my ambitions are summed up in the domain name of this blog; I want to someday be able to exclaim, “I love my tool.”

Tagged with:

I abhor Interface Builder

This is mainly regarding iPhone development using Interface builder.

I absolutely abhor Interface Builder. I literally wasted three hours last night trying to get the proper arrangement of UITabBarController, UINavigationController, and a couple table views. At the end of this exercise, I finally had what I was looking for.

But then I compared it to what it would take to write it in code.

As an exercise, I decided to scrap the Nibs and write the code:

  • Set up Tab Controller: 2 lines
  • Set up Tab Items in Tab Controller: 1 line per tab + 2 lines for array creation/assignment

I wasted three hours of time for this?

The more and more I write a new application for the iPhone, the more I realize how much UI work stays in code. The most common class to use for driving an interface is the UITableView, and there’s no way to use Interface Builder to set up a predefined list.

Interface Builder tries to go the distance, and to upper-management types it probably succeeds. But the goal of Interface Builder is to separate the UI from code using the MVC model. The inspiration was to allow UI designers freedom, and allow coders the freedom to avoid UI design. Unfortunately, Interface Builder for iPhone projects absolutely fails at this.

And thus my plea goes like this to Apple: Give us tools that don’t suck, please?

My first good experience with git

Today I embarked on a mission as I was setting up a new machine, I decided now was a good time to test the waters of git. Upon reassurances from a coworker that it was worth it, I purchased the entry level account on GitHub.

I had tried to dabble with Git before, but got turned off by the install process back when I first tried this. Mind you it was back in May of 2006. Things are much easier now, with premade packages for most systems.

I love the idea behind distributed source control, and have liked the idea of Git since I watched Linus’ Google Tech Talk. I’ve struggled with merging subversion repositories, and even recently at work we had a painful merge day.

My initial impression of GitHub is that it is an excellent resource. This isn’t shocking to me, as I’ve read great things about it.

Only time will tell if I get addicted to git, or if it’s just another fad. Subversion is a “safe” place for me to be, and git is an adventure. Hopefully it lives up to its reputation.

Welcome to my humble abode

I will hopefully be posting things that are a little more interesting in the coming days.