lice! : Category Random thoughts, everything about Random thoughts

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


Not so stupid db & and how / why IO works with concurrency in clojure

Murphy, a friend of mine, asked in a comment to my last post ‘does stupiddb support the clojure concurrency model out of the box’. Sadly my first answer had to be ‘perhaps’, since I honestly wasn’t sure, most of it should but the logging caused me headache – since in the worst case it might happen that two threads log at the same time. I wasn’t sure how the writer handles this, and my fear was it might come out mixed.

So I did some research, mainly I addressed it in the #clojure channel – a place where many smart people and me hang around and talk about clojure. My first idea was ‘lets use agents’. Agents are clojures answer to asynchronous but ordered state. Pretty much what logs are.

How do they work? A agent has a state or value, in the case of stupid db this would be a java.io.SomeKindOfWriter. Now we can send this agent functions to execute, and take the new value. This means something like this:

(def log (agent (io/writer log-file)))
; ...
(defn- write-log [out action key value]
  (binding [*out* out]
    (prn [action key value])
    (flush))
  out)
; ...
(send log write-log :assoc 1 1)

This will write the log [:assoc 1 1] if at the same time someone wants to write the log [:assoc 1 2] the one that is send later, will be sent last. So in the case we’ve a transaction that the [:assoc 1 1] transaction fails and needs to rollback to do it again, we would have something like [:assoc 1 1] [:assoc 1 2] [:assoc 1 1] right? That would still be correct since even we’ve [:assoc 1 1] in there twice, the correct value would be the last one in the log.

BUT, big but here, clojure is smarter some smart person in the channel pointed this line out to me:

Agents are integrated with the STM – any dispatches made in a transaction are held until it commits, and are discarded if it is retried or aborted.

What does this mean? Actually it means clojures STM takes care of the problem for us, the send is only fired if the transaction succeeds, that is pretty darn cool! So the log would actually look like [:assoc 1 2] [:assoc 1 1] which is awesome!

So the essence of this is: when doing IO in a dosync, or in a concurrent situation where you can’t guarantee that the io is only fired once, use agents since they ‘just work’. It is very neat and a good solution to the IO issue, I’m really surprised it isn’t promoted more.

Is everything perfect now? Not exactly, since agents are asynchronous the log might be delayed slightly, which isn’t nice :( but well it is a small tradeoff :) for things just working perfectly. If I figure out how to do it right when it happens, or at the end of the transaction I’ll give an update.

Posted by Heinz N. 'Licenser' Gies Mon, 17 May 2010 14:41:00 GMT


GUI's in clojure

There are some nice posts in the interwebs about how to use swing in clojure, it seems the syntax of clojure and the good java interop makes this pretty nice. Especially Stuart Sierra’s series has inspired me a lot since it is pretty details.

But in the end every posts leaves you with the feeling that you’re left alone with java when you really want to do something more then a tutorial. Creating objects, calling setters, getters using static fields. It is ugly to be frank, in his example Stuart did a great job to hide the javaness of grid layout from you, it’s a start but I think everything should be like that.

This is how it looks in the example:

(defn temp-app []
  (let [celsius (JTextField. 3)
        fahrenheit (JTextField. 3)
        panel (doto (JPanel. (GridBagLayout.))
                (grid-bag-layout
                 :gridx 0, :gridy 0, :anchor :LINE_END
                 :insets (Insets. 5 5 5 5)
                 (JLabel. "Degrees Celsius:")
                 :gridy 1
                 (JLabel. "Degrees Fahrenheit:")
                 :gridx 1, :gridy 0, :anchor :LINE_START
                 celsius
                 :gridy 1
                 fahrenheit))]
    (listen-temp celsius fahrenheit c-to-f)
    (listen-temp fahrenheit celsius f-to-c)
    (doto (JFrame. "Temperature Converter")
      (.setContentPane panel)
      (.pack)
      (.setVisible true))))

There is another nice post about the topic on Jeff Fosters blog showing this example:

