When the Interview Becomes the Ritual

There is a certain kind of candidate who walks into a technical interview with a very different set of tools than the ones the interviewer expects. For Vidrun, a witch from the ice-locked fjørds of Svalbard, those tools include a sprig of cloud-pine, a pocket full of walnuts, and a deep familiarity with the byte-level anatomy of the JVM.

Tim, the interviewer, has a standard plan: a friendly chat, a coding exercise, a sense of how the candidate thinks. He asks for a classic cycle-detection problem — given a path that may or may not loop back on itself, determine whether the travelers are doomed to wander forever or will find their way to freedom. Vidrun agrees to help, and opens an editor.

The first surprise is that she does not reach for a functional language or a clever recursive implementation. Instead, she starts writing what appears to be Clojure, but with a twist that immediately puzzles Tim: the code appears to be doing IO, loading classes, and manipulating byte arrays — all before any actual algorithm appears.

A Story Told in Bytes

The Clojure turns out to be a gateway. Vidrun explains, with total earnestness, that cycle checking is a tight inner loop and therefore should not be written in a high-level language. The real work, she insists, should happen in Java — or, more precisely, in raw bytes that define a Java class from scratch.

Tim watches, increasingly concerned, as Vidrun builds a classloader to return a single byte array for a particular class. She generates magic numbers ("Every class begins with a babe, in a cafe," she explains, referencing the JVM specification's famously unusual section 4.1). She notes that using class file version 49 avoids the need for stack maps, keeping things simple.

The constant pool count requires careful attention. Vidrun recalls that "22 sufficed then," but Tim points out that 0x17 is decimal 23, not 22. Vidrun's answer involves the javanisse — a small, magical gnome who inhabits every JVM and demands an extra constant be set out for him, lest segfaults occur. Tim sputters, but the byte count stands.

The class needs a superclass (Object), a self-reference, an Iterable interface, and an iterator with hasNext and next methods. Method names begin with lowercase letters by convention only, Vidrun notes, choosing a nonstandard name simply because it is already in the constant pool. There is no <init> method generated, since the class will never be instantiated — saving bytes that javac would have spent.

Illegal by Convention Only

Tim latches onto details as they go by. There are only four variable slots for arguments plus locals — "Og to til javanissen!" Vidrun reminds him, reserving two extra. She stores an iterator into a register that previously held the method argument, and Tim objects: those are not even the same type. "If it were meant to be illegal," Vidrun says sagely, "Sun Microsystems would have made it unrepresentable."

The algorithm itself emerges from the bytes. A pair of iterators are created from a single Iterable argument. One iterator — Jorunn, fast and strong from years of skiing — moves ahead with powerful strides. The other — Bjørn, fat and lazy in register 0 — ambles along at a slower pace. After each step, the code checks whether they have run into one another. If not, the process repeats.

The method body is written instruction by instruction: some sixty bytes of logic, each opcode chosen from memory rather than generated by a compiler. Fewer variables, no superfluous loads and stores, no stack maps, no line numbers. The result is compact — 356 bytes total, against the roughly 580 that javac would have produced.

Unit Tests and the Art of the Ward

Tim, grasping for normalcy, asks about unit tests. Vidrun weaves a story of a looping path in the woods — the riddle's very premise, now serving as a test case. She explains that the code "rhymes with 'chaos'" when asked about its name. Before running the spell, she invokes the four cardinal directions — H, J, K, L — and only the J wind answers, which suits her fine.

The class loads. The cycle detector runs. Tim sits in mute concern, his hoodie glistening with quick-melting frost.

Some candidates would be asked to leave. Vidrun, perhaps, has been hired. She reaches into her pocket, and with slow, gentle movements so as not to startle Tim and send him scurrying back to his burrow, she offers him a walnut.