You are currently browsing the archives for the concept tag.

Unified TUIs

I do not like software using complicated GUI to achieve simple operations. For example, why use ThunderBird or Evolution, when one can use mutt ? Why use X-chat when irssi is available (and can run in screen) ? Why use Totem or VLC when Mplayer does the job ?

There is a pattern here: if possible, use a TUI.

I have reasons for that: first, it does not require advanced graphical capabilities; second, TUI are light and can be run through ssh; third: sobriety and minimalism; and last, it's prettier1.

After using this type of software, there is an obvious step: writing TUI. And this is far too clumsy. There are basically two2 way of doing it:

  • Doing all the UI using ANSI escape sequences3
  • Using ncurses

This is evidently a non-choice and anyway, almost all languages — even JavaScript — have ncurses bindings, so why even think about doing something else?

The problem is that each API is different, here is an example. Let's say I wan't to do something basic: clean up the terminal, write Syntactic Sugar and wait until a user presses q to exit. Pretty easy, no ?

Not that easy though. I won't put some code is several languages, but here are the step one has to take in order to implement this program:

  1. Initialize the screen
  2. Set up different options (echo off, etc.)
  3. Add the string to the current screen
  4. Start a input loop

The problem is there are no common conventions: let's assume that the screen is stdscr and that the function to add a string is addstr, should one use :
curses.addstr(stdscr , "foo") or stdscr.addstr(foo)? This depends on the language and on the bindings. Well, that's still ok, some languages have no objects, blah.

But the funny thing is not only how the functions are called, but what they do. For example, in C, there are 4 different functions: addstr, mvaddstr, waddstr, mvwaddstr; in Python there is just one function: addstr which takes different kind of arguments; in Ruby it's like in C; etc.

As I like to say, modern developers are not attached to one languages, but use the languages that fit their needs. I use OCaml, JavaScript, PHP and C on a regular basis, but I also happen to use Python from times to times4. The thing I'd really like is to be able to have advanced UI to the software I write, without having to learn and master several API.

I don't have any miraculous idea, but I may have a beginning of solution. I think one of the most important thing in programming is to learn from what other have done before and never reinvent anything5. This might look like heresy to some, but I'm pretty sure that a client/server model would be ideal to manage TUI, using the web as an inspirational source.

Basically, serving web applications is pretty much the same thing as writing a TUI6: there is a backend, written in whatever language you want, and a frontend which presents information and interacts with the user. I'm convinced this can be transposed to plain old terminal applications.

What I suggest is an XML format to describe the application layout, some kind of CSS to style the application and a script language7 to deal with events. This would have mainly two consequences:

  • No more complicated/cluttered/different API to master
  • The output of the application is independant of the platform

The first point is obvious: it was what I was looking for. The second is much more interesting: as the web is currently shifting to a platformy thing where content gets replaced by data flow and the page model shifts to an applicative model, I'm pretty confident that having applications which may run as well online and in a terminal might be the future of the TUI8.

Anyway, that was just a morning thought which got much more longer that I intended…

  1. but that's subjective []
  2. in fact, three, but I won't talk about S-lang, it's much like ncurses []
  3. this is very much like trying to write some advanced software in assembly… []
  4. and I should learn Ruby and Perl in the near future []
  5. except if you can do better []
  6. though Web 2.0 apps are usually more eye candy… []
  7. JavaScript ? ;) []
  8. after all, why should web 2.0 only be about GUI? []

Prototypes, Objects, Functions, etc.

As I said previously, I really like prototype based languages. In those languages, an object if a hashtable with a link to a prent object (for empty slots).

An object can also be seen as a function explicitly defined which associates an object to an object. Moreover, this object has two more features: the value of a slot can be changed, and there is some kind of inheritence (the parent object).

Functions can be seen as extensions of objects.

Before going further, I'd like to clarify something: I will consider that there are no differences between objects and functions. Everything is an object, even functions. In order to do so, the definition of an object has to be extended: an object's slot are not constants, but patterns:

def o = {
    "foo" -> "bar"
  | "bar" -> "baz"
  | 42    -> "Doug'"
  | n     -> n+1
}

This object has two methods "foo" and "bar", a slot 42 whose value is "Doug" and a slot n which returns n+1 (with the convetion "plop"+1 = "plop1"). Moreover the method is called using the following syntax:

o "foo"; // = "bar"
o.foo; // = "bar"
o 42; // = "Doug'"
o 41; // = 42

Thus when we write foo bar baz, we apply the object foo bar to the argumente baz. It's some kind of curryfication. Here is another cool example:

def fibo = {
    0|1 -> 1
  | n   -> this n = this (n-1) + this (n-2)
};
fibo 10;
fibo 20;

Fibo is well know, but here there is an implicit and automatic memoization, which is really awesome.

I have a few other ideas, but I'll keep them for another day ;)

A few blog ideas

There is a category of blogs which have some kind of success based only on their concept. I don't talk about usual blogs here, but about those crazy, stupid blogs which can be so amazing. Here are a few ideas for those who would like to start one:

Will it fit in my nose

Everyday a new object, and the same question Will it fit in my nose. A few pictures, some videos and a few words: a whole new way of comparing objects.

The Techno Test

Regularly (once or twice a week) a tech style test of an everyday's life object : plain corn, soap or the mailbox. Thoughts about the licence, accessibility or packaging might be interesting.

Feed Me Tonight

Everyday the blogger publishes the content of his fridge; the readers then make his dinner's menu. When the fridge is empty, the readers might suggest a few ideas. There is a high interaction, and it's a nice place to put some food pictures, videos and recipes.

Show Debugging

Studying movies and TV shows, tracking down all occurences of on screen source code in hackers movies and analyzing the code. Bonus : same thing with maths formulas.

A universal API

The web is currently living a silent revolution, with platforms such as MySpace or FaceBook. I don't really want to talk about those, but let me just say a few word about their future.

Recently, Jeff Hubber (Google) has said the the web is the platform. Whereas this might seem prententious, there is some truth to it : closed platforms will attain their limits one day or another. Those platforms actually believe that transposing to the internet the model of environment based applications will work on the long term. This is nonsense, we are currently evolving in the so called Web 2.0, which aims to be interoperable and based on content flow.

So, I thought about this idea of web as a platform, and I believe that some kind of universal, open source, API should exist. Here is the context in which we are :

actuel.png

There are a great number of services, each providing their own API.

On the other hand, a universal API would look like this :

api.png

This would free the developers from the service, as they would have access to a few primitives in charge of getting the information from the right place, and they could concentrate on the features of their application.

Basically, most current web services provide APIs, so it would really be nothing more that some glue

A modular architecture :

  • A core containing generic functions (get_user, get_bla)
  • A lot of interfaces between the core and foreign APIs

For example, if someone want to write a photo widget, he could the use the following (without bothering about which service is actually used) :

$my_widget = new UAPI(UAPI::PICTURES);
$my_widget->import("flickr", "fotki", "zoomr");
$my_widget->flickr->connect("login", "pass");
$my_widget->fotki->connect("login2", "pass2");
$my_widget->zoomr->connect("login3", "pass3");
$pics = $my_widget->get_pics();
foreach ($pics as $pic)
{
  echo $pic->url;
  foreach ($pic->tags as $tag)
  {
    echo $tag;
  }
}

Of course, this can be extended to any service, not only image hosting.

I think that the day this kind of abstraction will exist, then the web will become the platform de facto

Parametrized CSS classes

Something I just hate about CSS is that a class is static. Let's say I want to include a picture in a page and that depending on the picture I want to align it to the left with a 1px top border and a variable right border, of align it to the right with a 1px bottom border and a variable left border. And let's add that all images should have a 10px padding.

The obvious solution is to use something like this :

.images {padding:10px}
.left {float:left; border-top:1px solid black}
.right {float:right; border-bottom:1px solid black}

<img class="images left" style="border-right:5px solid black" src="image.png"/>

This is highly impractical. That's why I've been asking myself for quite some time why there is no parametrized classes in CSS. To clarify that, here is what I'd consider to be a good solution :

.images(pos,L) {
padding:10px;
float:[pos];
border-[!pos]:[L]px solid black;
border-[pos: left => top | right => bottom]: 1px solid black;
}

<img class="images(left,5)" src="image.png"/>

Inside the block {}, the brackets would indicate that the content has to be evaluated. With a few simple primitives, it may be quite powerful:

  • negation : [!var]. example : if [pos] = left then [!pos] = right
  • switch : [var: case1 => res1 | case2 => | res2 ...]

Moreover, something nice would be infinite level of nesting. Who has never been stuck while trying to style nested lists ? For example, let's say we want to print a list and that each level of the list should be half the size of it's parent, this is what we should write:

/* root */
li {font-size:2em};

/* recursion */
li li {font-size:[$1(font-size)/2]}

Here, $1 refers to the first pattern (the first li), and $1(font-size) is evaluated. With such a system, it would be easier to do more complex stuff. The question really is : why doesn't it exist ?