Sunday, March 2, 2014

Unwinding Complexity

keep coming back to complexity. It underlies so much of what software developers do for a living. Building a big, sophisticated software system is all about juggling millions of little moving parts. When it goes well the results are organized, stable and hopefully incredibly useful. We strive to build software that people can rely on to make their lives easier.

Building software is like building anything else, except that few people can see the final results. They can see the interface, feel the performance and sense the stability, but rarely can they stand back and appreciate all of the peices. This allows programmers to hide a tremendous amout of dirt in the system from their stakeholders. Given the high expectations and short timeframes, programing has become increasingly about sweeping dirt under the 'rug'. People chase every possible shortcut, even when they know the long-term consequses are dire. Added to those problems, deep analyse of any business reveals lots of skeletons in their closets plus a raft of inefficiencies that have built up over history. Rarely does a development project clean up the mess it finds, rather it just lifts the rug a little higher and sweeps more dirt under it.

Thus the millions of little parts in a project aren't just code and configuration. They are the huge collection of what is essentially artifical complexity, both internally and externally, that has built up over time. There is never enough time to get it cleaned up and reorganized, so the results just contribute to the ever growing organizational backgroud noise that increasingly hampers progress. Of course it is far worse for larger and older organizations, but even little companies have their messes. 

You'd think that a big new development would be the perfect time to clean house but no one ever leaves the time to get it done. No one ever has the energy. The inevitable consequence is that the dirt builds up layer upon layer. Decades go by while the artificial complexity grows into an ever larger Gordian knot. In many ways our rush to automate with software has just made these problems worse. Computers can simplify, but they can more easily obfuscate, and the way we build software these days, the latter is the most frequent occurrence. 

At some point this complexity exceeds the ability of people to deal with it. These days most large non-technical organizations just flitter around that threshold, spending most time barely in control. The natural response we have to this is to try to tighten down the processes, usually with new rules, but these rules just add more rope to the growing knot. The core, all of those skeletons and dirt, almost never gets touched. The ball of complexity just grows larger. This vicious cycle is what facinates me. Surely there is some way to reverse the cycle; to unwind the problems?

In the early days of the Industrial Revolution people were automating manual tasks in a rather ad hoc fashion. New inventions were siloed, and then thrown into use to deal with isolated aspects of the existing labor. In time, people like Henry Ford approached the problem from a broader perspective. They set the stage for modern factory production. Well-organized 'lines' of production that smoothly turn out works of high precision. An individual craftsman may put more skill and care into handcrafting their work, but their individuality shows in the output. Each peice is slightly different. Factories took some 'soul' out of the work, but they brought down the price while increasing the quality. This type of tradeoff is now well-established for a lot of manual work. We know how to mass product things like cell phones and build incredibly sophisticated projects like skyscrappers. In a sense we can use scale to minimize the overall complexity to a point where we can control quality. But all this knowledge onlyapplies to physical things.

Organizational processes and software both share the same property that the are crafted mostly with intellectual effort, not physical effort. The people doing this work these days operate as individual craftsmen, each infusing the output with our own personal stamp. Added to that, we have no way to measure the quality of our intellectual effort on either the small scale or the large one. We don't know if the results have been well-thought out or are half-baked. Anyone can propose an idea to fix a process problem, but there is no way to measure the quality or depth of that idea. It may fix the issues or it may be misguided and make them worse. There is no way to tell.

What I keep wondering about complexity is whether or not it really is possible to unwind it correctly, in a manner that is controlled? Could I, for instance, actually fix some of the deep company problems that I've run across? Not just in the software, but also in the organization?

My best guess is that complexity can be unrolled, and that it can be unrolled in a controlled process that is predictable. I keep thinking about what the equivalent of a factory line might be in this case. The problems roll in on one side and the appropriate thinking rolls out the other. In between, any and all of the necessary intellectual work that needs to be completed is done in an albeit uncreative, but very reliable way. That is, there is some definiable process that one should be apply to intellectual pursuits that eliminates artificial complexity by essentially normalizing the work in thinking to a finite number of defined steps. To clean up the mess, you just need to correctly follow the process. It might be time-consuming, but it is also deterministic. Once the work gets stripped down that way, it should gain intellectual precision but of course it loses that individual touch. It clearly wouldn't be as fun or creative as intellectual work is today, but the results would hopefully make up for that.

