Saturday, January 28, 2017

Your SOUP is Leaking - Crafting Acronyms

I've been making a lot of acronyms lately. Acronyms can help us think about, remember and communicate a concept. A good acronym, like a good word, can fundamentally change the way we understand the world. 

Until recently, civilization didn't have a word for blue. It's true! Business Insider has a surprisingly good article about how no ancient civilization had a word for blue. Even more surprising, it might be true that civilizations without a word for blue couldn't even see blue - at a conscious level. They had the same hardware, but their software wasn't tuned to thinking about blue, and therefor they couldn't see it. 

Words enable thinking and communicating. Without the word blue, how would you describe the color? You might say "it's the color of the sky," but as the lovely children's book Sky Color demonstrates, the sky has colors across the spectrum. You might point to other blue things, but it turns out in ancient cultures basically there weren't any blue things. Blue is extremely rare in nature, and no-one is going to build something they don't have a concept of.


Concepts are powerful. Concepts embodied in a word, more-so.


Picking a Good Acronym

Really, we are talking about making up a good word or a good, new-use of a word for a concept. Acronyms work because they provide a built-in mnemonic for remembering them. I find the stickiest acronyms reuse existing words such that the other meanings of that word somehow reinforce the new concept.


Traits of a good acronym:
  • Pronounceable - if you want people to use it, they have to be able to say it
  • Real Word, preferably with related meaning - the stickiest acronyms use this (see above)
  • Fun or Funny - make it playful so people play with it - and start using it
  • Phonetic - if it isn't a real word, make sure it's a least phonetic. If someone hears it, they should be able to write it down without having it spelled out.
  • Short - shorter == stickier
  • Clear Expansion - the expansion should be clear and succinct. It should embody the essence of the new concept.
  • At Most 1 Forced Letter - sometimes the expansion is 'forced' to match the acronym. Letters are left out or added to make it work. The more forced, the less sticky. 

My Favorite Case Study


  • Real word
  • Super clear expansion
  • Real-world wet vs dry makes a nice analogy between code with and without repetition respectively.
  • When I first ran across DRY maybe 7 years ago, I went "yeah!!!" Someone summed up a vague concept in my head succinctly and clearly. Ever since it's almost become a mantra in my daily practice. It's been a significant influence in my ever-deepening understanding of programming.

My Acronyms


  • ZEN code has many traits in common with Zen-buddhism sense - serene, minimal
  • The expansion very precisely describes the programming pattern.
  • In both these ways and the fact it's pronounceable and spellable, it beats out YAGNI.

EVA - Essence Vs Artifact
  • Pronounceable, short, phonetic, though not a real word
  • Clear expansion
  • I find it fun and pleasant. Maybe I've see WALLE too many times. I always here his voice when I see the word.

POET - Principle of Exposure and Transparency
  • Real word. One might say good poetry is both clear and has depth. This concept is mostly about clarity, but the concept itself has a lot of depth. I know that's a little forced, but every synergy between the real-word and the concept gives the acronym lift.
  • I forced 1 letter - the 'of' is included, but the 'and' is not.
  • Including the word 'principle' could be considered another form of forcing. All these acronyms are in some form 'principles' - why is this one so special it needs to be included explicitly? Nothing. It just works!

NINO - Natural-In, Natural-Out
  • Pronounceable, short, phonetic
  • Expansion suggests a question - what is 'natural'? This is key to the concept - get thinking about how to make our UIs as natural as possible for humans. There is no definitive answer what that means.
  • Oh so much better than WYSIWYG as an acronym. 
  • The NINO concept is bigger - a superset of WYSIWYG.

WLC - Write Less Code
  • NOT pronounceable or phonetic - I hesitate using the acronym at all. However...
  • The expansion is awesome. It's super catchy and a hugely important concept. I use it all the time in my presentations. 
  • WLC just becomes a shorthand. I -never- attempt to pronounce the acronym. ('wulk'? - ick)

