header image
2011 European User Group Meeting
July 19th, 2011 under Devel, rengolin. [ Comments: none ]

For all LLVM users in Europe that didn’t catch the announcement on the main list, be warned that we’re organising the European LLVM User Group Meeting in September, 16th, in London. All information necessary to register and submit your work is on the link.

It’s free of charge and we’ll also provide a happy-hour after the meeting for an extended networking. If you’re just curious about LLVM or work with it day to day or is thinking of starting your PhD with LLVM, please register and show up. You won’t regret. ;)

More information will be available on the link above and through the main mailing list. Stay tuned!


Google+ and the Yahoo-isation of Google
July 1st, 2011 under Corporate, rengolin, Web. [ Comments: 3 ]

Almost a decade ago I joined Yahoo to work on the search team. At that time, Google was giving Yahoo a hard time with their amazing search, while Yahoo was mostly based on directory search and some ad-hoc buyouts (AltaVista et al). Yahoo came with its own search, then bought Inktomy, then re-wrote the search engine, and they’re now using Bing. They were late on the search business. Too late. Not that Inktomy was bad, but it wasn’t better than Google and certainly wasn’t a novelty.

When Google came with Gmail it was a shock to all of us, Yahoo workers. How can they offer 1GB free mail and we only offer 10MB? How can a (then) small company provide such massive storage while the behemoth of the Internet could only afford peanuts? It’s all in the administration. Yahoo, for some reason I still don’t understand, had to have all user’s emails on filers (very expensive storage), and had to reserve the whole storage, even if less than 10% of the users actually used more than 50%. There was a lot of very expensive idle disks at Yahoo Mail…

Another case was social networks. Yahoo was never able to write a single decent social network that wouldn’t close an year later. Several internal attempts were made (during years of development) before the first Yahoo-360 came out, only to die a few months later of starvation.

Yahoo-style

When the internet was young, and Yahoo was at the top, they could do anything, people would just love. Yahoo mail was free and came with a calendar and some bits. It was horrid, but it was free, and we all used one day (especially after Hotmail was acquired by Microsoft). Somehow, the directors of Yahoo decided it was better to have it all, even if the quality was unbelievably low. They were so famous and so ubiquitous that anyone wanted to advertise on their websites. The more they had, the more people wanted.

That cycle made Yahoo create a huge number of useless pages and verticals (content website like weather, mobile, etc), just because people would pay loads of money to advertise there. I’ve seen many pages going live without proper review or a decent market analysis, and some were still with bogus content (non non non) and broken links after years. Yahoo had spread their butter so thin that it was impossible for them to compete with any other company.

Google came, Google destroyed Yahoo, Microsoft came and bought it. It may not be in paper, but Yahoo is the new Microsoft garden, where they put their feet up when they’re tired of working.

Facebook

With Facebook, the story is not completely similar. Google is still not where Yahoo was 8 years ago and the Internet is not as naive as it used to be. It’s true that Facebook killed every other social network website, but it’s not true that they’ll be able to do with GMail, what Google did with Yahoo Mail. Part because GMail is really good, and part because Facebook guys are not that good.

But there’s one trend that is happening to Google that is similar to Yahoo of the past: legacy. Google has a decade of code, normally more bad than good, and the new systems have to integrate with it. But that’s not the worse, by far. As Yahoo, Google started from ground-up, so they always had the start-up mentality. When the company wasn’t a start up any more, they still tried to do things the same way.

Two things happened during the last few years that put Google in a bad situation: first, because in the golden days they had truly done remarkable systems (simple, yet efficient), they thought (and carried on thinking) not only that they were the best of the best, but that they could do anything and anything they did was automatically better than any one else. Second, the lack of process and reality check only made things worse, by kludging infrastructure on top of infrastructure, by solving every problem as if it was map-reduce and by doing everything in-house, it was difficult to use off-the-shelf applications for things that weren’t really that relevant, and move on when it was, indeed, relevant.

Facebook is still a young company, but I hardly believe their fate will not be the same. It was also clear from the beginning (8 years ago), that Google would have the same fate. However, I don’t think that Facebook will overrun Google as the latter did with Yahoo, but that’s neither fault. The market is not the same, the Internet is not the same.

Google+

In the same style as Yahoo-360, Google is trying to use their own user-base to compete with Facebook, and for that, it’s very likely that they’ll fail. Not as bad as 360, but they won’t kill Facebook.

Hangouts, Circles, Huddle are just different names for the same functionality in Facebook, Twitter, etc. Even the layout of Google+ is identical to Facebook. 360 was exactly the same thing and that’s where I draw the line. That’s where Google is getting ludicrously similar to Yahoo 8 years ago and that’s why they’ll start failing more and more often from now on.

They stopped being creative. Their creative innovations (wave, buzz) is average at best, their copied products (chrome, android) and similar to the competition with no clear game changer and the old stuff (search, gmail) is still the same. Not bad, but not creative any more.

From now on, is only downhill. In a decade or so, Apple will offer to buy them, and fail to, but enough to dismiss the general trust people have on them and that will be the end. Zombies of the Internet…


Task Driven Computing
June 26th, 2011 under Computers, Life, rengolin. [ Comments: none ]

Ever since Moore’s idea became a law (by providence), and empires were built upon this law, little has been thought about the need for such advancements. Raw power is considered to many the only real benchmark to what a machine can be compared to others. Cars, computers and toasters are all alike in those matters, and are only as good as their raw throughput (real or not).

With the carbon footprint disaster, some people began to realise (not for the correct reasons) that maybe we don’t actually need all that power to be happy. Electric cars, low-powered computers and smart-appliances are now appealing to the final consumer and, for good or bad, things are changing. The rocketing growth of the mobile market (smartphones, netbooks and tablets) in recent years is a good indicator that the easily seduced consumer mass has now being driven towards leaner, more efficient machines.

But, how lean are we ready to go? How much raw power are we willing to give away. In other words, how far goes the appeal that the media push on us to relinquish those rights bestowed by Moore? It seems not so much, with all chip companies fighting for a piece of the fat market (as well as the lean, but).

What is the question, anyway?

