Meta-Languages Should be Simple Too

Meta-languages and meta-platforms are usually perceived as a complicated solution – Meta-code is a tricky thing. That’s no excuse, however, to make things even more complicated than they should be. The mental cost of thinking in meta-terms is enough: You don’t have to throw other complications in.

UML was never lightweight – A standard that was rolled out with 9 different diagrams sounds more like a committee’s compromise that something usable. When you start using UML meta-programming platforms (“Eclipse Galileo modeling” edition is shipped with a few) you find out just how ridiculously entangled it has become. The excellent Acceleo framework uses 3 different meta-languages (UML, OCL and EMF) to generate Java code that can generate other code from a UML model. Suddenly LISP’s Meta-Object Protocol or Python’s Metaclasses seems like the simple solution. Don’t get me wrong – Acceleo, comparing to other UML-based solution, is a great framework – But enough is enough. It’s difficult enough to write a meta-program in a single language. Two languages are somewhat expected too – A language and a meta-language. Piling 3 or 4 different frameworks into meta-programming is not the right solution – It’s the result of desparately trying to handle an over-complex meta-protocol.

I have some code generation program that I need to implement. Eventually, it will be an Eclipse-based plug-in… But before that, I think I’ll hack it in Python.

(Btw, there are alternatives to UML: OPM and Planguage to name a few. More to come on this)

2 comments so far, add yours

Up the pool

I’m a programmer. As such, it always shock me to see something that just works. That was my feeling when I managed to run Erlang’s pool module. The setup requires some attention, but after that, it’s insultingly simple.

To run an Erlang nodes pool, you need the following:

Continue Reading

Syntactic Diabetes

The following Java code is legal, believe it or not:

public enum MyEnum {
  INST1() {
    public void foo() {
      //...
    }
  },
  INST2...;
}

What the f…?!

Continue Reading

Forgiving those Scandinavians

After learning 15 or so programming languages, in different levels of proficiency, I don’t tend to get excited about a new programming language. Moshe occasionally sends me links to the project websites of new languages. I usually reply that “If you know you’re OOP, you don’t need 5 extra levels of fluff just to get things done”. One of his links, however, hit the bullseye: Erlang.

Erlang stands out in the landscape of new programming languages: It’s a pure functional language. Yes, you’ve read it right: Pure. No pointers, no shared memory, no side-effects. If you want something stateful in Erlang, you have to use special libraries.

Erlang, however, is not an academic language. That radical design derives from very practical reasons. Erlang was designed for a single purpose: To support concurrent, distributed, fault-tolerant systems. Anything else in Erlang derives from this goal. Since that many bugs in distributed systems are caused by shared resources and other mainstream-languages imperative features, the designers of Erlang simply threw them out. You can’t code a casting error in ML, and you can’t code a race condition in Erlang.

Continue Reading

SMTP through SSH Tunnelling in Linux

I don’t know how many of you have encountered this annoyance: You’re using an SMTP server to send your e-mail, but the server is accessible only from within its local network, so you can’t use it if you wander around with your laptop. It was a real problem for me, since I use the CS dept. SMTP sever, which is accessible only from the campus network. When I go home and take my laptop, I can’t use this server to send mail. My previous solution was to send mail through the ISP’s SMTP server, but it requires selecting the outgoing server according my location – and that’s annoying.

It’s probably not a very common problem any more, when more and more people use gmail. I personally don’t like using webmail account – I don’t find them convenient.

But this is not a ranting post: Here’s how to do this.

Continue Reading

SOAB IDEA

I was preparing a sketch-of a solution for the assignment I’m going to give to the students in OOP. It’s a Java program, so I used IntelliJ IDEA. The following piece of code had a warning sign on it:

System.out.printf("0, %s, %s, %s, %d\n",
  reg.getUsername(), reg.getFirstName(), reg.getSurname(), reg.getSalary());

The warning was: “format string does not match the types of its arguments.”

The reason: “getSalary()” returns float, not an integer, so the last arg should be “%f” and not “%d”.

Son Of A Bitch! That cocky IDE watches over my format strings!

