follow me on Twitter

    Blog has moved to, see August, 2008 on new site

    Blog entries for August, 2008

    This post moved to

    Chris mentions JavaScript embedding using SpiderMonkey.

    When GNOME first started out, there was much talk of using Guile as an embedded language. The concept was similar to the architecture of Emacs, Firefox, or all the games using Lua (such as World of Warcraft).

    I would define an "embedded" language as one that doesn't come with a platform. It's small and easy to glue together with an app written in C or C++. It uses the same platform as the app. If the platform has an introspection capability like XPCOM or GObject-Introspection, then the platform can be exported to the embedded language in an automated way.

    At some point, and I was one of the people to blame for this, we changed the focus of the Linux language discussion to grand unified schemes involving component technologies and virtual machines. The result is that too much desktop stuff is still written in C.

    A "C/C++ core plus embeddable language" architecture for an application has many pragmatic advantages.

    • Higher layers of code such as UI code are so much easier in a dynamic "scripting" language.
    • Proven to be practical and scalable for huge apps such as Firefox and World of Warcraft, even with dead-simple languages such as JavaScript and Lua.
    • No platform silos. In a GNOME app, the embeddable language uses GIO, GTK+, GStreamer, Clutter, or whatever you are using - it does not have its own http stack and everything else.
    • You can choose to write each part of the app in the easiest language; some stuff is easier in C/C++.
    • Sandboxable / well-modularized. The interpreter is generally an object that can be destroyed; no heavy language runtime or VM takes over the entire app.
    • Embeddable languages don't seem to create a huge jump in memory footprint, for whatever reason, so they are still sensible for "swarm of many processes" environments like GNOME and KDE that multiply any per-process overhead by a significant factor.

    (There are advantages to the heavier full-platform languages also, but I'm guessing everyone knows them already so I won't make a list.)

    JavaScript is a great choice for an embedded language. I did not realize at first that SpiderMonkey has no dependencies; it is not tied up with the rest of the Mozilla platform (XPCOM, etc.), it's completely standalone. And most programmers understand at least some JavaScript already.

    There are some problems right now, for example there's no standard packaging and .pc file for jsapi.h/, so it's hard to make an app build on multiple distributions unless you suck in an internal copy of the library.

    It's necessary to add a couple things to JavaScript before it's truly usable; most notably, some kind of module system. I'm not sure SpiderMonkey itself should have that though - it starts to define a platform and make the language "not embedded". Maybe modules are introduced by higher layers (in fact xulrunner adds a module system if you use the whole xulrunner platform).

    I don't mean this as a SpiderMonkey advocacy post, though we're using it successfully at work. Other options are the WebKit JavaScript engine, Guile, Lua, Tcl, etc.

    My main point: the "C/C++ core plus embedded scripting" architecture is a very smart way to write an app, and doesn't have some of the real downsides of heavier platforms.

    This post moved to

    Most people know about the price/earnings ratio. If you want to learn one more thing about financial numbers, return on equity could be a good choice.

    Return on equity is annual profit divided by net worth. If you have $100 in net worth, and make $10 in annual profit, then you are making 10% ROE. If you think you can make a 15% return elsewhere, you could sell your assets to net $100 in cash, and invest in the 15% return elsewhere.


    Depending on the nature of the business, maybe you can add more net worth and make more profit. If you're making $10 on your $100 tied up, maybe you can add another $100 and now make $20. Still 10% ROE, but more money made.

    This is supposed to determine what companies do with their profits. If they can reinvest into the business (or at least, some business) at a decent ROE, then they should do so. But if they can't, they should be paying the profits out as dividends their stockholders can invest elsewhere.

    Say you propose a project for your company to undertake. The key questions might be the return on equity, and how much equity can be invested. (Making 500% returns on twenty bucks might not be very interesting for a large company.)

    Where do earnings come from?

    Return on equity can be broken down to understand why a business activity is making money. An equation called the DuPont system tries to do this.

    The DuPont system is:

      ROE = 
        (Margin, how much of each sale is profit) x
        (Asset Turnover, how quickly inventory is sold) x
        (Financial Leverage, how much did we borrow)

    • Higher margin means more profit per dollar of stuff sold
    • Higher asset turnover means selling stuff more quickly
    • Higher financial leverage gives you more stuff to sell or more productive assets for the same net worth - you're buying machinery or inventory with a loan

    Different kinds of business make money in different ways, even in the same industry. For example, some few-months-old numbers for Dell and Apple (numbers don't quite add up due to rounding error; numbers are from Morningstar):

    • Dell: 5% margin x 2.0 turnover x 4.4 leverage = 43.8% ROE
    • Apple: 15.4% margin x 0.9 turnover x 1.8 leverage = 24.2% ROE

    Not surprising. Dell makes money by selling a lot of stuff quickly for a low profit, using more borrowed money. Apple makes money by selling more slowly, but for higher profits. Both are workable models, neither one is wrong. Both companies are single-minded about their approach; Dell has focused on increasing turnover rather than increasing margin, and the opposite for Apple.

    Leverage is the most dangerous way to make money, because if the margin flips negative the ROE goes negative. Banks make their money on leverage, and they are supposed to be conservative about ensuring the margin stays positive, for example by only making sound loans to people who can pay them back.

    The worst kind of business is high leverage with a low, but unstable, margin. Example (other than subprime lending): airlines.

    • American Airlines a few months ago: 2.2% margin x 0.8 turnover x 10.8 leverage = 19% ROE
    • American Airlines now: -7.1% margin x 0.8 turnover * 17.42 leverage = -98% ROE

    Airlines are always about to go bankrupt. The margin depends on ticket prices (which they can't raise very much without losing sales), and fuel costs (which they don't control and which bounce around wildly). They can't control the margin, and on top of that the margin is low so requires high leverage to make the ROE worthwhile.

    Perhaps this explains why airlines are awful to customers. They can't afford to spend any money.


    Here's what a business activity should not be about: growing revenue for its own sake. Often it's possible to grow revenue by reinvesting in a business (say, hiring more salespeople, building more manufacturing capacity, running ads) ... but the ROE may be too low. If customers don't really want the increased sales enough to pay for them, then margins are low or even negative. At that point it would be better to invest in an index fund, or a savings account, rather than in the business. It doesn't make sense to spend a bunch of money selling stuff people don't want.

    ROE determines what sort of price/earnings ratio is acceptable, because (in theory) the earnings will be reinvested at the ROE. If an investment pays 10% per year reinvested at 10%, that is worth a lot more than 10% per year reinvested at 2%. So the stock price should be higher relative to earnings.

    I find it helpful to flip price/earnings over (earnings yield). It gives me much more pause to invest in something yielding 2% than something with a P/E of 50. Higher P/E almost sounds good - it's higher, right? Maybe this explains the tech bubble.

    Both ROE and P/E require all kinds of adjustments and normalizations to remove accounting artifacts before they mean all that much. That's one reason it's futile trying to buy stocks if you aren't a qualified analyst (or relying on one).

    As concepts, though, these ratios should help you decide what makes sense for the businesses you're involved with as an employee or owner. Is your company more focused on turnover or on margin, for example? Is your new project proposal profitable enough - would you personally invest in it instead of a mutual fund, if it were your money?

    This post moved to

    Even though I spend all day as a software developer, I find it useful to understand something about financial and business topics. Many people (including a much younger version of myself) reflexively dismiss business - marketing, finance, etc. - as irrelevant to them.

    Sometimes this is because people think of business as in some way distasteful. It can be. However, a better way to look at it is that some businesses and people engaged in business are distasteful.

    Mutually beneficial exchange

    Here is what business is supposed to be like. Say we live in a small town hundreds of years ago. I am a blacksmith and you are a farmer. You need horseshoes and I need food. We exchange one for the other. We are both better off.

    This is what a company should be like, and it's also how I like to view employment (an exchange of time for money that is mutually beneficial).

    Business is not always like this. Monopolies, for example, can mean that exchanges have lopsided benefits rather than mutual benefits. Another issue is that large (or mismanaged) organizations can become irrational - a public company should be a mutually beneficial exchange between the stockholders and the customers. The employees of the public company, specifically the management, are supposed to act as agents of the stockholders. But it's not unusual at all for politics and self-interest to trump both customers and stockholders. Or for short-term thinking to trump long-term.

    It gets more complicated when customers and stockholders mutually benefit, while some third party gets screwed. That's when government incentives or regulations are needed.

    The more complex and "abstracted" from stockholders and customers a business gets, the worse it can be for both stockholders and customers. Look at the subprime mess: it was too complicated and unclear where the mutual benefit was, with quite a few links in the chain between investors and customers. This allowed the agents (management, employees) in the middle to muck things up badly.

    Your company should be making a profit, and your customers should be better off than they would be without your company. True for a one-person company, true for a thousand-person company. Nothing else is sustainable (or ethical).

    A way to get things done

    Say you want to get something done. Work on a certain project, create a better mousetrap of some kind and get it out to people, spend your time on whatever activity, solve whatever problem in the world.

    There's no way around it: whatever you want to get done will use resources. It will use time, materials, or both. Even if your project is to quietly meditate in the wilderness, you'll be spending time on food, shelter, and other tasks to sustain yourself. You're converting some type of resource into some other outcome.

    To get something done, you could do all the work yourself. But not all tasks are that small. So people look for ways to achieve larger goals.

    To achieve a larger goal, you can either increase your own productivity, or you need to organize other people - ideally into a self-sustaining snowball that keeps pushing your goal further and further forward.

    There are two ways I know of:

    • Start a business.
    • Organize volunteers and donations; but volunteer labor and donations are both supported by some kind of business.

    Business is just cooperation

    Either everyone in the world is a completely self-contained and self-sustaining unit, doing their own hunting and gathering, building their own shelter, etc. ; or they are engaged in exchanges that should be mutually beneficial, i.e. they are in business.

    When specific businesses or specific business people don't seem to fit into this, those are bad businesses and bad business people.

    Trying to ignore business matters is a bad idea. You'll never get anything done (or even understand what's going on in the world).