Ever since that became a trend, the question has always been: “how lean can we make our machine without impacting on usability?”. The focus so far has only been on creating smarter hardware, to a lesser extent (and only recently) reducing the unneeded fat of operating systems and applications, but no one ever touches the fundamental question: “Do we really need all that?“.

The questions is clearly cyclic. For example, you wouldn’t need a car if the public transport was decent. You wouldn’t need health insurance if the public health system was perfect, and so on. With computing is the same. If you rely on a text editor or a spreadsheet, it has to be fast and powerful, so you can finish your work on time (and not get fired). If you are a developer and have to re-compile your code every so often, you need a damn good (in CPU and memory) computer to make it as painless as possible. Having a slow computer can harm the creative process that involves all tasks around it, and degrade the quality of your work to an unknown quantity.

Or does it?

If you didn’t have to finish your work quicker, would you still work the same way? If you didn’t have to save your work, or install additional software, just because the system you’re working on only works on a particular type of computer (say, only available on your workplace). If you could perform tasks as tasks and not a whole sequence of meaningless steps and bureaucracy, would you still take that amount of time to finish your task?

Real world

Even though the real world is not that simple, one cannot take into account the whole reality on each investigation. Science just doesn’t work that way. To be effective, you take out all but one variable and test it. One by one, until you have a simplified picture, a model of reality. If on every step you include the whole world, the real world, in your simulations, you won’t get far.

There is one paper that touched some of these topics back in 2000, and little has changed since then. I dare to say that it actually got worse. With all these app stores competing for publicity and forcing incompatibility with invisible boundaries, has only made matters worse. It seems clear enough for me that the computing world, as far I can remember (early 80′s) was always like that and it’s not showing signs of change so far.

The excuse to keep doing the wrong thing (ie. not thinking clearly about what a decent system is) was always because “the real world is not that simple”, but in fact, the only limitation factor has been the greed of investors who cannot begin to understand that a decent system can bring more value (not necessarily money) than any quickly designed and delivered piece of software available today.

Back in the lab…

Because I don’t give a fig to what they think, I can go back to the lab and think clearly. Remove greed, profit and market from the table. Leave users, systems and what’s really necessary.

Computers were (much before Turing)  meant to solve specific problems. Today, general purpose computers create more problems than they solve, so let’s go back to what the problem is and lets try to solve it without any external context: Tasks.

A general purpose computer can perform a task in pretty much the same way as any other, after all, that’s why they’re called “general purpose”. So the system that runs on it is irrelevant, if it does not perform the task, it’s no good. A good example of that are web browsers. Virtually every browser can render a screen, and show surprisingly similar results. A bad example is a text editor, which most of them won’t even open another’s documents, and if they do, the former will do all in its power to make the result horrid in the latter.

Supposing tasks can be done seamlessly on any computer (lets assume web pages for the moment), than does the computer only computes that task, or is it doing other things as well?

All computers I know of will be running, even if broken, until they’re turned off. Some can increase and decrease their power consumption, but they’ll still be executing instructions to the world’s end. According to out least-work principle (to execute tasks), this is not particularly relevant, so we must take that out of our system.

Thus, such a computer can only execute when a task is requested, it must complete that task (and nothing else more), and stop (really, zero watts consumption) right after that.

But this is madness!

A particular task can take longer to execute, yes. It’ll be more difficult to execute simultaneous tasks, yes. You’ll spend more cycles per particular task than usual, yes! So, if you still thinking like Moore, than this is utter madness and you can stop reading right now.

Task Driven Computing

For those who are still with me, let me try to convince you. Around 80% of my smartphone’s battery is consumed by the screen. The rest is generally spend on background tasks (system daemons) and only about 5% on real tasks. So, if you could remove 95% of your system’s consumption, you could still take 20x more power consumption for your tasks and be even.

Note that I didn’t say “20x the time”, for that’s not necessarily true. The easiest way to run multiple tasks at the same time is to have multiple CPUs in a given system. Today that doesn’t scale too well because the operating systems have to control them all, and they all just keep running (even when idle) and wasting a huge amount of power for nothing.

But if your system is not designed to control anything, but to execute tasks, even though you’ll spend more time per task, you’ll have more CPUs working on tasks and less on background maintenance. Also, once the task is done, the CPU can literally shut down (I mean, zero watts) and wait for the next task. There is no idle cost, there is no operational code being run to multi-task or to protect memory or avoid race-conditions.

Problems

Of course, that’s not as easy as it sounds. Turning on and off CPUs is not that trivial, running tasks with no OS underneath (and expecting them to communicate) is not an easy task, and fitting multiple processors into a small chip is very expensive. But, as I said earlier, I’m not concerned with investors, market or money, I’m concerned with technology and it’s real purpose.

Also, the scaling is a real problem. Connection Machines were built and thrown away, clusters have peak performance way above their average performance levels, and multi-core systems are hard to work with. Part of that is real, the interconnection and communication parts, but the rest was artificially created by operating systems to solve new problems in an old way, just because it was cheaper, or quicker, or easier.

Back in the days…

I envy the time of the savants, when they had all the time and money in the world to solve the problems of nature. Today, the world is corrupted by money and even the most prominent minds in science are corrupt by it, trying to be the first to do such and such, protecting research from other peers just to claim a silly Nobel prize or to be world famous.

The laws of physics had led us into it, we live in the local minima of the least energetic configuration possible, and that’s here, now. To get our of any local minima we need a good kick, something that will take us out in a configuration of a more energetic configuration, but with enough luck, we’ll fall into another local minima that is less energetic than this one. Or, we we’re really the masters of the universe, maybe we can even live harmoniously in a place of local maxima, who knows!?


May the 4th be with you
May 4th, 2011 under Digital Rights, rengolin. [ Comments: none ]

Today is the annual Day Against DRM, please remember to check your shopping list for possible DRM-ed products, and consider doing some of the ideas on the site… I can give you a few examples why this is bad.

First, I own an iPad and cannot use it. It won’t be recognized by my Linux machine, I can’t copy music or books to it, I can’t browse my music collection on my server to play random songs, I have to sync it with iTunes (and only iTunes) that I have to run on a Windows virtual machine inside my Linux machine. It’s dead slow, it won’t sync up things from my iPad unless I find the magical option pull changes from iPad instead of the ubiquitous sync option, etc.

