# Java just won’t manage Non-Primitive Numbers

I just stumbled over something really funny; something that would fit to the Watman lightning talk by Gary Bernhardt. As you may know, Java is jet another language that copied a really great programming language of the visionary Alan Kay, named Smalltalk. In Smalltalk everything is an Object (yes, really really everything! So even classes are objects, describes by meta-classes – even creating a subclass is done by sending the superclass a message, to which it replies with a subclass!) and all programming is done by objects sending and receiving messages, and answering to them. This is why in OOP, you don’t have functions but methods. A function can be called – it can be applied to values. So you actually define what to do. In OOP, an object decides on how to properly react on a message. It does so by looking up it’s methods on how to react on the received message. But how it will react is totally up to the object, it’s even possible that many different objects reply to the same message by using different methods; a function on the other hand is unique. But the key idea is that while in imperative programming you see and apply the function, in object-oriented programming this is a black-box to you (unless you programmed the method).

But I digress. Coming back to Java, when it was developed, it wanted to implement OOP, but on the other hand it also wanted to keep up with the speed popularity of C. So not only did the syntax change to be more C-like, but also a lot of things that work purely object-oriented in Smalltalk where implemented as they are in C. This also applies to numbers, they are primitives; values that lie in RAM, values on which functions are applied to. Now, this may sound totally normal to us – we don’t think of a number as an object, which we ask to do something, and then see if it does it, or not. But with Smalltalk, that’s exactly how it’s done:

1 class
=> SmallInteger

1 resondsTo: #+
=> true

Other pure object-oriented languages, such as Objective-C or Ruby (example below) behave in a similar way:

1.class
=> Fixnum

1.respond_to?(:+)
=> true

So how does it work? + is a method, same as any other method – with the exception that it is written in a special way, so that it can be used more human-readable, in an infix notation. #+ and :+ are symbols in Smalltalk/Ruby, which are used to identify the method. Say you have a method called println(), the symbol would be :println in Ruby or #println in Smalltalk. Ruby allows us to send a message to a object not only by naming the method, but also by using the send()-Method, that every object understands, and where the first argument is the the symbol of the method and the following arguments are arguments accepted by the method. So, here it should become obvious that + is actually a method and the second number (another object) an argument:

1.send(:+, 2)
=> 3

The Answer to the message is actually a new object. Not so in Java. Primitives are non-object values

System.out.println(1.getClass());

=> Unresolved compilation problem:
Cannot invoke getClass() on the primitive type int


# researchr on Linux (Addemdum to Computer-aided Scientific Workflow)

In my last blog entry, I presented the extemporary, yet neat solution for an academic workflow, which was unfortunately limited to Mac. Though I own a MacBook myself, I am also very passionate about Linux and like to find solutions that are plattform-independent.

I already suspected, that given setup should be easily portable to Linux, only the Open Source tools Skim and BibDesk would take some deeper programming, as they depend on the Cocoa Library. But one could find alternatives:

So the presented workflow should be more or less reproducible on a Linux system. Get a feel for why this workflow is – in my opinion – ingenious, and then try porting it to Linux. The community of scientists using Linux will most definitely appreciate it.

One way to replace Skim and BibDesk would be to turn to an integrated solution, such as the Cross-Platform solution Mendeley, which uses the Qt framework and is therefor available for Linux, Mac and Windows. It is similar to Papers, but in my opinion, Mendeley seems to be much leaner. It also offers some social-network features, that other reference management systems lack.

The Ph.D. student Bodong Chen (who incidentally also studies at the University of Toronto) tried it, and seems to have succeeded. On his researchr-Wiki he gives some pointers on how it’s done (and it seems, like he also tried to do so on Windows, but as I suspected, there seems to be no success).

So, to all you Linux-Heads out there, here’s a solution for you, too. Try it out, make it better, document it, and give me a link, if you do 😉

# Computer-aided Scientific Workflow

In Hamburg (at least ten years ago) when you went to Gymnasium, at some point you would learn about something called methodological competences, a “learn to learn” course showing you how to conduct research for the topic of interest, how to then efficiently read through texts, take notes, organize these notes and finally – as a preparation for the finals – how to learn and present these things.

It was this course, that at our school was thought in a two weeks seminar on Sylt, that got me interested in this topic. Of course, in 1999, when we had that course, it was still all about the analogue world – literature was obtained at the library (we even learned how books are sorted in the Staatsbibliothek), texts were photocopied, we were told to use highlighters, write flashcards, etc. Still every now and then when my interest on this topic awoke again, I started reading about new ideas on how to efficiently and effectively process knowledge that you obtain while reading and how to preserve this knowledge in a way that makes it usable even in ten years time. Now the most famous person managing this would be Niclas Luhman who was meticulously writing down every thought on every book he ever read onto little papers, numbering and tagging them, keeping handwritten indices in lookup-table. In many interviews he explained how he worked, stating, that he wouldn’t even need to write a book anymore – with this system, called Zettelkasten he’d look up important words, and the story would tell itself. He even spoke of it as a person with whom he was leading a discussion – his alter ego (see this German article on Sciencegarden as well as the following interview).