Industrialized thinking would be a much larger leap forward than was factory automation. We could, for instance, tidy up our governmental organizations so that for once they operate efficiently and with the least cost. That probably wouldn't decrease our taxes, rather our countries could provide more services at a much higher quality. The costs incrued by a bedraggled bureaucracy would finally be minimized instead of gradually eating more money for less output. Companies would be freed from their internal fog to really be able to compete well in their markets. Costs would be controllable.

I can definitely see how these ideas could change our world, but are they really possible? It could just be that the invisible nature of thinking negates this possibility in the same way that software isn't visible to most people. We can't yet measure what we can't see. It is this indirect link that binds building software to any possible industrial thinking concept. How do you guarantee the quality of intellectual output? You can't just hire anybody for quality control, and you can't even be assured that the people you hire are really seeing things as they truely are. These types of problems already dominate software development.

So far I don't have any decent answers for this problem. Some people might suggest documentation, but I've seen that fail too often as an approach. People don't proof read very well, and when they do it is usually for syntax not concepts like semantics or higher. To industrialize, the output has to be checkable in some way that would occur in an intermediate stage, long before it is too late. It would have to be reliable.

One approach that might have merit is to trace all things backwards. Start at the end and traverse back to the start. That is, if you wanted to simplify something like the laws of a country, you start tracking those that are actually being applied. Where they depend on other laws for properties like consistency or integration those get added into the mix as well. At some point you'll end up with a denormalized tree (dag actuallly) with what's currently in practice. Normalized these relative to a consistent underlying set of principles and the results should hopefully be a considerably smaller sets of 'clean' laws that could effectively replace the older ones. Even from the description you can tell that this whole process sounds rather tedious and boring, but if it really has those qualities and it is complete when done than it is likely the sort of industrialized approach that we are looking for. It might not be as fun as crafting endless new laws on top of each other, but compressing the overall complexity of the legal system would make it far easier for people to get fairer resolutions to their problems. Some lawyers might not be happy about that, but it would benefit society.

Roughly, it took about a hundred years for manual automation to get industrialized and it probably took another one hundred to get to today's level of precision. Cleaning up our disorganizations and ad hoc thinking processes will most likely follow suit at some point in the future. It may take generations, but it is likely inevitable. Until then, the only ways to clean up artificial complexity are time and luck, and pehaps the occasional brilliant insight.

Friday, February 21, 2014

Levels of Code

Throwing together computer code isn't that tricky, but doing it well enough that it's usable in a serious enviroment requires a lot of work. Often programmers stop long before their code gets to an 'industrial strength' level (5 by this classification). 

For me the different levels of code are:

        1. Doesn't compile
        2. Compiles but doesn't run correctly
        3. Runs for the main logic
        4. Runs and handles all possible errors
        5. Runs correctly and is readable

And the bonus case:

        6. Runs correctly, is readable and is optimized

The level for any peice of code or system under consideration is it's lowest one; it's weakest link. Thus if the code is beautifully readable but doesn't compile then it is level 1 code, not level 5.

Level 1 can be random noise or it can only be slightly broken, but it doesn't matter. It wouldn't even be worth mentioning except that people sometimes check this level of code into their repositories, so it deserves its own level. Level 2 isn't much of an accomplishment either, but a lot of level 2 code actually makes its way into software unnoticed.

Level 3 is where most programmers stop, they get the main logic functioning, but then fail to deal with all of the problems that the code can encouter as it runs. This includes not checking returns from lower level calls and not being able to cope with the unavailability of shared resources like databases.

Level 4 involves being able to correctly deal with any type of external failure, usually in a way that doesn't involve a crash and/or manual intervention. Networks, databases, filesystems, etc. can all become unexpectantly unavailable. The code should wait and/or signal the problem. Once the resource is available again the code should automatically return to using it properly. Any incomplete work should be correctly finished. If the downtime period is short, except for a log entry it shouldn't even be noticed.

