Archive for the ‘Javascript’ Category

Tim’s Guide to JVM Languages.

Donnerstag, Dezember 1st, 2011

JRuby: for people who realize the Ruby interpreter isn’t that hot performancewise or –more likely– whose sysadmins refuse to deploy anything but jar files. Vaguely useful in case you absolutely require a Java library for a script that involves opening a file, parsing xml, printing to the screen, adding two `byte`s or something similarly impossible to do in Java without becoming so enraged that you end up twisting some cute little animal’s head off.

Jython: see JRuby

Groovy: for hardcore Java nerds who don’t want to admit to themselves that Java isn’t the be-all end-all of programming by resorting to JRuby or Jython. Because for unknown reasons, groovy is somehow „more“ Java.

Scala: for people who feel Java isn’t special enough for them, because they’re very special. Yet they’re too limp dicked to use haskell or erlang. In all honesty, they would prefer to use ocaml, but the JVM handles cache line optimization in Intel’s upcoming Larabee architecture better and they need to squeeze every last bit of performance out of their „boxen“. They also enjoy using important words like „contravariant“ that noone including themselves understands. This makes them feel even more special.

Fantom: see Scala, add: for who Scala is too mainstream because Twitter and one other company allegedly used it a some point.

Clojure: see Scala, but switch „scheme or lisp“ in for „haskell or erlang“, feeks slightly less absurd than Scala to me.

JavaScript: oh-my-god just go ahead and scratch my eyes out, why in hell would anyone … oh yeah, it ships with the JVM (no joke). The „embedded language“ of choice in case you need to embed some language into your Java desktop software.

JavaFX: sadomasochists with a serious Sun Microsystems fetish who have wet dreams of Dukeâ„¢ (the little java dude) gnawing their balls off. They also really hate Flash and want to stick it to Adobe. But they haven’t heard that Adobe discontinued it or that you can do „mouseover“ effects in HTML5 thus enabling Rich Internet Applicationsâ„¢ without Appletsâ„¢.

All of the other JVM languages are either someone’s uni dissertation or total bullshit. Except for Frink which is pretty awesome but not really a general purpose programming language.

That said, Java is a really annoying language, but so are all other computer languages that don’t live in the JVM to some degree. It’s perfectly possible to write solid and useful code with it.

(this rant originally posted by me here. I updated it with a link to cute animals and frink)

Javascript Editor.

Samstag, November 25th, 2006

maennchen.pngTrotz tiefgründiger Abneigung gegen Javascript (zumindest sofern’s im Browser läuft), erwische ich mich immer wieder dabei, blöde Tricks in Javascript zu implementieren. Um mir dabei behilflich zu sein, habe ich vor einiger Zeit einen kleinen, browserbasierten Editor gebastelt und per Copy & Paste von Projekt zu Projekt mit mir herumgeschleppt.

Inszwischen bin ich dazu gekommen, diverse Bestandteile zusammenzutragen und zwecks einfacher Wiederverwendbarkeit zu einem Päckchen zu schnüren. Dank eines genialen Bookmarklet, kann man den Editor sogar an beliebige fremde Seiten tackern, und mit den Javascript Elementen dieser Seiten interagieren.

`sprintf` in Javascript

Montag, November 13th, 2006

Schon tausendmal gemacht, aber ich konnte es mir nicht verkneifen meine eigene unvollständige Javascript sprintf Implementierung zu schreiben:

[viewcode source=“sprintf.js“ link=“yes“ scroll=“yes“]

Unterstützt werden die folgenden Formate:

%o : numerischer Wert, oktal, Format: 0…
%x : numerischer Wert, hexadezimal, Format: 0x…
%b : numerischer Wert, binär, Format: 0b…
%d : numerischer Wert dezimal
%s : „normale“ Zeichenkette

Prozentzeichen können durch %% dargestellt werden.

Beispiele:

sprintf ("%s, %o, %x, %b", 17, 17, 17, 17)

=> 17, 021, 0x11, 0b10001

sprintf ("Alles Gute zum %d. Geburtstag, %s %s!", 88, "Frau", "Schmitz")

=> Alles Gute zum 88. Geburtstag, Frau Schmitz!

Außerdem wird die eigebaute Javascript Klasse String um die Methode, fmt ergänzt. Dies erlaubt, dass Zeichenketten unmittelbar als Formatstrings verwendet werden können:

"%d.) %s".fmt(1, "an erster Stelle...")

=> 1.) an erster Stelle…