Remix.run Logo
Refreeze5224 2 hours ago

I wonder at what level you could enforce/how far you could take the idea of "don't allow invalid states to be represented" to a programming language, to prevent this kind of language debauchery.

C does seem to sit at the perfect intersection of language age and low-level access to allow this kind of competition, whereas something like Go seems far less suited for it. Javascript is routinely obfuscated pretty well for human readers. I'm not familiar enough with Rust to say, but I bet with what little I know of its syntax you could create some pretty ugly stuff?

retrac a minute ago | parent | next [-]

> at what level you could enforce/how far you could take the idea of "don't allow invalid states to be represented" to a programming language

Standard ML, Haskell, and Lisp, among other languages are pretty serious about invalid states. One should never be able to break the virtual machine and put it into an unknown state, unless intentionally mucking around with unsafe {} or its equivalent. Rust is often described as being at least partly in the ML family because of its approach to types and safety, which is very ML-ish.

Dependent typing like in Rocq goes even further, and makes it impossible to express invalid algorithms. Expressing practical programs in formal terms like that is rather hard though. It largely goes over my head, for sure.

AlotOfReading 2 hours ago | parent | prev | next [-]

You can write programs of a similar spirit in most languages. C has a programming culture that's much more tolerant of it than say, Python though.

Zig could probably support a similar contest as it grows up.

bunderbunder an hour ago | parent | prev | next [-]

I used to write obfuscated C for fun. I haven’t touched it in a while, but as I recall there are really two C syntax features that unlock most of the “magic”. Whitespace is generally not significant, so you can cram a whole lot onto a single line. And the combination of pointers and weak typing lets you be as anarchist as you like about manipulating data. (Oh, and the preprocessor. The one and - thankfully - only C preprocessor.)

Of the two^H^Hhree, I think that the first is what contributes most to the aesthetic appeal of obfuscated C. The only other languages I’ve used that are as good for making code that looks impenetrable are Forth and JavaScript, both of which share that feature.

(Probably any lisp, too, but for some reason I’ve never actually tried. I can say, though, that the most confusing codebase I ever inherited was written in Clojure.)

So yes, I’m inclined to agree that Rust can be a good language for writing deliberately ugly code, and Go not so much. But for a different, perhaps more trivial reason.

Narew 2 hours ago | parent | prev [-]

With macro rust can surely produce some creative stuff