Level 5 is somewhat subjective, but not as much as most people might assume. Realistically it means that some other qualified programmer can come along and quite easy figure how to enhance the code. That doesn't mean the code will remain at level 5 after the changes, but it does mean that the work to change it won't vex the next coder. If they understand the domain and the algorithm then they will understand where to insert the changes. Indirectly this also implies that there are no extra variables, expressions or other distractions. It is surprising how little level 5 code is actually out there. 

Level 6 requires a deep understanding of how things work underneath. It means that the code meets all of the other levels while doing the absolute minimum amount of work and it also takes advantage of techniques like memoization when it's both possible and practical. Extremely rare, it is often the minimum necessary for code to be described as 'elegant'. Failed attempts to reach level 6 can result in the code dropping several levels, sometimes all of the way back to level 2, thus the expression about premature optimization being the root of all evil.

Level 4 code is often good enough, but going to level 5 makes it possible for the code to be extended. Level 6 is a very worthwhile and achievable goal, often seen within the kernel of sucessful products, but it's incredibly difficult to maintain such a high standard across a large code base.

In this classification I haven't explicitly dealt with reuse or architecture, but both of these are absolutely necessary to get to level 6 and certainly help to get to level 5. Readability is clearly impaired if similar chucks of code are copy-pasted all over the place. A good architecture lays out the organization that allows the underlying sections of the code to efficiently move the data around, which supports level 6. In general, disorganized code usually converges towards level 2, particullarly if it is under active development.

Sunday, February 16, 2014

Principles

This post http://tekkie.wordpress.com/2014/02/06/identifying-what-im-doing/ by Mark Miller really got me thinking about principles. I love the video he inserted by Bret Victor at http://vimeo.com/36579366 and while the coding examples in it were great, the broader theme of finding a set of principles really resonated with me. I've always been driven to keep building larger, more sophisticated systems, but I wasn't really trying to distill my many objectives into concrete terms. Each new system just needed to be better than the last one (which becomes increasingly hard very quickly).

Framing my objectives as a set of principles however sets an overall theme for my past products, and makes it easier to be honest about their true successes and failures. 

As for principles, I no doubt have many, but two in particular drive me the hardest. One for the front end and another for what lies behind the curtains. I'll start with the latter since to me it really lays the foundations for the development as a whole.

Software is slow to write, it is expensive and it is increadibly time consuming. You can obviously take a lot of short-cuts to get around this, but the usefulness of software degrades rapidly when you do, often to the point of negating the benefits of the work itself. As such, if you are going to spend anytime building software you ought to do it well enough that it eventually pays for itself. In most instances this payoff doesn't come by just deploying some code to solve a single problem. There are too many development, operational and support costs to make this an effective strategy. It's for exactly this reason that we have common code like operating systems, libraries, frameworks, etc. But these peices are only applied to the technical aspects of the development, what about the domain elements? They are often way more complex and more expensive. What about the configuration and integration?

My backend priciple then is really simple: any and all work done should be as leveraged as much as possible. If you do the work for one instance of a problem then you should be able to leverage that effort for a whole lot of similar problems. As many as possible. For code this means 'abstraction', 'generalization' and eventually 'reuse'. At an organizational level this means some architectural structure that constrains the disorganization. At the documentation level this means that you minimize time and maximize readership.

Everything, at every level, should be designed and constructed to get the upmost leverage out of the initial effort. Every problem solved needs to viewed in a much larger context to allow for people to spot similar problems elsewhere.

Naysayers will invoke the specter of over-engineering as their excuse to narrow down the context to the absolute smallest possible, but keep in mind that it is only over-engineering if you never actually apply the leverage. If you manage to reuse the effort, the payoff is immediate and if you reuse it multiple times the payoff is huge. This does mean that someone must grok the big picture and see the future direction but there are people out there with this skill. It's always hard for people who can't see big pictures to know if someone else really does or not but that 'directional' problem is more about putting the wrong people in charge than it is about the validity of this principle. If the 'visionary' lacks vision than nothing will save the effort it is just doomed.

When a project has followed this principle it is often slower out of the gate than a pure hackfest. The idea is to keep building up sets of larger and larger lego blocks. Each iteration creates bigger peices out of the smaller ones which allows for tackling larger and larger problems. Time no longer is the enemy, as there are more tools available to tackle a shrinking set of issues. At some point the payoff kicks in and the project's capabities actually get faster, not slower. Leverage, when applied correctly, can create tools well beyond what brute force can imagine. Applied at all levels, it frees up the resources to push the boundaries rather than to be stuck in a tar pit of self-contructed complexity. 

My principle for the front end is also equally effective. Crafting software interactions for people, whether it be command line, a GUI or a NUI, is always slow and messy work. It is easily the most time-consuming and bug prone part of any system. It is expensive to test and any mistakes can cost significant resources in managing the debugging, support, training and documentation. A GUI gone bad can suck a massive whole into a development project. 

But an interface is just a way of hanging lots of entry-points of functionality for the users to access. There is a relative context to save the users time from having to respecify stuff and there is often some navigational component to help them get quickly from one peice of functionality to another, but that's it. The rest is just litterally window dressing to make it all look pretty. 

So if you are going to build a GUI, why would you decompose everything into a billion little peices and then start designing the screens from a bottom up perpective? That would only insure that there was extra effort in making endless screens with nearly the same bits displayed in a redundant manner. You can't design from the bottom up, but rather it must be from the top down. You need to look at what the users are really doing, how it varies and then minimize that into the smallest, tightest number of entry-points that they need. An interface built this way is small. It is compact. It contains fewer screens, less work and less code. It takes the users quickly to what they need and then gets them back to a common point again in as little of effort as possible. It's less work and they like it better.

A system with hundreds of scattered screens and menus is almost by definition a bad system, since it fails due to its size to be cohesive; to be usable. Functionality is useless if you can't find it. Sure it is easier to write, you don't have to agonize over the design, but that lack of thought comes with a heavy price tag.

Programmers build GUIs from the bottom up because they've been told to build the rest of the code from the bottom up. But for an interface this is backwards. To be effective, the interface has to be optimized for the user, and of course this will make the programmer's job far more difficult, but so what? Good coding is never easy, so forcing it to be that way simply dumps the problems back onto the people we are trying to help. The system should be easy to use even if that means the code is harder to write. And if the work is hard, but relatively redundant than that is precisely what the first principle is for. The difficult bits should be collected together and encapsulated so that it can be leveraged across the entire system. So for example, If the coders spent extra time generalizing a consistent paging mechanism for a screen, then that same code should be applied to all screens that need paging. Ten quick, but flakey paging implementations is ultimately more expensive and very annoying for the users.

It's hard to put a simple name to this second principle, but it could be characterized by stating that any people/machine interfaces need to be designed in a top-down manner to insure that they are optimized for the convience of people rather than for the convience of the construction. If people are going to benefit from software then they have to be the higest priority for its design. If money or time is a problem, less stuff should be delivered, but the priority must be people first.

Both principles echo strongly in my past works. Neither is really popular within the software development communities right now, although both frequently get lip service. People say they'll do both, but it is rare iin actuallity. Early agile, for instance, strongly focused on the end users but that gradually devolved into the stakeholders (management) and generally got pushed aside for the general gameification of the development process. These days it is considered far better to sprint through a million little puzzles, tossing out the results irratically, then it is to insure that the work as a whole is consistent and cohesive. Understanding the larger context is chucked outside the development process onto people who are probably unaware what that really means or why it is vital. This is all part of a larger trend where people have lost touch with what's important. We build software to help people, making it cheap or fun or any other tasty goal is just not important if the end product sucks. 

Saturday, January 25, 2014

Rights of the Modern Age

Our world just keeps on changing and with all of these changes we must keep on updating and asserting our basic human rights. To this end I suggest a couple of new rights that I think we all possess:

We own the intellectual property rights to all our interactions with the world. That is, if we buy something from a store, we own and control any data generated from that interaction which includes us as individuals. The store can own any data that shows they sold a bunch of stuff to a collection of anonymous people, but if that data singles anyone out, in any way or shape, then that person owns it. That right not only includes stores but governments and healthcare as well, in fact any and all interactions that we have as we creatively engage with the world around us. If it is specifically about a person then clearly they should own the rights to it and it can't be used or even collected without their explicit consent.