(import '(javax.swing JFrame JLabel JTextField JButton JComboBox JPanel Timer)
       '(java.awt.event ActionListener)
       '(java.awt GridLayout))

(defn draw-sort [canvas alg]
 (prn alg))

(defn sortapp []
 (let [frame (JFrame. "Sort Visualizer")
 canvas (JPanel. true)
 algorithm-chooser (JComboBox.)
 run-button (JButton. "Run Algorithm")]
   (.addActionListener run-button
     (proxy [ActionListener] []
 (actionPerformed [evt]
  (draw-sort canvas (.toString (.getSelectedItem algorithm-chooser))))))
   (doto algorithm-chooser
     (.addItem "Quick sort")
     (.addItem "Bubble sort"))
   (doto frame
     (.setLayout (GridLayout. 2 2 3 3))
     (.add algorithm-chooser)
     (.add canvas)
     (.add run-button)
     (.setSize 300 300)
     (.setVisible true))))

So why am I showing this examples, someone has already? Because they inspired me to write clj-swing . Especially the second one, while being a good introduction to swing in clojure, is in my eyes very ugly. Taking all that above together adding a few macro mojo and some reading into swing you could get something like this instead:

(def sr (ref '["Quick sort" "Bubble Sort"]))
(def lm (ref '[]))

(defn grid-bag-sort-app []
  (frame :title "Sort Visualizer" :layout (GridBagLayout.) :constrains (java.awt.GridBagConstraints.) :name fr
   :show true :pack true
      [:gridx 0 :gridy 0 :anchor :LINE_END
       _ (label "Algorithms")
       :gridy 1
       _ (label "Button")
       :gridx 1 :gridy 0 :anchor :LINE_START
       algorithm-chooser (combo-box [] :model (seq-ref-combobox-model sr))
       :gridy 1
       _ (button "Run Algorithm" 
           :action ([event]
          (dosync (alter lm conj (selected-item algorithm-chooser)))))
       :gridx 3 :gridy 0 :gridheight 2 :anchor :CENTER
       _ (scroll-panel (jlist :model (seq-ref-list-model lm)) :preferred-size [150 100])]))

Why is that better? Well in my opinion there are some reasons. First of all There are only 2 java objects you really need to handle, aside of that all is clojury. that means you can further macrofy this if you want. Also it embraces clojures nice STM to swings MVC as a model.

(seq-ref-combobox-model sr)
;; and
(seq-ref-list-model lm)

wrap a ref that contains a sequence into a ugly java proxy so the list and combo box automatically reflect the content – all done for you in one call.

It’s by far not done but I hope it is a good start to make clojure a language that can be used nicely in GUI apps, something that sadly never happened for ruby…

Posted by Heinz N. 'Licenser' Gies Sun, 02 May 2010 06:00:00 GMT


Why is it so hard to have multiple languages?

There is one thing that boggels me for ages now, why is it so hard to use multiple languaes on one Computer. Since I sit in Germany here it is a situation I often encounter. Let me explain the problem at hand.

For letters, mails and most of writing I require a german keyboard (layout) to write all the funny german letters like äöüß. Also my laptop (both private and work) have a german keyboard build in - can't change that sadly or only for insane prices.

For coding I relly prefare an english keyboard since the layout is way more programmer friendly, I don't have to use AltGr to get things like curly or edged brackets - I would show you which I mean but just to proove my point my laptop right now refuses to enter them at all.

So it sounds pretty simple in itself, for coding I use an english keyboard - I have one on the docking station at work and a blue tooth one for coding at home. For letter writing use a german keyboard. Sadly it is not, it seems that some smart software developper decided input language should be based on the widnow you're in - doh. so when I take my work laptop from the dock I've to change the input language FOR EVERY FREAKING SINGLE WINDOW! No fun trust me! Even worst it gets with windows login screens and other security stuff, which entirely refuse to accept english keyboard layout. On my Mac it is nearly as bad, the language is window based again but at least it does not tend to randomly forget what I wanted.

The worst was when I tried to switch to german today and since I got fed up with chanign every window I disabled the language chaning - which did not mean he puts all the windows in the selected language just that he now don't let you change the language in them any more - so now I'm stuck with an explorer window with english layout which I guess will ge back to normal after reboot - which will likely be when I want it to be english and it is then set to german for all eternity...

What I don't get about this is why it seems entirely imposible to every OS to base the input language on the device I use. I really really wonder why this is so hard. When I've two keyboards one english one one german one wouldn't be the simplest way to tell the OS 'this keyboard is german that one is english'.

Posted by Heinz N. 'Licenser' Gies Fri, 19 Mar 2010 11:29:00 GMT


Ruby 1.8 vs Ruby 1.9 - the slightly different benchmark

I think there are about one million trillion benchmarks out there that compare ruby 1.8 with ruby 1.9. And about any one of them has a different judgement on things. So I figured hey I’m going to give it a look too.

First of all, what I’m looking at? Nope not the speed of how things execute today, but what it execute. It has to do with some nifty tool I found called SytemTap it offers some utilities to trace what a application is doing. For example, on what I’m looking here, what system calls it performs. This can be quite nifty to see where bottlenecks are.

Before we go into some details lets first think about what that means for the results. They are completely independent from the environment, that is good, meaning a second process running along side won’t influence the results. Then again at times the meaning of them can be quite questionable, admitted I have no clue what about 90% of them even do. A third point is that even a process with no system calls at all can be slow as hell.

Non the less there are some things that, at least for me have a quite clear meaning. so lets take a look at some simple examples.

I took the bm_app_mandelbrot.rb file distributed with ruby 19, jus because well I liked it, I know it’s not the most valid example but it’s output is nice and short and the results had been the same with about any other test I ran.

Ruby 1.9:

sys_munmap              calls:     4    avg time (us):   27     total(us):    109
sys_mprotect            calls:    12    avg time (us):   21     total(us):    257
sys_mmap                calls:    39    avg time (us):    7     total(us):    297
sys_rt_sigaction        calls:    32    avg time (us):    5     total(us):    178
sys_rt_sigprocmask      calls:    11    avg time (us):    5     total(us):     57
sys_read                calls:    19    avg time (us):   36     total(us):    690
sys_rt_sigtimedwait     calls:     1    avg time (us):    7     total(us):      7
sys_brk                 calls:    17    avg time (us):    6     total(us):    105
sys_open                calls:    18    avg time (us):   15     total(us):    276
sys_getcwd              calls:     1    avg time (us):    8     total(us):      8
sys_getdents64          calls:     2    avg time (us):   69     total(us):    139
sys_getrlimit           calls:     6    avg time (us):    5     total(us):     32
sys_getpgrp             calls:     1    avg time (us):    5     total(us):      5
sys_getppid             calls:     1    avg time (us):    5     total(us):      5
sys_getpid              calls:     1    avg time (us):    5     total(us):      5
sys_getegid             calls:     3    avg time (us):    4     total(us):     14
sys_geteuid             calls:     5    avg time (us):    5     total(us):     25
sys_getgid              calls:     2    avg time (us):    5     total(us):     10
sys_getuid              calls:     2    avg time (us):    5     total(us):     11
sys_lseek               calls:     3    avg time (us):    5     total(us):     16
sys_ioctl               calls:     5    avg time (us):    7     total(us):     38
sys_arch_prctl          calls:     2    avg time (us):    5     total(us):     10
sys_newstat             calls:    15    avg time (us):   46     total(us):    698
sys_newfstat            calls:    15    avg time (us):    5     total(us):     80
sys_futex               calls:     1    avg time (us):13408     total(us):  13408
sys_fcntl               calls:     1    avg time (us):    5     total(us):      5
sys_faccessat           calls:    13    avg time (us):    6     total(us):     86
sys_select              calls:     5    avg time (us):    7     total(us):     36
sys_set_tid_address     calls:     1    avg time (us):    5     total(us):      5
sys_clone               calls:     1    avg time (us):   19     total(us):     19
sys_close               calls:    21    avg time (us):    5     total(us):    125
sys_uname               calls:     3    avg time (us):    5     total(us):     17

Lets have a look, there are a hell of a number of words that are hard to understand, but lets just focus on 2 things,

All calls are pretty much even, in the number of calls, okay even with a difference of 38 calls. It is not per se a good thing but once we look ahead we’ll see that, at least it’s not a bad thing.

The second interesting thing is that the call sys_futex took the most time, which makes sense as it is a method used to wait for a memory access so I’d say it’s nothing unusual.

Now it gets interesting, lets have a look at ruby 1.8:

sys_munmap              calls:     6    avg time (us):   30     total(us):    182
sys_mprotect            calls:    11    avg time (us):   20     total(us):    221
sys_mmap                calls:    40    avg time (us):    7     total(us):    295
sys_rt_sigaction        calls:    30    avg time (us):    5     total(us):    151
sys_rt_sigprocmask      calls:2022790   avg time (us):    5     total(us):10252567
sys_read                calls:    20    avg time (us):   11     total(us):    227
sys_brk                 calls:    22    avg time (us):    6     total(us):    148
sys_open                calls:    21    avg time (us):   10     total(us):    222
sys_getrlimit           calls:     2    avg time (us):    5     total(us):     10
sys_getpgrp             calls:     1    avg time (us):    5     total(us):      5
sys_getppid             calls:     1    avg time (us):    5     total(us):      5
sys_getpid              calls:     1    avg time (us):    5     total(us):      5
sys_getegid             calls:     3    avg time (us):    4     total(us):     14
sys_geteuid             calls:     3    avg time (us):    5     total(us):     15
sys_getgid              calls:     2    avg time (us):    5     total(us):     10
sys_getuid              calls:     2    avg time (us):    5     total(us):     10
sys_lseek               calls:     2    avg time (us):    5     total(us):     10
sys_arch_prctl          calls:     2    avg time (us):    5     total(us):     11
sys_newstat             calls:    21    avg time (us):   11     total(us):    249
sys_newfstat            calls:    15    avg time (us):    5     total(us):     81
sys_faccessat           calls:    13    avg time (us):    6     total(us):     87
sys_set_tid_address     calls:     1    avg time (us):    5     total(us):      5
sys_close               calls:    24    avg time (us):    5     total(us):    136
sys_uname               calls:     3    avg time (us):    5     total(us):     16

Okay here sys_rt_sigprocmask is most interesting, alone cause it is called like 2 million times o.O I think we can agree that there is a difference to ruby 1.9 even without exactly knowing what the heck it is doing. So I did a bit of research cause that kind of jumped in my attention, it sets some kind of flags for the process.

Doesn’t sound so bad does it? Now you’ll love to hear this: about most of them do exactly the same, and when I understood it correctly the call should not do anything in that case.

A little quote:

rt_sigprocmask changes the list of currently blocked signals. The set value stores the signal mask of the pending signals. The previous ac- tion on the signal is saved in oact. The value of how indicates how the call should behave; its values are as follows: SIG_BLOCK The set of blocked signals is the union of the current set and the set argument.

Now I modified the SystemTap script a bit to show me what kind of sys_rt_sigprocmask calls are made and it reveals that the majority of them use SIG_BLOCK and a null pointer for the new set. Now when I understand this call correct this is a completely useless call to remember the man page, ‘the set of blocked signals is a union’ and some basic math one might get the feeling ‘a union with an empty set is the set itself’

What does that say? Honesty in full extend that is pretty much open to interpretation. If you’d ask me, it says that there is no question a huge improvement in the code from 1.8 to 1.9.

If someone has a nice long script that runs out of the box and is not some kind of serve that will run forever, please let me know. I’m still looking for other tests on this.

Posted by Heinz N. 'Licenser' Gies Sat, 02 Feb 2008 00:55:00 GMT


OS X and case sensitivity

Okay,

Today I’ve something a little sad to write about. I am, as so many people lately, a mac user. I love OS X and the software for it, yet I stumbled about something that pretty much dissapoints me.

Okay to get to the pint, in the latest versions OS X allows to use ‘HFS+ case sensitive’ which is a great thing and I assume a lot of the people from the unix world are pretty happy about it. It’s cool, after all OS X is a unix system right should be a nice feature (and about time that it came)

WRONG! Using the case sensitive HFS+ can pretty much wrack your entire system and render it useless. Here is what I found:

Case sensitive and Adobe

I just would like to say here, way thanks a lot Adobe. Hire some coders that can use the correct case in filenames when you sell software for thousand of dollar!

Just imagine you’re running some design firm and happen to have case sensitive HFS+. Yay reinstalling a dozens Macs! Again very very much thank you!

Okay, so much for the rant. It’s just pretty disappointing it makes OS X kind of look like a bad joke… it also makes me wonder how things will be on Leopards ZFS, will people have to stay with old rusty case insensitive HFS+ when they want to keep using their software?

Abut again, it’s not a fault of Apple in my eyes, they can’t change the fact that some people seem to be too busy counting money them fixing their software…

Posted by Heinz N. 'Licenser' Gies Sun, 10 Jun 2007 19:55:00 GMT


OSS Pizza

Pizza! ——– I guess everyone, well everyone active in the computer scene, knows that feeling? I mean that urge for pizza, like there wouldn’t be any other food on the planet that that one pizza the delivery boy will bring you once you got the order out? Sure everyone does. But did you ever wondered where this urge comes from? Is it just appetite? If it would be then the toast in the fridge would do the same job as a ordered pizza right? But first to a completely different topic, did you ever wondered how all that genius open source coders earn money? I don’t mean that ones that toss out a little program once in a lifetime but people ‘Linus Torvalds’ (perhaps the best known one for writing the first Linux kernel). I mean doing such things consumes *a lot* of time and as commonly known pizza is not for free. Well if you ever wondered about that you’re definitely not alone, some guys on M\*U\*S\*H (a online community) including myself wondered about that some time ago too and, believe it or not we found an answer to *both* questions! The answer is nearly too simple to even get the idea: Pizza delivery! Yes that simple, they worked as pizza delivery boys. The question raises where someone would find time to code such great things that are seen in the open source world when delivering pizza. Again the answer is unbelievable simple pizza boxes, they work greatly as a place to make notes on, smaller code snippets or with big sized pizzas even larger peaces of codes. The fact why programmers love pizza is easy to conclude, as Darwin already stated ‘survival of the fittest’, it is a genetical reason to buy pizza in the result that programmers who bought more pizza not only had more to eat but also might stumbled across one of this useful pieces of code written on their pizza boxes and managed perhaps to pay their bills thanks to being able to doing more (or better work) which raised their chance to survive longer then coders who weren’t able to pay their pizza and by chance were beaten to death with a rolling pin.

Posted by Heinz N. 'Licenser' Gies Fri, 28 Jul 2006 19:54:54 GMT