Secondly, the Play Station is a wonderful machine and many people wanted (and could) run Linux on it. Years ago there were clusters of Play Stations, since its GPU was powerful enough to do scientific computation (better than many computers at the time), but now, you can’t even touch it without going to jail.

Finally, in the age of the internet, companies are still attached to material values such as possession and ownership, whereas the internet transforms everything into a service. Amazon, although they still use DRM on Kindle, they understood it quite well and have created the most important cloud service on the planet.

Why those companies are not using the same model for everything? Well, generally reality doesn’t get transformed that quickly, so it was a great shock. But now society is demanding new rules for a new reality and the fact that many people are going to jail for preserving their own rights is alarming and a crucial sign that the old rules don’t apply any more.

This day is to remind you that you are not alone in thinking that this is all wrong, that you should be able to listen to any music, on any device, anywhere, since the technology allows you to. If the business model does not account for it, change the business model!

May the 4th be with you…


Touch-screen keyboard
May 2nd, 2011 under Computers, Gadgtes, rengolin. [ Comments: 2 ]

I’ve been using virtual keyboards for a while (iPad, Android phone) and, while it’s good enough, it made me wonder…

QWERTY

The QWERTY keyboard was invented in the 19th century and before computers had keyboards, it was mainly used for typing letters. The advanced feature of a typewriter was the SHIFT key.

When computers had their input changed from switches and punched cards to keyboards and printers (before monitors were invented), the natural choice was to use the ubiquitous QWERTY layout. But because of the nature of computing, many additional keys were needed. Since the single most important function of a keyboard was to input code (and not Word documents), the SHIFT concept was extended with CONTROL keys, the FUNCTION keys were added and some other impossible concepts in typewriter, such as the Home/End, Insert/Replace, etc.

All that was added around the traditional keyboard, and today it’s now ubiquitous as well. All editors (code and otherwise), use extensively those keys and it’d be impossible to imagine a keyboard without it. But, to be honest, the layout of the computer keyboard did not technically have to mimic the old fashioned typewriter. It just did to ease the transition between writing letters on paper and code on silicon.

Nowadays, the virtual keyboard is, again, mimicking the 120 years-old layout, just because everyone got use to, but now the excuses to keep it are fading. I do not know anyone that still uses a typewriter, do you? Also, most of the extra keys are still only used by coders of some sort, including Vim, Emacs, Photoshop and Excel.

Swipe movements

Clicking on links, editing text and drag&dropping is very awkward on the iPad (not to mention on phones), so that’s not going to stick more than a decade. However, gestures are so intuitive on touch-screen interfaces that it can easily become mainstream, if done right.

One browser I use on Android (Dolphin) has hand gestures, and I have to say it’s horrible and too complicated. It’s based on the old mouse-gestures that, by definition, is out-dated and not technologically compatible.

Touch gestures have to be more natural, like moving objects on your desk. One way to do this is to use the (now famous) two-finger swiping. Another is to add hot-areas to your touch screen, where people know are for specific purposes. For example, imagine a touch-screen keyboard the size of an iPad (10″, no screen on it, just the keyboard). Remove every other key than the QWERTY keyboard itself. Just as you would use the lower area as a pointing device, the lower area (either swiping or tapping) brings a full-screen pointing device, with all gestures and controls one needs. Another tap would bring the main keyboard back.

The same way, right and left screens would bring editing capabilities to your programs, and each program could have its own screen. Some could revert back to the main keyboard as you press on key (as to save the return tap), others would require you to press multiple keys are the same time. The top part could bring the multi-media area, with animated buttons, etc.

Feed-back

All that is not complete without some feed-back, the worse thing on using virtual keyboards. The click noise is easy enough, but tactile is coming a long way without really going anywhere. Microsoft, Apple, Nokia, Sony, all tried (and patented) solutions to tactile touch-screen and yet, not mainstream device today uses one. I’m sure that’s mostly due to technical difficulties (maybe battery life, or bulkiness), none of them critical to a keyboard.

When playing games on the phone that emulate joysticks (SNES emulator, or other Android-specific ones), I often die because of the lack of tactile feed-back, that is, I take my finger off the D-pad without noticing. This is most annoying and virtual keyboards aren’t going anywhere without a decent feed-back system.

Some laptop/tablet cross-breeds, have dual touch-screens for that purpose, and I think (or rather, hope), that this is the future. But they need to change the layout of how keyboards are supposed to work. Luckily, that can be done all in software, and Linux is an open system, which anyone could implement it.

If you do, please open source it and make it free. Any penny you get from it is a second away from it being universally accepted.


C++ class sizes #2
March 31st, 2011 under Devel, rengolin. [ Comments: 1 ]

In my previous post about class sizes, we visited the empty classes and how their derived classes change in size. Now, we’re going to look what the ABI have to say about tail padding in inherited classes.

Again, for normal (POD) structures, everything is as it looks like, same as in C. But for more complex (non-POD) classes, things change a bit. The Itanium C++ ABI has a rather complex rule for defining the offset and size of class members, but each target-specific ABI (like ARM’s) can have additional rules that make it very complex to define the size of a class member.

Plain-Old-Data

So, first, a brief explanation of POD. POD is a concept in C++ that states, for the purpose of layout, a C++ structure (that is more than simple C structures) are just like plain old data. This normally means that the structure behaves like data, ie. it can be created on zero-initialized memory, copied with memcpy without any side effect, etc.

But not being a POD doesn’t always means you have a complex virtual class with multiple inheritance. Sometimes a simple change can transform it into a non-POD, like adding a simple empty constructor to the base class.

For example, in both C and C++, the structure below has 8 bytes:

struct Foo {
  int a;
  char b;
};

because the structure alignment is the same as the most aligned member, which is int. Assuming int is 32 bits, the second member has size one but aligns to four, yielding a size 8 for the final structure.

In C++, you can derive from that structure, and the derived class is normally implemented by having the base class as sort of a member inside it.

So, the C++ struct Bar below:

struct Foo {
	int a;
	char b;
};

struct Bar : Foo {
	char c;
};

