Chrome Experiments

19. July, 2012

If you want to see what’s possible in today’s browsers, go to Chrome Experiments.

My picks:


Designing DSLs

16. July, 2012

Hello and welcome to a new series of blogs called “Designing DSLs” or DDSL for short. If you have used or designed a DSL before, then you’ll know that there are a couple of pitfalls. This blog series aims to provide tips how to build “great” DSLs – whatever that might be 😉

What are the most common pitfalls for designers of DSLs?

  • The DSL is too broad
  • The DSL is too limited
  • The syntax has weird quirks (a.k.a. backwards compatibility syndrome)

Why is it so hard to design a great DSL? They should be simple, right?

Well, as Einstein (“Everything should be made as simple as possible, but no simpler“) and Blaise Pascal (“I would have written a shorter letter, but I did not have the time.“) already knew, it’s always easy to make something complicated – simplicity is hard.

On top of that, every mathematical system is either incomplete or inconsistent. And let’s not forget that each DSL is a model, too. And as you might know, all models are wrong but some are useful.

Should we abandon all hope? No. Just always remember that a good DSL is hard work.

First, a general tip: Look at existing examples. There are thousands of examples out there; use them. Knowing several programming languages yourself is a big bonus (everyone should know more than two languages).

“Wait a minute,” I hear you ask, “these are real programming languages!” So? A lot of brainpower went into designing them (or working around shortcomings), which makes them a great source of inspiration. Bonus: A lot of people know these languages which gives you a larger audience to discuss ideas (as opposed to the 3-4 people who will use your DSL in the beginning).


Software Development Costs

14. July, 2012

I’ve prepared a small presentation to give an overview of software development costs.

This diagram describes the costs/gain per feature.

Complexity Curve

The most simple curve, complexity, is easy to understand: Costs go way up as you add features. Adding another feature to an already complex product is way more expensive than adding the first feature to a non-existing product.

Bugs in Final Product

The number of bugs in the final product is harder to understand. As you add features, you also add bugs. The number of bugs per kLOC is an individual constant. We always make the same mistakes and we the number of bugs we create per kLOC is pretty stable, too. The number is different for each person but every developer has their own number and that number doesn’t change much unless external circumstances change dramatically. In fact if you create statistics about bugs found per team member, you can tell how many new bugs there will be after he added N lines of code (see “They Write the Right Stuff“).

That means every product has bugs. If the project isn’t a complete disaster, then the team will have found a way to cope with these. Or to put it another way: If the number of bugs grows too fast, the project will either be canceled or drastic measures will be taken to reduce the flaws again.

This is what the curve means: In the beginning, there will be few bugs because there are only a few lines of code. Remember: number of bugs = lines of code * individual constants. Each line that you don’t write reduces the number of defects.

As time passes, the number of bugs will grow just because lines of code are written. Eventually, that number will either explode or the team will find a way to keep the number in check.

Gain per Feature a.k. ROI

The last curve is for the marketing department. It describes the usefulness of the product for a customer as features are added. A product without features (a.k.a vaporware) is not very useful for a customer. The first feature will be the most useful … or it should be: Why are you wasting your and your customer’s time with features that aren’t the most useful?

But as you add features – and trust me, customers and marketing will try to get as many as they can get – the usefulness doesn’t grow as much anymore. Each feature comes with the cost of complexity: There will be more menu items, dialogs and buttons. The manual will get bigger. The customer will need to remember more to use every feature. That starts with remembering that a feature even exists and goes on with remembering how to use it efficiently.

At the same time, you started with adding the most useful features, right? So additional features, by definition, can’t be as useful as the first ones.

And eventually, the product will contain more features than any single customer cares about. New features will be added for new customers that existing customers don’t care about or that even get in their way (when menu items move around, for example).

This is one reason why everyone feels that Google or Apple products are so easy to use: They work really, really hard to reduce the number of features in their products.

