lice!

clj-sandbox 0.4.1-SNAPSHOT

clj-sandbox 0.4.1-SNAPSHOT is released, it fixesd a security bug in the whitelist tomj reported the other day.

In addition to that an :initial argument can be passed now. It holds a seq of s-exps that will be evaluated in order to allow predefining functions. This is handy to overwrite functions and macros like defn or whatever.

Posted by Heinz N. 'Licenser' Gies Tue, 27 Jul 2010 06:32:00 GMT


clojure swing in real world

I’m currently working on a little tool for my work, one that requires a little gui, a menu, a combo box, two tree views and a text field, most of them interconnected. I’m lucky that I can develop this on clojure since to me it’s a great joy to write in this language. Now I said GUI, and fortunately I’d had clj-swing in my back of tricks and this was a great oportunity for me to test it in real world conditions, now I figured that I share the few things I’ve learned during this last days and weeks.

It works

As absurd this sounds, I was positively surprised of how well it worked and that I had to jump trough little loops to get things working. Of cause it wasn’t all smooth and nice, a few times I had to fall back to java interop but I think it was forgivable in the whole picture. Also it showed me a few things that clj-swing could do better and allowed me to improve it, which will continue to happen :).

The REPL is tricky

I am coding in EMACS+slime and I noticed that swing and slime don’t go along to well, all the seperate treads lead to the point where the swing app locks up for no reason – runnig it with java works fine so.

clojuires mutables are great

We all know this already but I mean great in another sense, it is super easy to store the data in them and see how things automatically update the GUI once the data changes, weehee!

And here how the gui code looks, somet things will go away with in the next clj-swing version and the code for actual actions is in extra functions (as it should be) but this is how you can generate a window with two tree vriews a splitter a combo box and a text field all interacting in one way and another over refs:

(defn -main []
  (let [matcher-cb (combo-box (keys @matchers)
            :maximum-size (java.awt.Dimension. Short/MAX_VALUE 25)
            :action ([e] (combo-box-change-action e)))
  menubar (make-menubar 
     [{:name "File"
       :mnemonic KeyEvent/VK_F
       :items 
       [{:action (make-action 
            {:name "Open..."
             :mnemonic KeyEvent/VK_O
             :handler (fn [_] (open-action matcher-cb))})}
        {:action (make-action
            {:name "Compile..."
             :mnemonic KeyEvent/VK_C
             :handler (fn [_] (compile-action (selected-item matcher-cb)))})}]}])
  text (text-field :editable false :str-ref tf :maximum-size (java.awt.Dimension. Short/MAX_VALUE 25))]
    (frame :show true :menubar menubar
     :default-close-operation :EXIT_ON_CLOSE
     :title "Config Generator 2.0"  :size [600 400] 
     [_ (split-horizontal
         (tree :model (mapref-tree-model raw-data "Data"))
         (stack
    [_ (panel :name p
        :layout (BoxLayout. p BoxLayout/PAGE_AXIS)
        [_ matcher-cb
         _ text])
     tr (tree 
         :action ([old-path new-path]
        (tree-change-action old-path new-path text))
         :model (mapref-tree-model 
           data {:name "Data" :good (good-data? @data)} 
           :node-wrapper (fn [node path] (Pathed. node (str (:name node)) path)))
         :cell-renderer renderer)]
    (add-action-listener text ([e] (check-validity)))))])))

Posted by Heinz N. 'Licenser' Gies Tue, 20 Jul 2010 10:47:00 GMT


On Parentheses

Recently I started to hear too often ‘but it has too many Parentheses’, of course I’m talking about LISP here. To be precise, a LISP called clojure. And to be honest, it gets boring. I find this a quite lame and actually no argument at all.

And now you think ‘oh he’ll go on arguing why they are good’. No I won’t. I’ll just say they have their place. But mostly I will now rant about why this is such a boring argument, that it is stereotypical. It’s not arguing about a language feature, not even really a syntax (since people who scream ‘ewwww Parentheses’ more often than not don’t take the time to actually explore the syntax.)

But it is different – so it must be bad right? Just like black people must be bad because they are different! There is no reason to actually get to know a black person and judge them on their character because, after all they already look different: ewwww! Now if I’d had said that without the tone of sarcasm and without the context you’d likely call me a racist wouldn’t you? But why do we apply these moral guidelines to people and not to language?

You can pick the one icky characteristic from every language and go scream ‘ewww *’ as a good reason never to take a real look at it. Let me humor you and list a few that just come to mind to help you avoid learning any language ever:

  • C – Ewwww pointers!, Ewwww buffer overflows!
  • C++ – Ewww not C!
  • LISP – Ewww parentheses.
  • Ruby – Ewwww sloooooow!
  • Python – Ewwww indentation!
  • Java – Ewwww too much Objects!
  • ASM – Ewwww low level!
  • JS – Ewwww browsery!
  • PHP – Ewwww PHP! (too much here so I just summarize it)
  • VB – Ewwww Microsoft!
  • C# – Ewwww even more Microsoft!
  • Perl – Ewwww unreadable!
  • obj-c – Ewww Apple!
  • Delphi – Ewwww Microsoft and dead!
  • Pascal – Ewwww old!
  • Lua – Ewww not for serious things!
  • MATLAB – Ewww too mathy!

Now we’re through nearly all of the top 20 languages, it is clear now that they are all are horrible. I think people should just stop programming altogether! (Note: Those of the top 20 I do not know at all I omitted for the sake of not giving a weak argument.)

Okay now back to being a bit more serious: Do you see where I’m coming from? No language is perfect. Just because there is one feature that strikes you odd, or even just different, stop. Don’t just judge the language when you’ve never used it.

But now I’ve got to clean up my mailbox so I can receive all the complaints from the C, C++, LISP, Ruby, Python, Java, ASM, JS, PHP, VB, C#, Perl, Obj-C, Delphi, Pascal, Lua, and MATLAB community about how unfair I am to pass judgement on their languages.

Posted by Heinz N. 'Licenser' Gies Thu, 08 Jul 2010 07:30:00 GMT