is similar (for layout purposes) to a C construct:

struct Bar {
	struct {
		int a;
		char b;
	};
	char c;
};

So, both in C and in C++, the size of Bar is 12 bytes. Now, doing a slight change in Foo, we’re going to break that:

struct Foo {
	int a;
	char b;
	Foo() {}
};

struct Bar : Foo {
	char c;
};

You may be surprised to know that the size of Bar is still 8 bytes.

non-POD structures

Adding the constructor is one way of killing the POD-ness of a structure, but anything that adds some C++ flavour to it is enough. For instance, Bar itself is a non-POD, because it was derived from another structure. Adding simple methods (non constructors) is fine, but adding a virtual method makes it a non-POD (as you have to add the virtual table). Anything that leaves some room for implementation detail will be considered a violation of the POD contract and will transform your structure to a non-POD.

Ok, so what does that mean? If it just means your structures will be smaller, well, I’ll add a constructor to all my structures! But, no, the only change in in the tail padding. If you want to compress your structures, use packed structures, the tail padding rules are too complex to deal with them and still maintain your code clean.

So, the original Foo structure had 8 bytes. Four for the first int, Four for the char. But the char only used one of those four, so you have a 3-byte tail. When inheriting from a non-POD structure, the C++ ABI allows you to use the tail padding of the base class, providing your new type fits in there. In our example, the new type was char that fits in the 3-byte tail of the base class, so the final layout uses two of the four bytes and still have a 2-byte tail.

Further inheritance of the same type (adding a single char member) will still pack at the end of the base structure.

Bit-fields

Every time you think you have understood the rules of C++ layout, go back to bit-fields and you’ll always be surprised.

Lets have a look at this example for a moment:

struct Foo {
	char a;
	int b : 8;
	Foo(){}
};

struct Bar : Foo {
	int c : 8;
};

The first member is a char, so one byte. The second is an int, so 4 bytes and the final layout is 5 bytes, aligned to int goes to 8 bytes, right? Well, no. Even without the constructor, the size of that structure is 4 bytes.

Compilers are smart enough (and the ABI allows them to be) to figure that the member b will have only 8 bits, so there is no point in wasting 6 more bytes just to follow the declared type.

You may not be surprised, now, to know that the size of Bar is still 4 bytes, since the member c in Bar gets tail-padded into the base Foo.

But what about this:

struct Bar  {
	struct {
		char a;
		char a1;
		char a2;
		int b : 4;
	};
	int c : 4;
};

The three chars push the final member to the last byte in the block, of which only 4 bits are really used, so you have 4 bits of tail-padding. The second member c of Bar gets tail-padded into those four bits, since they fit, and the final size of that structure is 4 bytes.

I hope to have convinced you to never try to be smart and convert your structures and classes to arrays or pointers. Even disregarding virtual inheritance (which is probably coming in another post), the C++ ABI for structure layout is too complex to rely on and use it in your own code. Worse, because this is not in the standard, concrete implementations are free to change the details and sometimes, still following the generic ABI. You’ll find a few cases in the ARM ABI where they differ slightly from the ABI without actually being incompatible, sometimes not that lucky.

The final lesson is: be smart, use the language features and rely on the compiler to optimise things for you. If you’re not happy with the optimization, fill a bug rather than hack your code.


Why no MMORPG is good enough?
March 8th, 2011 under Devel, Fun, Games, rengolin, Software, Web. [ Comments: none ]

Massively multiplayer online role-playing game (MMORPG) are not new. The first I remember playing is the Legend Of the Red Dragon (LORD), but before that, of course, I’ve played other (real-life) multiplayer RPG games as well, and they were never quite the same thing.

Of course, at that time the graphic cards couldn’t quite compete with our imagination (not to mention connection speeds), but a lot has improved in both fronts, and lots of very good looking games have arrived, but still, there’s something missing. For years I couldn’t put my finger on it, but recently I think I nailed the issue: user driven content.

The interface

Most of the MMORGP are war games. World of Warcraft, LOTR online, Vendetta, Star Trek Online, Regnum and so many others rely on war to be fun. Of course, all of them have the side issues, some trade or silly missions, but the real fun is going to the battlefield.

If you look from the technical side of things, this is not surprising at all. Aside from good graphics, one of the hardest things to do in a game is a good interface. Very few games are perfect like Tetris. I gave Tetris to both my sons when they were about 2 years old and after about a minute they were already playing. There is no need to instructions, tutorials or any training and still today I find it quite fun. This is why it’s probably the most successful game in history.

But it’s all about the interface. It’s easy to create a seamless interface for Tetris. Try to create an interface for a strategy game that doesn’t require some hours of training, or an interface for first-person games that actually allows you to know where you are, or an interface for adventure games that doesn’t make you click in half-dozen places to get anything. Many have tried, all have failed.

At the dawn of internet games, strategy and quake were dominant. That’s because the internet wasn’t so fast and both were quite good in saving bandwidth. Quake had a special fix to avoid sending one packet for every bullet and only one packet when you press the trigger and another when you release it, the rest was up to the client.

But in war games, the interface is pretty much established. World of Warcraft didn’t invent anything, they just mixed Warcraft with Lara Croft (rubbish interface, by the way). Space ship games got the interface from Wing Commander (Vendetta got it from W.C. Privateer), Lord of the Rings and Regnum mixed Second Life with old-style RPG (even with the same deficiencies) and Star Trek Online copied from everyone above.

Now, the interface for a good strategy or adventure game is somewhat complicated. For a first-person 3D RPG, even worse. It doesn’t have to be mind controlled to be easy, nor you have to use 3D glasses or any immersion technology to be fun. Simplifying the game is one way, but then it’s even harder to make it more interesting.

It’s the user, stupid!

I can see only one way to add value to a game that is simple but still fun: user driven content.

You can enrich the world in which you’re immersed into. For instance, Zynga is quickly gathering an impressive amount of users by adding a lot of content. I don’t play those games, but people around me do and I can see why it’s so addictive. There are so many things to do and the frequency of updates is so impressive that it’s almost impossible not to be driven to it.