Next week: Bug fixing costs.

Related:


Dealing With Cheating

13. July, 2012

All online games attract cheaters. Most of them try to ban players who cheat but Rockstar Games came up with a better approach: They herd them.

Makes me wonder what took them so long. It would be great if there was a special server for cheaters and people using modded clients. Just imagine how many people will start working on AI problems (identify threats, take cover, shooting at targets, move around in a complex maze).


TNBT: Bringing Code Together

12. July, 2012

If you develop web apps, you have a workflow like this:

  • Repeat forever
    • Edit code
    • Deploy to server
    • Check in browser
    • Tweak HTML/CSS in browser
    • Find the location in the code which is responsible

Sucks? Yes. But until recently, there simply wasn’t a better way to do it. Only Eclipse allows to run am embedded web browser in your IDE but there is no connection between the code and the output. There usually isn’t a connection between related parts of the code. Or can you see all the relevant CSS styles while you edit code that generates an HTML tag? I mean: Can you see the CSS styles for “.todo” when you hover your mouse over code that means “send ‘class=”todo”‘ to the browser”?

Meet Brackets and see how awesome your IDE could be. If seeing is believing, here is the video:

Related Articles:

  • The Next Best Thing – Series in my blog where I dream about the future of software development

Create a Better World, One Game at a Time

10. July, 2012

Can you make the world better by playing games?

Sure: Fold enzymes on fold.it. Scientists tried for 15 years to fold a H.I.V related enzyme, fold.it solved it in 15 days.

You know better than the government? Look at social impact bonds.

Want to improve ethical behavior of large corporations? Donate to a convent.

Under the condition that they use it to buy enough shares to submit resolutions at shareholder meetings. And if that doesn’t work, the church has centuries of experience with public shaming. As Sister Nora Nash of the Sisters of St. Francis put it: “We’re not here to put corporations down. We’re here to improve their sense of responsibility.

Related:


Sonar: The current batch process and the configured remote server do not share the same DB configuration

10. July, 2012

You might see this error message when starting the Sonar client, for example via Maven (mvn sonar:sonar):

The current batch process and the configured remote server do not share the same DB configuration
- Batch side: jdbc:...
- Server side: check the configuration at http://.../system

The message is a bit misleading. Sonar doesn’t actually compare the database URL, it compares the ID which you can find in the database table properties under prop_key = sonar.core.id and this isn’t an ID, it’s the start time of the Sonar web server:

select * from properties where prop_key = 'sonar.core.id'

There are two reasons why there could be a mismatch:

  1. The database URL on the batch and the server side don’t match (just check it via the URL which the Sonar client gives you)
  2. There are two Sonar servers using this database. This can happen, for example, when you migrated the service from one host to another and forgot to shut down the old version properly.

Patent Battles are a Ridiculous Abuse of Intellectual Property Law

6. July, 2012

A human with a brain. What has the world come to? 😉 In his blog post “Capitalism“, US-Judge Richard Posner argues that “statistic indicates that capitalism is a necessary condition of economic success rather than a sufficient condition.” But sadly economists like Alan Greenspan have been fallen for the delusion that “capitalism was a self-regulating system; market failures were, with few exceptions, either self-correcting, or less harmful than regulation aimed at eliminating them.”

We all know where that lead to. Power needs to be controlled by an independent force. Capitalism doesn’t work without democracy and democracy, we all know only too well, works only with a balance of power.

I agree with him that the patent system is a good idea for pharmaceuticals (as I said before).

But software patents have become just a weapon. Posner says: “It’s not clear that we really need patents in most industries.” And unlike in drugs, each piece of technology is protected by a long list of patents. The smart phone in your pocket is probably protected by thousands of them because each piece of it is “protected” by hundreds of individual patents.

Hopefully, more judges follow his lead and put an end to legal but unethical behavior.

Related:


Jazoon 2012: Stay Human – on the future of men and robots

4. July, 2012