SOUPShowing Our Undies Programming
  • expansion is funny
  • real-word
  • real-soup is not a good thing when mixed with computers, and it isn't when mixed with code
  • The SOUP concept is a form of leaky-abstractions - and real soup can leak :). If you've used up 'your undies are showing' jokes, you might say to a coworker 'your SOUP is leaking.' It's a nice synergy.

Go!

Go MUYOA (Make Up Your Own Acronyms)! If you've got a concept you are revisiting regularly, try figuring out a way to capture it in a word. Who knows, it could catch on and the world could see blue for the first time!

Wednesday, January 25, 2017

SOUP - Showing-Our-Undies vs Conscious-Programming

Have you ever thought, while using an application, that it should be doing this work for you? A great example is reload buttons, in particular the pull-down-to-reload UI on many mobile apps. Why should the user need to tell the app when to update its data? The app should know and automatically update its data the instant it changes.

The problem is programmers getting lazy. Programming is hard. Programming problems can be hard. And sometimes... Programmers just push the problem onto the user - they ask the user to press a reload button instead of automatically updating.

This mentality is ubiquitous. Apps everywhere expose the inner problems of the program that are irrelevant to the user. We programmers get lazy and let our undies hang out in public.

SOUP is about Quality

Laziness is not the only cause of SOUP. Real-world budget constraints and the need to get-to-market lead to cutting quality. Hard problems to solve in programming often get pushed off to the user with the conscious or unconscious justification that it's 'easy for the user to do.'

Presenting the user with an amazingly-well-designed app is the key to success, and yet it's easy for us to forget that and let 'real-world' pressures cause us to degrade the user's experience. This destroys the magic and results in a second-rate app that is much more likely to fail.

SOUP is about Culture and Normalization

The other major problem is culture. We become normalized to a certain kind of app working a certain way. We forget to stop and ask if there is a better way for the user to accomplish their task. I think spreadsheets are in this rut. Fundamentally they haven't changed since the original Visicalc. They are great for getting started, but once you have more than a few dozen cells with calculations, they become a bear to use. 

Programming tools are always improving. Often something that was hard in the 1970s is now easy in the 2010s. However, many UIs are still written as-if we were using the tools of the '70s, '80s or '90s.

Conscious Programming

The term conscious-blah is used for many things these days: conscious-living, conscious-eating, conscious-parenting, etc. Open up google and type in 'conscious a' or any other letter of the alphabet and you'll see some similar terms show up. 

I think all of these mean the same basic thing. We can't be conscious of everything all the time, but we can shine the light of consciousness on as many things as we can think of for a brief time each. It's about creating a practice of revising our assumptions, actions and thought processes periodically to make sure they still hold true. Incidentally, I've had a live-motto since well before the conscious-everything craze which sums this up nicely: question everything

I advocate for conscious-programming because there are many unfounded assumptions in programming - many artifacts which distract us from the essence of what we are trying to do. My post on Amazingly Great Design has some ideas on how to effectively focus on the essence of delivering value to users and cut through the jungle of artifacts.

Tuesday, January 3, 2017

Why CORS, Why?!?

The Problem with CORS

The App Principle: A web page is an application. In order for web pages to remain relevant in an app-driven world, web-apps must be able to do anything native apps can.

CORS breaks this principle. It restricts the information a web-app can fetch from the internet, and even if you are allowed to fetch it, it sometimes restricts what you can do with that information. Native Apps can fetch anything from the internet and do anything with it.

CORS has other problems as well. It isn’t consistently implemented across browsers. Safari 9.x interprets HTMLImage.crossOrigin differently from other browsers. CORS setup is difficult to get right and therefor it’s easy to get it wrong and actually create exactly the vulnerabilities CORS is supposed to prevent. Last, CORS returns extremely opaque errors: http://stackoverflow.com/questions/4844643/is-it-possible-to-trap-cors-errors .

Why Does CORS Exist?