You might think that the games are too simple, and the graphics are average, but the interface is extremely simple, the challenges are simple, yet still challenging, and the number of paths you can choose for your character are enormous. In this case, the user experience is driven by his own choices. The content is so rich that each and every place is completely different from every other, solely driven by user choices.

Not many game companies (certainly not the indie ones) have time or money to do that. So, why are indie games generally more interesting than commercial ones? They go back to square one, simplify the game and optimise the interface. EA would never release something like Angry Birds or World of Goo, and yet those are the two best games I played in a long time. But, world of Goo is over and Angry Birds require constant attention (seasonal versions) to keep selling or making money (from ads).

They are missing the user content. It might not be their style, nor objective, but that’s a difference between Deep Purple and a one-hit-band.

Back to MMORGP

So, from all MMORPGs, there are many good looking, some with good challenges and a lot of slaughtering fun, but I tire quite quickly from playing them. The last I played was Vendetta. Quite good graphically, it has some reasonably accurate physics simulation (what drove me to it) but not accurate enough to keep me playing. The content tires too quickly to be fun after a few hours and even though I had 8 hours of free play, I spent less than two and dropped it.

This was always a pain, since Final Fantasy and the like, building up the character, hitting slugs for XP, fight-heal-run until you level up. Though Final Fantasy was better, as it normally would throw you on level 10 or so, so you didn’t need too much of levelling up. But why? Who likes beating 253 slugs to get 1000 experience points, going to level 2 and being able to equip a copper sword that doesn’t even cut a snail’s shell?

One of the best MMORGP experiences I had recently was Regnum. This is a free game made in Argentina and has a lot of content, good interface and a healthy community. They do the normal quest levelling up technique and it works quite well until level 15 or so. After that, it’s hitting bears, golems and phantoms for half a year until you can go outside and beat other users.

I got outside prematurely (couldn’t bother to wait) and the experience was also not great. Huge lag on big crowds, people disappearing in mid-air and appearing a few meters away, etc. But the most annoying of all was the content. It was always the same fort that we had to protect, always the same keep we had to attack, always the same talk on how our race is superior to your race, etc.

I haven’t seen Lord of the Rings (which sucks on Linux) or Star Trek Online (which doesn’t even run), but I bet they can get a bit further. They’re there to compete with World of Warcraft, not Regnum, but the fate will be the same: boring.

So, after quite a big rant, how would I do it?

User content

First, a memory refresh: all free first-person shooter I know of are a re-make of Quake. They use the same engine, the same world builders, the same techniques. On Debian repositories you’ll find at least a dozen, all of them running on some version of Quake. Nexuiz, Tremulous, Open Arena, Urban Terror, etc.

Not only the Quake engine is open source, but it was built to be extensible and that, even before the source was opened by ID. I made some levels for Doom, there were good editors at the time (1994?), probably there are full development suites today.

The user has the power to extend, create, evolve and transform your game in ways that you never thought possible. To think that only the few people you hire are good enough to create game content is to be, to say the least, naive.

Now, all those games are segmented. Nexuiz levels don’t connect to Tremulous levels. That’s because the mods (as they’re called) are independent. To be able to play all those different games you need to download a whole lot of data (objects, music, game logic, physics settings, etc) and each game has it radically different. Sarge with a rocket launcher would be invincible in most of other quake variants.

But that is, in my opinion, the missing link between short spurs of fun and long lasting enjoyment. I want to be able t build my world (like Zynga), but in a world with free movement (like Quake) with quests (like MMORPGs) made by the users themselves (like no FP-game I know) in a connected world. It cannot penalise those that connect seldom, or those that connect through text terminals, Android phones or browser users in any way.

As some games have started to understand, people like different things in games. I like building stuff and optimizing structures, some like carnage, others like to level up or wait 45 minutes for a virtual beef pie to be ready. You cannot have all that in one game if you’re the only content generator.

Also, if the engine is not open, people won’t be able to enhance it for their particular worlds. It doesn’t have to be open source, but it has to have a good API and an efficient plugin system. Tools to create mods and content is also essential, but the real deal is to give the users freedom to create their versions of the game and be able to connect them all.

If every game is also a server, people can create their small worlds inside the bigger world, that is in the central server. A business strategy would be, then, to host those worlds for people that really cared about them. Either host for free in exchange of ads and content generation, or paid hosting for the more serious users. You can also easily sell content, but more importantly, you can create a whole marketplace of content driven by the users! Read Neil Stephenson’s Snow Crash and you know what I mean.

I think Apple and Google have proven over and over that a market with apps generated by the users is very effective indeed! Intel is just following the same path with their new App store, so yes, this is a good business strategy. But, it’s still fun for a wider range of people, from game addicts to casual gamers, from heavy modders to passive Facebook users.

There are many ways of doing that, maybe not all of them will be successful, but at least from my point of view, until that day arrives, no game will be fun.


C++ class sizes
January 28th, 2011 under Algorithms, Devel, rengolin. [ Comments: none ]

In a recent struggle to define the class size in C++, I thought would be good to share some of my findings, since there isn’t much about it on the net. The empty class size is all over the place, neatly put in Stroustroup’s FAQ, but the other weird cases were less common to find.

For obvious reasons, the C++ standard is pretty vague about class sizes and memory layout. This is more of an ABI issue than a language standard, but the problem is that even the Itanium C++ ABI is a bit vague on that point.

The C++ standard allows the memory layout to be defined by the ABI and position the class members on where it fits more naturally on the target, but there is one specific clause: an object cannot have zero size. While most layout decisions are target specific, this is strictly a language decision. If objects were allowed to have zero bytes in size, an array of 1000 zero-sized objects would occupy no space at all and it would be impossible to choose one from the other.

Empty classes

First, a background on empty classes. An empty class is somewhat useless in most cases, but there is one case in which it plays an important role: type safety.

If you want to group objects that have nothing in common (to use in an algorithm), or to force a specific class of template parameters, or even differentiate between exceptions, even if they don’t have any data on it (just to catch them differently), you can use an empty class and it does the job pretty well. Thus, using and deriving from empty classes is somewhat a common enterprise in C++.

Empty class size

So, what happens when you declare an empty type?

class Empty {
};