What I like about the Jazoon is that they try to widen your horizon. We had presentations how to publish books, psychology and the NASA. This year, the closing keynote was about androids – as in artificial humans, not Google.

Henrik Scharfe from Aalborg University talked about “Stay Human – on the future of men and robots” and Geminoid-DK, an android which Scharfe had built after his image (production notes). For this project, Time magazine put him on the “100 Most Influential People” list in 2012.

According to Scharfe, we’re all part of the “ultimate project: Make sense of the world” in a perpetual loop. To achieve this, we communicate. A very powerful means of communication is the story. Stories need not be true, they have to be relevant. In a sense, we talk to scale, to widen our influence.

During the presentation, Scharfe gave some insight into the production of the android. How odd it feels to enter a room where a copy of yourself is assembled. When the skin on the head is hanging open like from a nasty wound. When “your” arms are still missing. A head without hair. The different stages of coloring. When a worker stabs a needle through the skin to add the facial hair. Thoughts how the workers will treat your copy when you’re not around.

The team did celebrate its “birthday,” the date when it was first activated. For Henrik, it “felt like a friend waking from a long coma.”

After the android was assembled, automatic movements were programmed. We don’t usually notice but the facial expressions only “work” when all the details are right. This was hard to achieve because of the properties of the silicone skin, it’s thickness and the distance to the actuators. When the android is presented in public, this leads to opposite reactions by children and adults.

While adults are fascinated how human-like the android is, children are frightened by it because they sense that something is wrong. When the automatic movements (breathing, blinking) are deactivated and Henrik switches to manual control, this flips. Now, adult and teenagers are worried but the children suddenly see the android as a toy – something they can relate to.

When used as a mannequin, customers are hesitant to touch the clothes on the android while they have no problem to touch the dummies.

Looking at the future, Prof. Scharfe sees new modes of presence. Instead of traveling to Australia for a presentation, you might send your android (or just the skin). Over time, there will be a blended presence.

Beware: His android always causes a commotion at customs (when they stuff him into the X-ray) and the cabin crew (“Who is flying?” “I thought you were!”)

Of course, that causes questions: What happens if someone gets hurt by your android? Or when someone hacks into the remote control? As the androids get smarter (= they will be able to do more things on auto pilot like finding a room in a building), are they allowed to protect themselves against theft or attack?

Do we want to allow people to build androids for recreational activities? What about sex?

What if I order an android that looks like my girl friend? My ex-girl friend? Adolf Hitler? The pope? The President of the United States? My beloved dog? A Saber-toothed tiger (scale 1:1)? A child of mine that died in an accident or from an illness (like in A.I. Artificial Intelligence)?

Can I destroy this android? Walk it to a public square and club it with a baseball bat? Run it over with a car? Shoot it? Have it beg for mercy while I’m doing this? It’s just a recording, right?

If androids get really smart, will we grant them rights? How will you feel when your android greets you in the evening with “Honey, we need to talk. There is this really cute model at the other end of the city. Oh, and I’ll keep the kids.”

Will it be murder when I wipe the memory of such an android?

As you can see, these questions are important because technology just plows on. Technology doesn’t decide what’s right or wrong, we do. Answers will come through technology but we must still ask the questions. We must stay human where it counts.

To do that, more advanced research structured need to be built. It must be more simple for researchers to find relevant information (Watson comes to mind). It must be easier to share research. To collaborate. Today, it’s hard to combine resources. Some things aren’t on-line. Instead of individual PCs, universities and high-schools need to offer cloud services for their staff and students.

And most importantly, research needs to get out of the lab. It’s a neat story that people greet Geminoid DK when they enter the lab and say goodbye even when it’s switched off. But seeing surprise in the faces of children in a crowd only happens on the street.

Related:


Jazoon 2012: CQRS – Trauma treatment for architects

4. July, 2012

A few years ago, concurrency and scalability were a hype. Today, it’s a must. But how do you write applications that scale painlessly?

