So Gooey: Can You See The Button?

May 9th 09:43
by why

Time yourself. Here are four equivalent samples of gooeys. Each is trivial. Just a button. And a certain amount of goo. Find that button!

1. JavaFX:

Frame {
  content: Button {
    text: "Press Me"
    action: operation() {
       System.out.println("You pressed me");
    }
  }
  visible: true
}

2. Silverlight (XAML):

<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="MyNamespace.MyCanvasCodeInline">
  <Button Click="Clicked">Press Me</Button>
  <x:Code><![CDATA[
    void Clicked(object sender, RoutedEventArgs e) {
      button1.Content = "You pressed me";
    }
  ]]></x:Code> 
</Page>

3. REBOL/View:

REBOL [] view layout [
  button "Press me" [print "You pressed me"]
]

4. Tcl/Tk:

button .press -text "Press me" -command {
  puts stdout "You pressed me"
}
pack .press

Good job! Your reward is this interview with Carl Sassenrath. An excerpt:

One of the main goals for REBOL 3 is to make many parts of it open source so that it can be supported on a greater number of hardware and software systems without RT needing to do all that. Now developers can help bring REBOL into new products and markets.

Now begin the comments …

22 comments

MenTaLguY

said on May 9th 10:03

Note however, there will still be a kernel of REBOL that is not open source. This factor lets us keep the language 100% compatible between different computers and operating systems.

Sure, sure. Wake me when REBOL’s actually Open Source and I can run it on e.g. Linux/PPC (or natively on anything 64-bit, for that matter…).

That said, a Ruby GUI abstraction in the style of REBOL/View would be pretty cool.

MenTaLguY

said on May 9th 10:05

tap tap tap Hmm, did this thing just eat my last comment?

why

said on May 9th 10:13

Back in 2005 there was a RubyCentral project of that exact nature. See the second item by Andrey Melnik. (Vanished.)

why

said on May 9th 11:13

Oh, what am I thinking! Here’s one for Hackety Hack:

Web.popup {
  buttons("Press me") { say("OK") }
}

Although some things are changing. Like how Web.popup is becoming Window.

Djur

said on May 9th 12:42

Guh. XAML.

Actually, one of the things I’m working on is a little declarative GUI toolkit for Ruby. My current project allows scenario developers to generate custom GUIs, but the scenario developer’s code runs in a separate process from the UI. So they need to be able to declare UI elements and style them and provide them with behavior without letting them go straight to the (potentially insecure) GUI metal. The problem is that it’s more of a ‘user interaction/input’ system than a traditional GUI system—it’s more focused on presenting data and getting responses than on designing widgets.

zverok

said on May 9th 12:52

Seems both Melnik’s 2005 projects are worth notion. Also seems, none of them had been ended. Somebody knows, what’ve happened with my compatriot?

Back to topic. I’m working on Ruby wrapper for this library (much more lightweight than Mozilla layouting), and it has it’s own Markaby-like builder (and it would have it’s own Camping-like desktop framework).

It would do something likewise:

App.run {
button(“Press me”).on_click{puts “You bet!”}
}

Thijs

said on May 9th 13:30

The Amiga was—err, still is, very nice indeed. And REBOL is really nice too. If only it were really free…

MenTaLguY

said on May 9th 13:55

I think one key thing is to make the common case simple. The rule with buttons is that, with few exceptions, they have some text and some code that runs when you click the button. Auf Ruby that pretty much means:


button("Some text") { some_code }

There’s always option hashes for the stuff you need more seldom.

MenTaLguY

said on May 9th 14:03

Hmm, looks like SuperRedCloth(?) isn’t quite up to snuff with closing &lt;pre&gt;&lt;code&gt; yet.

MenTaLguY

said on May 9th 14:06

Well, it seems the Ajax preview matches the real entry completely now. That’s good.

What’s the new recipe for code samples, though?

zverok

said on May 9th 14:32

> I think one key thing is to make the common case simple.

If it was complain for my example (and “on_click” part of it), I can say–it’s Markaby thing. Thus, “just block” is reserved for DOM creation. Something like:

button{img :src=>"1.gif"; span “and title”}.on_click{puts “see?”}

(btw, “code” without “pre” works :)

MenTaLguY

said on May 9th 14:36

I wasn’t picking on your example in particular (more stuff like the TCL example in the original post), although I’ll admit that Markaby is not my favorite thing for templating in general.

(“code” without “pre” means you don’t get indentation)

MenTaLguY

said on May 9th 14:43

Anyway, enough complaining from me! It’s true that .on_click {} is the best approach when you’ve got multiple sorts of event handlers to deal with.

zverok

said on May 9th 14:52

> although I’ll admit that Markaby is not my favorite thing for templating in general

Than, what’s your favourite? Just today the topic was discussed in Russian RoR list, where there was an opinions after erb, lilu, Haml, Markaby, and Zope’s TAL.

(yeah, I’ve noticed)

MenTaLguY

said on May 9th 15:35

I’m somewhat partial to lilu actually, though I’m not really happy with any of them. The big thing is a lack of simple semantics. I’m actually trying to develop my own templating system at the moment.

zverok

said on May 9th 15:44

it’s a completely off-topic yet, but can’t you share in short, what your templating system would look like? i’m very interested in simple semantics!

(_why, don’t ban me, pleeeease)

Nathan

said on May 10th 01:09

I’m a fan of Haml ;).

MenTaLguY, I’m also curious as to what you’ve got up your sleeve.

I’d love to see a nice, declarative GUI framework in Ruby. Preferably one that can have native WMs as a backend, while preserving snazzy Ruby syntax.

kurtiss

said on May 10th 01:37

…and which sample takes the cake for finding the action to be executed when the button is pressed?

MenTaLguY

said on May 10th 13:44

At the moment, what I’m playing with is essentially a substantially less magic version of Markaby. All that stuff with fragments? Gone. (There are alternatives.) The underlying abstraction also deals in byte streams, so it’s theoretically useful for generating more than just XML/HTML.

But I’ll post more about it when I feel I’ve got something genuinely useful. I’d like to find a more declarative approach to do atop this the templating-via-substitution thing that lilu does, among other things.

michael schurter

said on May 11th 09:55

What about good old XHTML + JavaScript?

&lt;input type=“button” onclick=“‘Hello World!’)” /&gt;

Unfortunately blog software seems completely incapable of allowing me to post such beautiful and elegant code. :)

damy

said on May 11th 14:59

… now it would be interesting to see a comparison for interactive 3d objects with video ..

Jim d.

said on May 23rd 15:35

I agree that XAML can be verbose, but to be fair it’s the only example that will run (except for maybe REBOL). You omit the necessary boilerplate code to get the javaFX or Tcl/tk code off the ground.

That said, I agree that xaml can be verbose. However, I’d argue that it’s xml syntax has strengths when it comes to creating design tools around it. I’m sure hand-coders will villify me, but the truth is that GUI design is best accomplished, well… with a GUI.

Comments are closed for this entry.