What is the size that objects of this type will have? It cannot be zero, as the standard forbids, so it has to be something. The best choice is one byte, since no architecture will benefit from having less (please, don’t think of bit-fields!) and if alignment is a problem, most (all?) compilers will adjust the byte to a word aligned block in memory.

Obviously, an empty class that derives from another empty class also has to follow the same rule:

class Empty {
};

class NowWhat : public Empty {
};

In this case, both empty and NowWhat have size 1. But if NowWhat has data on it, will the extra byte still be there? On both standard and ABI, there is nothing saying that it shouldn’t, but also nothing saying it should. What’s important here is the reason why you need the extra byte: the address of different objects must be different.

When the derived class already has data, its objects will already be at different locations when laid out in memory, so there is no necessity of the extra byte.

class Empty {
};

class NowWhat : public Empty {
  int a;
};

Now, Empty still has 1 byte, but NowWhat has 4, not 5. Some people consider this an optimization, I just think it’s following the rules by what the standard requires.

The reverse case is much simpler. If the derived class is the empty one (for whatever reason), the size is already non-zero, so the classes below have both the same sizes (4):

class Full {
	int a;
};

class Empty : public Full {
};

Multiple Inheritance

Multiple inheritance brings a bit of colour to this problem. The C++ standard requires that two objects always occupy different memory locations (so they compare differently by their pointers and don’t allow non-empty zero-sized arrays). So what is the size of the Derived class below?

class Empty {
};

class M1 : public Empty {
};

class M2 : public Empty {
};

class Derived : public M1, M2 {
};

Before, we could make the NowWhat class with only one byte because that would be sufficient to discriminate it in an array, but what about comparison. If you cast a Derived object to Empty via M1 you get a different (logical) object than if you do it via M2, so they must compare differently. For that, you need to add another byte, and return the first address when via one class and the second via the other.

Empty members

With single and multiple inheritance nailed down, let’s think of a more complicated case.

class Empty {
};

class Another : public Empty {
};

class NotSoMuch : public Empty {
	Another a;
};

What happening here is that the first item of the derived class is, in fact, of an empty class type, that also derives from the same class as the type.

See, this last bit is important, because if you replace Another a; by another empty class type (say Empty2), the size of the derived class will still be 1. But in this case above, this is not true. The size of NotSoMuch is actually 2.

The field Another a; has size one, as any empty class objects, so what’s the second byte for? The second byte is a padding, at the beginning of the class, to avoid type conflicts.

Type conflicts

When deriving from empty classes, the ABI (2.4-II-3) states that you should always try to put the derived members at zero offset and, in case of type conflict, move down (alignment-wise) until you don’t have any more type conflicts. The question is, what is a type conflict in this case? In the multiple inheritance, the type conflict was clear (the diamond inheritance), but here, not so much.

Since both the class and its first member can be converted to Empty types (as pointers, for instance), you can have two Empty objects that, if compared must return different addresses. In the code below, n is (a pointer to) the derived object. Itself is converted to an Empty pointer, stored in en.

	NotSoMuch *n = new NotSoMuch();
	Empty *en = (Empty*)n;
	Empty *ea = (Empty*)&n->a;

If the member Another a; was in the offset zero of the class, the pointer ea would be in the same address as en, and on a comparison for equality, it’d return true.

The type conflict in this case is that, while both en and ea are pointers to an Empty type, the former gets there via NotSoMuch and the latter via Another. According to the C++ standard, they must be different, thus, return different addresses.

Again, if the empty class member is not the first element, none of that happens. The example below has size 4 (instead of 5), because the two similar (but different) Empty pointers would now be separated by 4 bytes, thus not violating the standard.

class Empty {
};

class Another : public Empty {
};

class NotSoMuch : public Empty {
	int i;
	Another a;
};

Templates

Template code is also susceptible to this problem, of course, and the iostream library is full of such examples. The problem is not so much for the abuse of empty classes (that doesn’t happen that much in STL), it’s just that non-virtual classes that only have member functions and no data fields are considered empty classes. And since templates are a good replacement for most virtual inheritance (and its inherent run-time complexity and slowness), basic libraries have to make extensive use of templates to avoid slowing down every single C++ program.

It’s true that the iostream library is particularly heavy and cumbersome, but it could be much worse.

The additional problem with templates (for the compiler, at least), is figuring out if there is a type conflict. While templates are already expanded by the time the basic C++ compiler kicks in, it’s complicated to carry the information on the source code about inheritance graph to every single template variation and specialization. Not to mention the new standard, where C++ is getting a variadic templates mechanism

I hope this is one more reason for you to avoid C-style pointer casts (especially void*) and only use C++ static_cast and dynamic_cast. Even reinterpret_cast is dangerous, but at least you can grep them on your source files and identify them one by one.


Dream Machine (take 2)
January 18th, 2011 under Computers, Gadgtes, Hardware, rengolin, Technology, Thoughts. [ Comments: none ]

More than three years ago I wrote about the desktop I really wanted… Now it’s time to review that and make some new speculations…

Back Then

The key issues I raised back then were wireless technology, box size, noise, temperature and the interface.

Wireless power hasn’t progressed as much as I’d like, but all the rest (including wireless graphic cards) are already at full steam. So, apart from power, you don’t need any cables. Also, batteries are getting a bit better (not as fast as I’d like, too), so there is another stop-gap for wireless power.

Box size has reduced dramatically since 2007. All the tablets are almost full computers and with Intel and ARM battling for the mid-size form-factor, we’ll see radical improvements with lower power consumption, smaller sizes, much cooler CPUs and consequently, no noisy fans. Another thing that is bound to reduce temperature and noise is the speed in which solid-state drives are catching up with magnetic ones.

But with regard to the interface, I have to admit I was a bit too retro. Who needs 3D glasses, or pointer hats to drive the cursor on the screen? Why does anyone needs a cursor in the first place? Well, that comes to my second dream machine.

Form Factor

I love keyboards. Writing for (int i=0; i<10; i++) { a[i] = i*M_PI; } is way easier than try to dictate that and hope it gets the brackets, increments and semi-colons correctly. Even if the dictation software was super-smart, I still would feel silly dictating that. Unless I can think and the computer creates the code for me the way I want, there no better interface than the keyboard.

Having a full-size keyboard also allows you to spare some space for the rest of the machine. Transparent CPUs, GPUs and storage are still not available (nor I think will be in the next three years), so putting it into the monitor is a no-go. Flat keyboards (like the Mac ones) are a bit odd and bad for ergonomics, so a simple ergonomic keyboard with the basic hardware inside would do. No mouse, of course, nor any other device except the keyboard.

A flat transparent screen, of some organic LED or electronic paper, with the camera built-in in the centre of the screen, just behind it. So, on VoIP conversations, you look straight into the eyes of the interlocutor. Also, transparent speakers are part of the screen, half-right and half-left are screen + speakers, with transparent wiring as well. All of that, wireless of course. It should be extra-light, so just a single arm to hold the monitor, not attached to the keyboard. You should be able to control the transparency of the screen, to change between VoIP and video modes.

Hardware

CPUs and GPUs are so 10's. The best way to go forward is to have multi-purpose chips, that can turn themselves (or their parts) on and off at will, that can execute serial or vector code (or both) when required. So, a 16/32 core machine, with heavily pipelined CPU/GPUs, on multiple buses (not necessarily all active at the same time, or for the same communication purpose), could deal with on-demand gaming, video streaming, real-time ray-tracing and multi-threaded compilation without wasting too much power.

On a direct comparison, any of those CPU/GPU dies would have a fraction of the performance of a traditional mono-block chip, but their inherent parallelism and if the OS/drivers are written based on that assumption, a lot of power can be extracted from them. Also, with so many chips, you can selectively use only as much as you need for each task for specific applications. So, a game would use more GPUs than CPUs, probably with one or two CPUs to handle interface and sound. When programming, one or two CPUs can handle the IDE, while the other can compile your code in background. As all of this is on-demand, even during the game you could have a variable number of chips working as GPUs, depending on the depth of the world it's rendering.

Memory and disk are getting cheaper by the second. I wouldn't be surprised if in three years 128GB of memory and 10TB of solid-state disk are the new minima. All that, fitting nicely alongside the CPU/GPU bus, avoiding too many hops (NB+PCI+SATA+etc) to get the data in and out would also speed up the storage/retrieval of information. You can probably do a 1s boot up from scratch without the necessity of sleeping any more, just pure hibernate.

Network, again, wireless of course. It's already a reality for a while, but I don't expect it to increase considerably in the next 3 years. I assume broadband would increase a few percent, 4G will fail to deliver what it promises when the number of active clients reach a few hundred and the TV spectrum requires more bureaucracy than the world can handle. The cloud will have to wait a bit more to get where hard drives are today.

Interface

A few designs have revolutionized interfaces in the last three years. I consider the pointer-less interface (decent touch screen, camera-ware) and the brain interface as the two most important ones. Touch-screens are interesting, but they are cumbersome as your limbs get in the way of the screen you're trying to interact with. The Wii-mote was a pioneer, but the MS Kinect broke the barrier of usability. It's still in its early stages, but as such, it's a great revolution and because of the unnatural openness of Microsoft about it, I expect it to baffle even the most open minded ones.

On the other hand, brain interfaces only began this year to be usable (and not that much so), the combination of a Kinect, with a camera that reads your eyes and the brain interface to control interactions with the items on the screen should be enough to work efficiently and effectively.

People already follow the mouse with their eyes, it's easy to teach people to make the pointer follow their eyes. But to remove uncertainties and get rid once and for all of the annoying cursor, you need a 3D camera to take into account your position relative to the screen, the position of other people (that could also interact with the screen on a multi-look interface) and think together to achieve goals. That has applications from games to XP programming.

Voice control could also be used for more natural commands such as "shut-up" or "play some jazz, will ya?". Nothing too complex, as that's another field that is crawling for decades and hasn't have a decent sprint since it started...

Cost

The cost of such a machine wouldn't be too high, as the components are cheaper than today's complex motherboard designs, with multiple interconnection standards, different manufacturing processes and tests (very expensive!). The parts themselves would maybe be a bit expensive, but in such volumes (and standardised production) the cost would be greatly reduced.

To the environment, not so much. If mankind continues with the ridiculous necessity of changing their computers every year, a computer like that would fill up the landfills. The integration of the parts is so dense (eg monitor+cameras+speakers in one package) that would be impossible to recycle that cheaper than sending it to the sun to burn (a not so bad alternative).

But in life, we have to choose what's really important. A nice computer that puts you in a chair for the majority of your life is more important that some pandas and bumble bees, right?


Computer Science vs Software Engineering
January 13th, 2011 under Corporate, rengolin, Science, Technology. [ Comments: none ]

The difference between science and engineering is pretty obvious. Physics is science, mechanics is engineering. Mathematics is (ahem) science, and building bridges is engineering. Right?

Well, after several years in science and far too much time in software engineering that I was hoping to tell my kids when they grow up, it seems that people’s beliefs are much more exacerbated about the difference, if there’s any, than their own logic seems to imply.

Beliefs

General beliefs that science is more abstract fall apart really quickly when you compare maths to physics. There are many areas of maths (statistics, for example) that are much more realistic and real world than many parts of physics (like string theory and a good part of cosmology). Nevertheless, most scientists will turn their noses up at or anything that resembles engineering.

From different points of view (biology, chemistry, physics and maths), I could see that there isn’t a consensus on what people really consider a less elaborate task, not even among the same groups of scientists. But when faced with a rejection by one of their colleagues, the rest usually agree on it. I came to the conclusion that the psychology of belonging to a group was more important than personal beliefs or preferences. One would expect that from young schoolgirls, not from professors and graduate students. But regardless of the group behaviour, there still is that feeling that tasks such as engineering (whatever that is) are mundane, mechanical and more detrimental to the greater good than science.

Real World

On the other side of the table, the real world, there are people doing real work. It generally consists of less thinking, more acting and getting things done. You tend to use tables and calculators rather than white boards and dialogue, your decisions are much more based on gut feelings and experience than over-zealously examining every single corner case and the result of your work is generally more compact and useful to the every-day person.