I’ve been trying to understand this question for a year. My best understanding is, before CORS, web-apps were even more restricted. CORS opens up cross-domain access while preventing hacks such as:

  1. Badwebsite.com attempts to fetch your emails from gmail.com; if you are logged in with gmail.com, without cors, it could do this!
  2. CORS “taint” - I just don’t know. Is this a way to appease copyright holders? It doesn’t really prevent anything since Native Apps aren’t restricted in this way. Further, all you have to do is set up a basic web-proxy server and your Web-App could do anything with any image on the web.


CORS is the Wrong Answer

Reason #1 above is the main reason for CORS. It is legitimate from a certain perspective. There is a potential vulnerability, but it is the wrong solution. The problem is when “badwebsite.com” attempts to contact “gmail.com” it gets to freely use your cookies authenticated with gmail.com. This is something Native-Apps cannot do, so why should a web-page get to do this? And yet IT CAN - without CORS restrictions. This is insane. It’s like logging into the Gmail Native App on your phone , and then switching to MyMalicousApp and allowing it to send requests to Gmail using your login information from the Gmail app.

Beyond CORS - A Simple Proposal

It is relatively easy to solve the CORS problem now that we have separated the essence from the artifacts. We just need a way to allow websites to make external requests without giving them access to all the client’s cookies. The answer is to treat each webpage as a separate, isolated application with its own, sandboxed set of cookies for all the other webpages it communicates with.

I propose we add an option to XMLHttpRequest called ‘useSandboxedCookies’. When true, any web-application for a given domain is now allowed to make any request to any url - just like any native app could. However, all cookies used in those requests are local to that web application. This is exactly how native-apps works.

Example:

  • Alice logs into Gmail.com directly.
  • Then she goes to MyWebsite.com, which attempts a GET from Gmail.com
  • The cookies in the GET request to gmail.com are empty - the GET originated in the sandboxed cookie-space of the MyWebsite.com app.
  • So, even though Alice is logged into Gmail.com in one tab, in the MyWebsite.com tab, requests to Gmail.com appear to be coming from a new session.


This solution doesn’t actually do anything you can’t already do with CORS. All you need to do is set up a proxy server, which returns all the right CORS headers, and any website can fetch data from anywhere on the net, taint-free. However, setting up a proxy is not generally an option because it is costly and inefficient. We need a client-side solution like the one above.

Safe, Cross-Web-App Communication

My useSandboxedCookies proposal above solves 99% of the CORS problem. Since it could be added to the HTML spec in addition to CORS, we could stop there. However, there is another use-case that my proposal prevents but CORS allows, however poorly.

There are legitimate reasons why MyGoodWebsite might want to access Gmail.com using Alice's logged in credentials, and Gmail.com may want to allow it. For example, Gmail.com may want to offer a ‘log in with Gmail’ feature to third-party web apps. My proposal above prevents this since the only client-side code allowed to access Alice's Gmail.com cookies is Gmail.com’s code itself.

We need a reliable way for two client-side apps to communicate with each other. To do this, we can add a relatively simple extension to the postMessage API: allow postMessage to post a message to a URL. When this happens, the browser fetches data from the specified URL to initialize a headless client-side javascript session. That session can then send and respond to postMessages with other client-side web apps.

In the example above, MyGoodWebsite could postMessage to gmail.com/api.js. Once the gmail app loads, it sends back a postMessage that it is ready. Then MyGoodWebsite can use Gmail’s custom API for authentication. The gmail.com/api.js app can then use the user’s already-authenticated gmail.com cookies to communicate with the gmail.com servers and authenticate the third-party app.

Recap

I've outlined two proposals which superscede CORS and solve its problems:

  • Sandboxed Cookies: allow a web-app to safely fetch data from anywhere on the web without a simple client-side flag set per request.
  • PostMessage to URL: Allow any web-app to start any other for the purpose of safe communication and safe use of authenticated cookie credentials.

I have wasted way too many hours on CORS over the past few years, and I'm sure I'm not the only one. These proposals are simple to use and implement. They would open the web up to the web itself, instead of just native apps.

Does anyone know how to get the attention of the HTML5 standards committee?


Thursday, July 28, 2016

Simulations and Chosen Realities

My best guess about the future is eventually we will all be “uploaded into the cloud.” (awkward, but it gets the meaning across)

It’s tempting to say we’ll all be living in a ‘simulation’ at that point. But, I think by that point we will select a new term.

When we say ‘simulation’ we mean something somehow inferior or an approximation to the ‘real thing.’ The problem with that notion is our perception of the ‘real world’ is always an inferior approximation of the real thing.

Therefor experience and perception are always a ‘simulation’ of the ‘real world.’

If we live in the cloud, and we experience a world that is generated for us by algorithms, as long as that experience is AT LEAST as accurate as our ‘real-world’ experiences were, then I don’t think it’s fair to call it a simulation anymore.

It’s something more. It is a ‘chosen reality.’ In some sense it will be inferior since the ‘real world’ will always be more complex and nuanced than our generated ones. But the difference will be beyond our ability to perceive it. Our chosen reality will be superior perceptually. It will be the reality we want, not the one forced on us. 

Wednesday, July 6, 2016

NINO - beyond WYSIWYG

What-You-See-Is-What-You-Get was always an awkward acronym. Say "wizzywig" and people just look at you strangely. There is an amusing anecdote about the origin of the acronym on Wikipedia. I hope it's true:
The phrase "what you see is what you get," from which the acronym derives, was a catchphrase popularized by Flip Wilson's drag persona Geraldine, first appearing in September 1969, then regularly in the early '70s on The Flip Wilson Show. The phrase was a statement demanding acceptance of Geraldine's entire personality and appearance. wikipedia 

NINO - Natural-In, Natural-Out

The idea, though, is powerful. Being able to see what the output of your work looks like as you edit is a tremendous relief to the mental burden of creation. It was a hot idea in the '80s and '90s, but it is equally important, and often ignored, today in 2016.

The main problem with WYSIWYG is it is only half the equation. How we put information into an app is equally important as how we get information back out. Just as we shouldn't have to perform mental gymnastics trying to anticipate how our final output will look, we shouldn't have to wade through a bewildering array of options to get our ideas into the app.

The best interfaces are the ones that get out of the way. You know an app is well designed when you completely forget the interface and instead can dedicate 100% of your mental energy towards your creation. These interfaces tend to have two things in common.
  1. They visually get out of the way. There is less screen clutter to distract you.
  2. Their feature-set is restrained. They avoid presenting you with too many options. Instead, they are carefully designed to have the bare minimum essential tools you need to create great stuff.

Comparison: Paper by FiftyThree - a NINO App

As of version 3, Paper by FiftyThree extended its excellent sketching app with note taking features. They introduce a brilliant set of natural gestures for formatting your notes that required zero screen clutter.


Comparison: Microsoft OneNote - a very Un-NINO App

By contrast, consider OneNote. It has a bewildering array of features, buttons, icons, widgets and text. My note in the screenshot below has a short title and one line of text. It is oppressively dominated by the rest of the interface.

Exocranium

Our devices, phones, tablets, computers, watches and more and more becoming extensions of our mind and body. I once heard a description of smart-phones, particularly with notes and productivity apps, as our exocranium. These devices and apps are becoming our brain outside our brain. The better the app, the more natural an extension of our mind and body. The better the app, the more natural its inputs and outputs - the more NINO it is.

Sunday, June 12, 2016

WLC - Write Less Code

Given two solutions to a problem, the one with less code is usually better. 

Plite of the Programmer


Our job as programmers is to deliver value to customers. We deliver value by identifying needs, translating them into requirements, and writing code to meet those requirements. The difficulty of the task is compounded by the fact that requirements are constantly, unpredictably changing. Even after we finally ship, the story isn’t over. Code is a living thing that must be maintained, usually well beyond anyone's expectations.

Over the lifetime of a product, we will edit code 10x more than we write code, and we will read code 10x more than we edit it. Each token we add to our code may be read over 100 times. Every token we save could save up to 100 token-thoughts and 10 future edits. The key to our productivity is writing less code.

Why Count Tokens?


Tokens are the smallest meaningful element in code. Tokens are a more objective measure of code size since lines can have any number of tokens. Measuring tokens also ignores white-space and comments. Last, measuring tokens doesn't penalize using clear names. ‘Occupations’ is just as good a name under the token metrics as ‘occus’ or other hard to understand abbreviations.

Don't abbreviate words. Saving keystrokes only saves writing the code. It doesn't save edits or reading. Abriviations make reading harder. Since reading code dominates our time, abbreviations are a losing proposition. Only use shortened words if the shortened version is used at least as commonly in speech.

Measuring tokens is a simple, effective metric that lets us make decisions quickly and get on with solving problems and delivering value.

Why ‘Write Less Code’?


It's a simple concept with depth. Amateurs and masters both can apply and learn from it. A more accurate metric might be refactorability. We spend most of our time refactoring code, not writing it. Refactorability is the code-quality metric. It can be broken down into code size, clarity, and structure. Of the three, size is the only one that can be objectively measured, and while clarity and structure are important, both are usually improved by reducing code size. Refactorability is not something a novice will understand. ‘Write less code’ is an excellent guiding principle for all programmers.

How to Write Less Code


All other good coding practices essentially reduce code size. Two of the most important, and most often violated coding practices for reducing code-size are DRY and ZEN.

DRY


Don't. Repeat. Yourself. Don't you dare repeat yourself ;). The most problematic artifacts I've seen, both from novice and expert programmers, is code repetition. The big problem with repetition is it compounds the complexity of refactoring. Not only do we have to fix two or more things instead of one, but we have to understand how they all interact. Plus it bloats the code-base making it hard to understand.

DRY is a subtle art. The first, obvious level is ‘don't copy-paste your code,’ but as we level-up, we start to realize anything gzip might compress potentially violates DRY. The ultimate measure is, as always, refactorability. How many code-points need to change for a common refactor? Is there a way to reduce repetition to reduce the complexity of refactorability?

ZEN


Build it with Zero Extra Nuts (more commonly known as YAGNI). Because it is impossible to
predict future requirements, adding anything to our code that isn't strictly necessary to meet current requirements is not only a waste of time now, but it will haunt us for at least 10x future edits and 100x future reads.

It is fun to add cool features, but the master knows the only thing that matters is delivering value to the customer.

Write Less Code - Formalized


My hypothesis, and my experience, comes down to this:

  • Given two different functions, modules or programs
  • that both meet or exceed the problem's requirements, both correctness and performance
  • the one with less tokens is always better
  • as long as it doesn't sacrifice clarity.

The Practice of Writing Less Code


As with everything in life, writing less code is a practice. There is no point where we will master it. There is always another layer of deeper understanding. We are always learning how to make our code DRYer and more ZEN. We must constantly be looking for ways to meet requirements with less code.

Saturday, February 6, 2016

ZEN (YAGNI) and Building In-House Frameworks

ZEN - Zero Extra Nuts. ZEN code is minimalist. It is relentlessly focused on solving exactly the requirements and nothing more. (3)
Write only what you need. It’s a profound concept. Engineers can’t help but overbuild things. For some reason this is inherent to being an engineer. In physical engineering, overbuilding is mostly an issue of up-front cost in terms of extra time and material. In software, there is also a substantial ongoing expense. The maintenance cost of code is related to its total size (1).

ZEN vs DRY


ZEN implicitly includes DRY (don't-repeat-yourself). Code repetition is one of the most pernicious forms of "Extra Nuts." Learn more about the subtleties of code repetition here.

ZEN and Frameworks


Minimizing the size of the code-base is an important goal. Using standard abstractions like functions and classes can reduce the total codebase size. This isn’t the same as building a framework.

What is a Framework?


A framework is a module. At their heart, modules are about encapsulation. Modules have an external interface and internal implementation. Better modules have simpler interfaces and more-isolated implementations.

Frameworks are different from other modules because they are designed to be used across multiple applications. Frameworks must be the best possible modules. In order to work across multiple applications, a framework must have the simplest possible interface and the most isolated implementation. Frameworks should also have their own codebase and be packaged for easy reuse.

Why Do We Build Frameworks?


If ZEN were the only value, we would never build frameworks. By the time we’ve built a solution to the required specs, we ship. End of story. That’s what ZEN tells us to do. If we only followed ZEN, our applications would include operating systems, drivers, database, compilers and every other part of our dev and runtime stack. In other words, each new application would be enormous and have a fraction of the capabilities we enjoy today.

I said above that the maintenance cost of code is related to its total size. When we measure the size of code in an app we do not include frameworks. This is for good reason. The complexity a module adds to an app is proportional to its interface size and leakiness of its implementation. Frameworks are the best of modules. Their leakiness is minimal and their interface refined. A framework with millions of source-tokens may only add a few thousand tokens worth of complexity to a project using it. 

Are In-house Frameworks Worthwhile?


Clearly using other people’s frameworks is a big win. You get 100x or more leverage in terms of complexity. You only have to maintain your application’s code base and you get all the framework’s capabilities for a very modest price. Building a framework in-house at first doesn’t seem like a good idea. The total code-size you have to maintain will increase when you take an application and factor it into an in-house framework plus the rest of the app.

We talked about how application code-size is properly measured, but we haven’t talked about how that value relates to maintenance. Maintenance costs are proportional to complexity, and complexity’s relationship to code-size is non-linear. If you double the code-size, you will more than double its complexity (2).

Realizing that code-complexity is non-linear in code-size reveals why it makes sense to write frameworks even if they only have one app using them. If the application’s code-size is N-tokens before we factor out the framework, and let's assume that we can cut the application code in half by factoring out the framework. There is always some overhead in writing a framework due to interface and abstraction code. We’ll assume that overhead is 10%.

After the split, both the framework and app will have (1.1 * N/2) tokens, or (1.1 * N) total. For simplicity, our final assumption is a complexity-to-size factor of O(N2):


  • Complexity before split: N2
  • Complexity after split: 0.6 * N2
    • App: (1.1 * N/2)2
    • Framework: (1.1 * N/2)2
    • Total: 2 * (1.1 / 2)2  * N2


That’s a 40% savings! Granted, I made the favorable assumptions, but clearly it is possible to have large savings. Further, you don’t have to limit yourself to making just one framework. There are diminishing returns, but in my experience I've still found improvements with over 10 in-house frameworks.

Once you have a good framework, it is possible to re-use it in other apps. Then the savings really start to compound. If we assume just two apps, using the example above, the complexity savings increase to 55%. You also get code-size savings as well - about 18%.

When to use 3rd Party Frameworks


Obviously you should use an existing framework, if one exists, instead of writing your own. Right? Well, when evaluating the merits of a 3rd-party framework, there are a lot of things to consider. 

Let's start with technical aspects:


  • Does it do what you need it to do?
  • Does it meet your performance goals?
  • Is the source open?
    • Can you look at the source code? No matter how good the documentation is, there are always questions it doesn’t answer. If the source is open, you can get definitive answers. If not, you will be flying blind.
  • Is it OpenSource?
    • Can you contribute improvements back to the project?
    • How clear are the maintainers about what sort of contributions are acceptable?
    • Can you fork the project? This is only a last resort, but it is nice to have as an option. If you expect to fork early, you will be mostly maintaining your own, in-house framework. The problem with this is it is a codebase no-one in your organization knows well. Seriously consider writing your own in-house framework from the start.
  • How difficult will it be to switch frameworks later? 
    • How much of your code will directly interact with the framework?
    • If you are picking a UI framework, most of your code will be tied to that framework. Changing frameworks later probably means rewriting the app from scratch.
    • If you are using an encryption framework, like, say, md5, only a line or two of your app will use it. Changing that framework later is usually trivial.


There are also important non-technical aspects to evaluate:


  • Momentum. Usually there are multiple options for the same type of framework. Eventually, some die out and some thrive. It’s a good idea to use a tool like Google-Trends to determine which projects are thriving and which are dieing. If a framework dies, you may need to fork it to maintain it, and then you are back to maintaining an in-house framework.
  • Direction. 3rd party frameworks evolve outside your control. It is important to not only assess the current technical merits of the framework, but also, where is the framework going? What values and goals does the controlling team have? What values and goals does their organization/funding have? If your use-case is not squarely in their target use-cases, seriously consider looking elsewhere.

When to Write an In-House Framework


There are two main questions to ask each time you consider building a framework:


  • Is it the best of modules?
    • Is the interface simple?
    • Will the implementation be well isolated and minimally leaky?
  • Is there a reasonable chance you’ll reuse the framework on other projects? ZEN argues you should be cautions making assumptions here, but if you think there is a > 90% chance you’ll reuse it even once, this can be a big factor.


If you haven’t written a line of code yet, should you even consider writing a framework yet? You should never write something unless you know for certain you will use it. Don’t build more than you immediately need for current requirements. In this, you should always follow ZEN.

However, when looking at current requirements, it is reasonable to ask how you are going to meet them. As you do, you will be considering how to modularize your implementation. If you are doing an agile approach, this design work will happen in code as you go. If not, you may be doing some up-front design. Either way, there will be a point where you have modules.

As soon as you start to form modules, you should start thinking about if the modules make sense as a frameworks. If the answer is “yes” to both questions above, then package up the module immediately, put it in its own code-base, and declare it a framework. The sooner you do it, the sooner you can reap the simplification rewards. Once you do, keep following ZEN. Continue to only add functionality as you need it.

Frameworks Clarify Thinking


Frameworks have another benefit beyond reducing complexity. Once you have isolated part of your code in a framework it takes on a life of its own. It has purpose beyond just serving the current app (though it should still be driven by that app's requirements ala ZEN). A framework begs for clarity in its purpose. By drawing a line between your app and your framework you have to start thinking clearly about what belongs where. 

Don't expect to nail the framework's "purpose" in the first pass. Your framework will evolve as ZEN drives it. Over time, though, clarity will emerge and you will have a new, powerful tool, codified in your framework, but also in your mental toolbox for solving and thinking about programming problems.


Writing Frameworks is Hard - and Worthwhile


I don't want to make this seem easy. Writing the best of all possible modules is hard! However, it is a learnable skill. You are only going to learn a skill be practicing it - a lot.

And what about ZEN? Writing frameworks and ZEN are not in conflict. You can write frameworks while observing ZEN. After all, DHH, one of the strongest proponents of ZEN, wrote Ruby on Rails.

Footnotes

  1. I measure codebase size in parse tokens rather than lines of code. Though still only an approximate measure, they are much better than LOC. They are the smallest meaningful unit in code. LOC measures several aspects of code which are ignored by the compiler including comments and whitespace.
  2. Codebase complexity can be understood in terms of graph-theory. Complexity comes from the number of possible interactions within the code. In the worst case, if you have N bits of code (tokens), you can have as many as N * (N - 1) or roughly N2 possible interactions. In practice the relationship between code-size and code-complexity is somewhere between O(Nk>1) < CodeComplexity(N) < O(N2).
    Modular design is all about reducing the number of interactions a chunk of code has with the rest of the code-base. This is how modules help reduce complexity.
  3. ZEN is roughly the same concept as YAGNI, but unlike the latter, both the word 'zen' and the expansion, 'zero extra nuts' convey meaning. We can say some code needs to be more 'zen,' and others will understand. To say code needs to be more 'yagni' holds no meaning for most people.