Given that science seeks to enlighten us with their research, we own the right to not accept anything they say unless they also present the raw, unedited data that they gathered to back up their analysis. I don't want to see or hear about any work unless the process to compile it was completely transparent. If the data really shows what their analysis claims it shows, then they will have no problems releasing two things: the paper explaining the analyse and any data (including unused data) that was gathered to investigate the claim. Given the increasing sophistication of mathematical approaches for extracting conclusions from data, any claim presented without data should be considered untrustworthy and quite possibly propaganda designed to obscure rather than the clarify the underlying truth. Papers without data should not be considered 'scientific works'. Science is about discovering the truth, not about making one's career.

We all own the right to be different. We are all unique and should value this. Diversification is a key strength of our species so we shouldn't be alike, think alike or follow blindly. Any person, organization or process that is attempting to 'clean up our differences' is not acting in our best interests. They are violating our fundamentals rights to be different and to remain that way forever. A homogeneous world is just one sad shade of grey; we know this and all need to incorporate it into our philosophies of getting along together. Different is good, even if it can be annoying at times.

That's it for now but I'm sure as the next wave of madness hits us I'll figure out some other basic tenets of existence.

Monday, January 13, 2014

Controlling Complexity

"Make everything as simple as possible, but not simpler."

Albert Einstein

Within a context every object or process has a given amount of complexity. As Einstein said there is a base level of complexity that cannot be circumvented, but there are at least two types of complexity: inherent and artificial. There are many other names for these and many other ways to decompose complexity into subparts, but this simple breakdown clarifies a simple property of complexity, that is that under specific circumstances many complex things can be made simpler.

Simplification can occur for many reasons, but most commonly it is from removing artificial complexity. That is, the complexity that is piled on top for reasons like misunderstandings, short-cuts, disorganization, self interest and lack of understanding. Note that all of these are directly attributable to human intelligence, and with that we quite easy define 'inherent' complexity as the lower limit that is bounded by our physical world in the sense that Einstein really meant in his quote. Also note that I started the first sentence referring to context. By this I actually mean a combination of spacial and temporal context. Thus, things can get simpler because we have learned more about them over time or because we are choosing to tighten the boundaries of the problem down to avoid issues within the larger context. The latter however can be problematic if done under the wrong conditions.

For reducing complexity there is also the possibility of simplification by encapsulation, that is some part of the whole is hidden within a black box. The context within the box is obviously simpler, but the box itself adds something to the larger complexity. This works to some degree, but it can only be piled so high before it itself becomes too complex.

Often people attempt to simplify by reducing context, essentially "wearing blinders", but they don't follow through with the encapsulation. In that case, it is extremely unlikely that any underlying changes will actually simply things, instead they spawn off unexpected side effects which themselves are just added artificial complexity. This often goes by the name 'over simplifying' but it's a misnomer in that while the change within the context may be describable as a 'simplification' it isn't really.

Within this description we can also add abstraction as a means of simplifying stuff. In general it's really just a larger pattern or relationship manifested over a larger space of objects or processes, but it's ability to help comes from the fact that it organizes things underneath. Organization and sometimes categorization relate similar things together by properties, so exploiting these relations reduces the complexity of dealing with the individual parts. Abstraction thought has it limits in that it acts much like a bell curve. Some abstraction reduces complexity, increasing to a maximum point, then falling off again because the abstractions are too general to be applied for organization. Still a powerful abstraction, at a maximal point, can cut complexity by orders of magnitude, which is way more powerful than any other technique for controlling complexity. It's not free however in that considerable fewer people can deal with or understand strong abstractions. That leaves them subject to being misunderstood and thus becoming a generator of artificial complexity.

There are many ways to reduce or control complexity, but there are many more ways for people to introduce artificial complexity. It's this imbalance that is driving our modern age to the brink of serious trouble. So often people cry "simplification" while actually making things worse, and it isn't helped by living in an age where ability to spin the facts is valued far more than the ability to get things done well. Quantity and hype constantly trump quality and achievement.