After his dead in 1998 the Bielefeld University bought the Zettelkasten from the heir: 20 000 sheets, in 80 boxes, everything Luhman was thinking in his lifetime – and as he was well recognized for his works, this was treated as the holy grail of wisdom on sociological systems theory, and as far as I know it’s even analyzed today.

But what to do, when you don’t have that much time? When you simply cannot afford to spend your every days evenings creating, tagging, indexing and sorting new sheets of papers into a giganteous pile, that most people would rather consider to be the symptoms of a hoarding personality disorder?

# Computer Scientists having fun

Normally this would be something I’d put into my personal blog, but I guess, this one is too special for an audience that doesn’t have a CS background, so I somehow feel it’s in better hands here.

So to have some fun, the Computer Science student Michael Walker, also known as @barrucadu, implemented a Markov Chain (see his source at github) in Python and plugged it to a tumblr account, so it would generate answers to questions.

Now for the funny part: The Markov Chain is only trained with two books, both equally fundamentally important. The first one is the Bible, as translated by King James into the English language. The second one is not that familiar to Non-Computer Scientists, but in CS regarded as one of the more important books. Published in 1984 by Sussman and Abelson for their undergraduate Computer Science course at MIT, the book is even today the foundation of beginning CS classes all around the world. I’m talking of course about Structure and Interpretation of Computer Programs, which teaches all the basic concepts of Computer Science using the LISP dialect Scheme which was also designed for just this teaching purpose (and now evolved into Racket) by one of the authors.

Having put those two together, you can now ask this program questions via tumblr, and the program will answer you with such wisdom as:

In the beginning there was the word. And the word was Content-Type: text/plain.

or

And I will make all my goodness pass before thee, and our sins be upon us, because of our use of not and lisp-value.

So if you’re up for some really nerdy humor, just visit KingJamesProgramming. 🙂

# Non-breakable Space Problems

On OS X and apparently also some Unix-based machines you may have encountered a strange behaviour (in my experience especially on Laptop keyboards). On the shell it sometimes might just happen that you pipe something and get an error message. E.g.

pygospa@lalaith ~ % ls -ahl | grep .log
zsh: command not found:  grep

Retyping it may then bring you:

pygospa@lalaith ~ % ls -ahl | grep .log
-rw-r--r--    1 pygospa  staff    54B 15 Nov 11:55 tmux-client-8140.log
-rw-r--r--    1 pygospa  staff    24K 15 Nov 11:55 tmux-server-8142.log

So, what just happened? To me this actually happens so seldom that I never even bothered to try understanding. Therefore I often encountered another problem wich started annoying me. When editing a TeX-File, every now and then I got this error message:

! Package inputenc Error: Unicode char \u8:  not set up for use with LaTeX.
l.193 \end{align*}


I discovered that rewriting (not copying!) the line does some good. So it had to be some non-printing control character, and after searching for “OS X, Latex \u8 error” (I initially assumed that it must be an OS X thing, as I never encountered it in LaTeX on my Linux days – I now assume that it’s rather a Keyboard thing) I found a quick and dirty solution to it, adding this line:

\DeclareUnicodeCharacter{00A0}{ }

So the non-visible Unicode sequence was overwritten with a space. And thus I was never bothered again when editing LaTeX.

But now, while writing some RSpecs for a Ruby on Rails project I am working on it occurred again, and in RSpec there’s no quick and dirty solution that can be written into some preamble to fix an input error.

# dyld: shared cached file was build against a different libSystem.dylib, ignoring cache

After my last update of OS X 10.8.5 my terminals were flooded with above message – like twenty-ish lines when I started and up to six times after each console command I issued, making it impossible to work with the console anymore.

The error message also told me to run update_dyld_shared_cache and restart my machine. That’s what I wanted to do, but when I issued the command this is what my computer presented me with:

pygospa@lalaith ~ % update_dyld_shared_cache
update_dyld_shared_cache failed: you must be root to run this tool

So I switched to my administrator account which who is in sudoers and typed in the command again:

eru@lalaith ~ % sudo update_dyld_shared_cache
update_dyld_shared_cache: for arch i386, can't put /usr/lib/libtidy.A.dylib in shared cache because it is not owned by root
update_dyld_shared_cache: for arch i386, can't put /usr/lib/libncurses.5.4.dylib in shared cache because it is not owned by root
update_dyld_shared_cache: for arch i386, can't put /usr/lib/libutil.dylib in
(...)

There where at least 50 of those lines, and as it seemed nothing had been done, so I checked the permissions and as it turned out, all files in /usr where in possession of root except for /usr/lib, which belonged to the administrator. Huh, that’s strange. Anyway, let’s run it with the rights of the administrator then:

pygospa@lalaith ~ % update_dyld_shared_cache
update_dyld_shared_cache failed: you must be root to run this tool

Okay, I actually don’t like changing owners on a Mac, as it might break something, so my first try was to just make the files writeable for everyone. So I switched to /usr/lib, entered a chmod 777 * and got a bunch of permission denied responses:

eru@lalaith /usr/lib % chmod 777 *
chmod: Unable to change file mode on cron: Operation not permitted
chmod: Unable to change file mode on libCoreStorage.dylib: Operation not permitted
chmod: Unable to change file mode on libIOKit.A.dylib: Operation not permitted
(...)

Coming from Linux this is really strange, as eru was in possession of all those files… I tried making the directory writeable for everyone – with the same effect. Okay, let’s switch to root – root can do anything.

You’d think…

root@lalaith # l /usr/lib
drwxr-xr-x 316 eru wheel 10744 15 Sep 18:33 lib/
root@lalaith # chown root /usr/lib
chown: /usr/lib: Operation not permitted

Okay. Now I was really puzzled. What the frack is up with this strange behaviour? I did, what any good Windows User does, when he encounters a problem. I rebooted. Same old, same old. Next stop: Google-Town.

Tried sudo update_dyld_shared_cache -force and sudo update_dyld_shared_cache -root / -force, sudo update_dyld_shared_cache -verify

(…)If you suspect the shared cache is somehow corrupt, you can run: sudo update_dyld_shared_cache -verify which re-creates the cache and compares the result with your actual cache file.

and a bunch of other stuff. Nope. Okay, Apple Support Communities, hosted under discussions.apple.com – sometimes they have pretty good answers. And yep, there was someone with the same problem, and there was an answer marked as “solving my questions”, and it was short, and it just said… what?!

You have a missing or damaged system file. Back up all your data, then boot from your installation DVD and reinstall the OS. Your data will be undisturbed. After rebooting, run Software Update to bring everything up to date. You may have to run it more than once.

You’re kidding. I don’t have time for this, seriously! Fracking Mac, fracking Apple, to hell with this load of crap! I was really angry.

Fortunately I don’t follow instructions straight away, and after a lot of head aching googling and cursing the day, I came across Safe Mode.

Starting up into Save Mode does several things:

• (…)
• Mac OS X v10.5.6 or later: A Safe Boot deletes the dynamic loader shared cache at (/var/db/dyld/). A cache with issues may cause a blue screen on startup, particularly after a Software Update. Restarting normally recreates this cache.
• (…)

Sounds related – and yeah, it solved my problem! Starting into Save Mode is pretty easy: Power down, hold the “Shift”-Key, Power – and keep holding the “Shift”-Key for quite a while – untill the Apple logo appears.

It’ll then take a while – at least on a recent, souped-up Macbook Air it was enough time to brew a new cup of coffee. But it actually came up, I logged in, and: Hey! In Safe Mode the annoying message is gone! Reboot, and yeah, in Normal Mode everything’s back to normal.

# GitHub introducing 2FA

Three days ago GitHub released what Battle.net users might already know: Two-factor Authentication (2FA). 2FA is an authentication method, that uses more than one of the three known authentication factors:

• Knowledge
• Possession
• Inherence

Each of these factors describe a different mean of authenticating a person. The easiest and most spread way is knowledge, e.g. by using password authentication. A password is something that (ideally) only the user that is to be authenticated knows. Other examples include PINs or patterns (such as implemented by Android). Also pretty well-known are biometric scanners, e.g. for fingerprints, iris, voice recognition, etc. These are inherent features of a person, therefore they fall under the third group – you have to be the person to be authenticated. And then there is possession. These authentication methods include magnetic stripe cards, smart cards, RFID tags, but also physical keys. For computer systems, security tokens are becoming famous – a little device small enough to be used as key chain, that have a small displays showing a number that changes with time.

So, while most systems only issue one of these authentication factors, a 2FA system would use at least two of these factors. As mentioned above, Battle.net was one of the first (at least to my knowledge) that introduced a 2FA system as many Battle.net accounts are today worth a lot of money. Battle.net accounts have become a lucrative goal for skiddies – I witnessed this myself as my brothers Diablo II account was once hijacked letting him loose all his characters and probably a lot of money. The Battle.net Authenticator is either provided as a key chain device – or an App wich turns your mobile phone into a authentication device – that only the owner possesses.

Generally speaking, GitHub uses the same mechanism, though it offers more possibilities and uses an open source 2FA token generation, for wich there are many smart phone implementations – most famous being the Google Authenticator – which on server-side is offered by many service providers, including App.net (see instructions), Facebook(!!!) (instructions), Dropbox (instructions), Evernote (instructions) – and now also GitHub.