The next logical step, I suppose, is to do SQL syntax check to query strings, and then warn against SQL injection attacks (a.k.a “Little Bobby Tables“), and then write code instead of us, retarded humans.

The question is: If an IDE can do that – Why it cannot be a language feature? Why doesn’t the compiler steps in?

9 comments so far, add yours

Minimizing all windows in Gnome

The Gnome desktop environment is missing a very convenient feature: Minimize all windows. The “Show desktop” command (Alt-Ctrl-D) does not toggle all windows to a minimized state. Instead, it gives focus to the desktop window. Than, if you press it again, it does not re-minimizes all the windows, in case you opened new ones. It un-focuses the desktop and raises all the minimized windws – Exactly the opposite of what you expect! I got really annoyed by this, since that I keep on my desktop work-in-progress files, and to get to them quickly I want to minimize all the windows, not toggle the desktop focus. But this is not a ranting post – A solution follows.

Continue Reading

LaTeX and UML, cont’d

I had to re-write some paper I’m working on that included a good deal of UML diagrams, so I used it as an opportunity to examine Metapost and MetaUML in more depth. Here are the results of the experiment, for those of you who are interested.

Continue Reading

Logic Programming, Models and Bugs

A couple of days ago I finally wrapped up an assignment in the Logic Programming course. It took me some time, since I couldn’t find a nasty bug in it. Very embarrasing.

The assignment itself was a classic case of model-driven development, at least in its raw form: The model was half-a-dozen or so statements in first order logic. Based on this model I wrote about 100 lines of Prolog code. The Prolog program generated several hundreds of CNF clauses. A CNF solver took these clauses as a long list and gave a solution. The only problem was, of course, that the solution was wrong.

I looked for the bug inside my 100 lines of Prolog code, in vein. It wasn’t there. The Prolog program was just a simple CNF generator that worked well. It took some data and generated CNF clauses according to those logic statements that I wrote. That’s it.

The bug was, of course, in the model. The first-order logic formulas were wrong. I used a redundant logic variable that created un-needed constraints. I removed this variable and simplified the formulas, and then re-wrote the Prolog program. It took a couple of hours and, amazingly, worked perfectly from the first run.

The size of the bug was a single letter. My original formulas contained the variables “N”, “E”, “C”, “V” and “B”. “C” was redundant. Removing it and re-writing the statements solved the problem.

Moral: Models matter. Every program is based, explicitly or implicitly, on a set of ideas and assumptions. In this assignment I had to write them down, so I got a glimpse of their power. A single wrong assumption can be the difference between “working” and “not working”.

The Devil’s programer would say: “We, at hell.com, solved this problem. We don’t have a model for our programs, so the model cannot be wrong.” He’s lying, of course. All programs derive from a model. In most cases, it is a mental model. It doesn’t mean that it does not exist or that it cannot be wrong. It just means that it is much more difficult to debug it.

Leave the first comment

How To Embed UML in LaTeX

I finally found a way to encode a UML diagram inside a LaTeX document! I’ve been looking for something like this for some time now. Usually I resort to using an external tool that has EPS and PDF export, like Umlet or XFig (don’t laugh – XFig has an excellent vector output). It is not too convenient, though, to switch between writing an article (or a lecture) and editing a diagram. Plus, editing the diagram manually takes more time then just typing it in. So I was looking for some tool that would have the following qualities:

  1. Textual
  2. (Relatively) easy to use
  3. Can be embedded directly into a LaTeX document (the text itself, not the image)
  4. Support more then just class diagrams
  5. High quality graphical output: Vector format (not raster), aligned, manhattan and step paths (I.e, squared arrows, like in the GOF book)
  6. Does some of the layout work for you

I ruled out several posibilites. Cumbersome CASE tools, like Rational Rose et. al., were banned: They’re not textual, produce poor output and require too much work to produce a single diagram. Dot-based tools are textual and does all the layout for you, but do not support step paths and require some work to embed in a LaTeX file. Some LaTeX libs, like XyPic, produce amazing vector graphics, but are very difficult to master. However, this is not a ranting post. Solutions follow.

Continue Reading