From that perspective, (what we’re calling) engineers have a good deal of prejudice towards (what we called) scientists. For instance, the book Real World Haskell is a great pun from people that have one foot on each side of this battle (but are leaning towards the more abstract end of it). In the commercial world, you don’t have time to analyse every single detail, you have a deadline, do what you can with that and buy insurance for the rest.

Engineers also produce better results than scientists. Their programs are better structured, more robust and efficient. Their bridges, rockets, gadgets and medicines are far more tested, bullet-proofed and safe than any scientist could ever hope to do. It is a misconception that software engineers have the same experience than an academic with the same time coding, as is a misconception that engineers could as easily develop prototypes that would revolutionise their industry.

But even on engineering, there are tasks and tasks. Even loathing scientists, those engineers that perform a more elaborate task (such as massive bridges, ultra-resistant synthetic materials, operating systems) consider themselves above the mundane crowd of lesser engineers (building 2-bed flats in the outskirts of Slough). So, even here, the more abstract, less fundamental jobs are taken at a higher level than the more essential and critical to society.

Is it true, then, that the more abstract and less mundane a task is, the better?

Computing

Since the first thoughts on general purpose computing, there is this separation of the intangible generic abstraction and the mundane mechanical real world machine. Leibniz developed the binary numeral system, compared the human brain to a machine and even had some ideas on how to develop one, someday, but he ended up creating some general-purpose multipliers (following Pascal’s design for the adder).

Leibniz would have thrilled in the 21th century. Lots of people in the 20th with the same mindset (such as Alan Turin) did so much more, mainly because of the availability of modern building techniques (perfected for centuries by engineers). Babbage is another example: he developed his differential machine for years and when he failed (more by arrogance than anything else), his analytical engine (far more elegant and abstract) has taken his entire soul for another decade. When he realised he couldn’t build it in that century, he perfected his first design (reduced the size 3 times) and made a great specialist machine… for engineers.

Mathematicians and physicists had to do horrible things (such as astrology and alchemy) to keep their pockets full and, in their spare time, do a bit of real science. But in this century this is less important. Nowadays, even if you’re not a climate scientist, you can get a good budget for very little real applicability (check NASA’s funded projects, for example). The number of people working in string theory or trying to prove the Riemann hypothesis is a clear demonstration of that.

But computing is still not there yet. We’re still doing astrology and alchemy for a living and hoping to learn the more profound implications of computing on our spare time. Well, some of us at least. And that comes to my point…

There is no computer science… yet

The beginning of science was marked by philosophy and dialogue. 2000 years later, man kind was still doing alchemy, trying to prove the Sun was the centre of the solar system (and failing). Only 200 years after that that people really started doing real science, cleansing themselves from private funding and focusing on real science. But computer science is far from it…

Most computer science courses I’ve seen teach a few algorithms, an object oriented language (such as Java) and a few courses on current technologies (such as databases, web development and concurrency). Very few of them really teach about Turin machines, group theory, complex systems, other forms of formal logic and alternatives to the current models. Moreover, the number of people doing real science on computing (given what appears on arXiv or news aggregation sites such as Ars Technica or Slashdot) is probably less than the number of people working with string theory or wanting a one-way trip to Mars.

So, what do PHDs do in computer science? Well, novel techniques on some old school algorithms are always a good choice, but the recent favourite has been breaking the security of the banking system or re-writing the same application we all already have, but for the cloud. Even the more interesting dissertations like memory models in concurrent systems, energy efficient gate designs are all commercial applications at most.

After all, PHDs can get a lot more money in the industry than remaining at the universities, and doing your PHD towards some commercial application can guarantee you a more senior position as a start in such companies than something completely abstract. So, now, to be honestly blunt, we are all doing alchemy.

Interesting engineering

Still, that’s not to say that there aren’t interesting jobs in software engineering. I’m lucky to be able to work with compilers (especially because it also involves the amazing LLVM), and there are other jobs in the industry that are as interesting as mine. But all of them are just the higher engineering, the less mundane rocket science (that has nothing of science). But all in all, software engineering is a very boring job.

You cannot code freely, ignore the temporary bugs, ask the user to be nice and have a controlled input pattern. You need a massive test infrastructure, quality control, standards (which are always tedious), and well documented interfaces. All that gets in the way of real innovation, it makes any attempt of doing innovation in a real company a mere exercise of futility and a mild source of fun.

This is not exclusive of the software industry, of course. In the pharmaceutical industry there is very little innovation. They do develop new drugs, but using the same old methods. They do need to get new medicines, more powerful out of the door quickly, but the massive amount of tests and regulation they have to follow is overwhelming (this is why they avoid as much as possible doing it right, so don’t trust them!). Nevertheless, there are very interesting positions in that industry as well.

When, then?

Good question. People are afraid of going out of their area of expertise, they feel exposed and ridiculed, and quickly retract to their comfort area. The best thing that can happen to a scientist, in my opinion, is to be proven wrong. For me, there is nothing worse than being wrong and not knowing. Not many people are like that, and the fear of failure is what keeps the industry (all of them) in the real world, with real concerns (this is good, actually).

So, as far as the industry drives innovation in computing, there will be no computer science. As long as the most gifted software engineers are mere employees in the big corporations, they won’t try, to avoid failure, as that could cost them their jobs. I’ve been to a few companies and heard about many others that have a real innovation centre, computer laboratory or research department, and there isn’t a single one of them that actually is bold enough to change computing at its core.

Something that IBM, Lucent and Bell labs did in the past, but probably don’t do it any more these days. It is a good twist of irony, but the company that gets closer to software science today is Microsoft, in its campus in Cambridge. What happened to those great software teams of the 70′s? Could those companies really afford real science, or were them just betting their petty cash in case someone got lucky?

I can’t answer those questions, nor if it’ll ever be possible to have real science in the software industry. But I do plea to all software people to think about this when they teach at university. Please, teach those kids how to think, defy the current models, challenge the universality of the Turin machine, create a new mathematics and prove Gödel wrong. I know you won’t try (by hubris and self-respect), but they will, and they will fail and after so many failures, something new can come up and make the difference.

There is nothing worse than being wrong and not knowing it…


« Previous entries Next entries »