Command and Query Responsibility Segregation (CQRS) is an architectural pattern to address these problems. In his talk, Allard Buijze gave a good introduction. First, some of the problems of the standard approach. Your database, everyone says, must be normalized.

That can lead to a couple of problems:

  • Historic data changes
  • The data model is neither optimized for writes nor for queries

The first problem can result in a scenario like this. Imagine you have a report that tells you the annual turnover. You run the report for 2009 in January, 2010. You run the same report again in 2011 and 2012 and each time, the annual turnover of 2009 gets bigger. What is going on?

The data model is in third normal form. This is great, no data duplication. It’s not so great when data can change over time. So if your invoices point to the products and the products point to the prices, any change of a price will also change all the existing invoices. Or when customers move, all the addresses on the invoices change. There is no way to tell where you sent something.

The solution is to add “valid time range” to each price, address, …, which makes your SQL hideous and helps to keep your bug tracker filled.

It will also make your queries slow since you will need lots and lots of joins. These joins will eventually get in conflict with your updates. Deadlocks occur.

On the architectural side, some problems will be much easier to solve if you ignore the layer boundaries. You will end up business logic in the persistence layer.

Don’t get me wrong. All these problems can be solved but the question here is: Is this amount of pain really necessary?

CQRS to the rescue. The basic idea is to use two domain models instead of one. Sounds like more work? That depends.

With CQRS, you will have more code to maintain but the code will be much more simple. There will be more tables and data will be duplicated in the database but there will never be deadlocks, queries won’t need joins in the usual case (you could get rid of all joins if you wanted). So you trade bugs for code.

How does it work? Split your application into two main parts. One part takes user input and turns that into events which are published. Listeners will then process the events.

Some listeners will write the events into the database. If you need to, you will be able to replay these later. Imagine your customer calls you because of some bug. Instead of asking your customer to explain what happened, you go to the database, copy the events into a test system and replay them. It might take a few minutes but eventually, you will have a system which is in the exact same state as when the bug happened.

Some other listeners will process the events and generate more events (which will also be written to the database). Imagine the event “checkout”. It will contain the current content of the shopping cart. You write that into the database. You need to know what was in the shopping basket? Look for this event.

The trick here is that the event is “independent”. It doesn’t contain foreign keys but immutables or value objects. The value objects are written into a new table. That makes sure that when you come back 10 years later, you will see the exact same shopping cart as the customer saw when she ordered.

When you need to display the shopping cart, you won’t need to join 8 tables. Instead, you’ll need to query 1-2 tables for the ID of the shopping cart. One table will have the header with the customer address, the order number, the date, the total and the second table will contain the items. If you wanted, you could add the foreign keys to the product definition tables but you don’t have to. If that’s enough for you, those two tables could be completely independent of any other table in your database.

The code to fill the database gets the event as input (no database access to read anything from anywhere) and it will only write to those two tables. Minimum amount of dependencies.

The code to display the cart will only need to read those two tables. No deadlocks possible.

The code will be incredibly simple.

If you make a mistake somewhere, you can always replay all the events with the fixed code.

For tests, you can replay the events. No need to a human to click buttons in a web browser (not more than once, anyway).

Since you don’t need foreign keys unless you want to, you can spread the data model over different databases, computers, data centers. Some data would be better in a NoSQL repository? No problem.

Something crashes? Fix the problem, replay the events which got lost.

Instead of developing one huge monster model where each change possibly dirties some existing feature, you can imagine CQRS as developing thousands of mini-applications that work together.

And the best feature: It allows you to retroactively add features. Imagine you want to give users credits for some action. The idea is born one year after the action was added. In a traditional application, it will be hard to assign credit to the existing users. With CQRS, you simply implement the feature, set up the listeners, disable the listeners which already ran (so the action isn’t executed again) and replay the events. Presto, all the existing users will have their credit.

Related: