Hacker News new | past | comments | ask | show | jobs | submit login
Signed Char Lotte (nickdrozd.github.io)
677 points by signa11 on April 1, 2021 | hide | past | favorite | 79 comments



There's a vaguely entertaining esolang ‘Shakespeare’ in which programs look like plays: https://en.wikipedia.org/wiki/Shakespeare_Programming_Langua...

BTW, in the spirit of art that uses two mediums with one source, there's this thing ‘oscilloscope music’: as far as I understand, the same signal goes to the speakers and the display, so it likely doesn't get more raw than that. Though, most of it is abstract shapes.

E.g.:

https://www.youtube.com/watch?v=_6a_nz4uRd0

https://www.youtube.com/watch?v=Y04LBDTsGIk


I wrote a program in Shakespeare once: https://codegolf.stackexchange.com/questions/123378/golf-my-...

It was a lot of fun, and I recommend the experience. You get to figure out control flow (if you've never written a program in anything lower level than C, as I hadn't, you'll need to figure out control flow with just jumps; there are no procedure calls or looping though there's "if"), and then there's some room for creativity in choosing the character names and scene descriptions.


> love 1s *!(not= atoi(let

Probably my all time favourite C fragment.


A close second for me is

    goto hell;


When I first read Perl I was convinced all its advocates had some deep seated emotional problems. They kept insisting that the program would perform an action “or die”.


If you turn strict off, you can have

    doIt() or die screaming
as literal code.


If you make a screaming sub, that doesn't even require foregoing strict:

    $ perl -E 'use strict; use warnings; sub screaming { "SCREAM" } sub doIt { 0 } doIt or die screaming'
    SCREAM at -e line 1.
Hell, we can go full English if we want:

    $ perl -E 'use strict; use warnings; sub screaming {"SCREAM"} sub it {0} sub do {0} do it or die screaming'
    SCREAM at -e line 1.
For those following along that aren't quite as familiar with Perl, that's a statement "do it or die screaming" which is all completely valid, strict and well defined Perl. When not a one-liner, it would be:

    use strict;
    use warnings;
    sub screaming {"SCREAM"}
    sub it {0}
    sub do {0}
    do it or die screaming


Today git informed me that it "could not detach HEAD" and refused to merge my work with that of my colleagues.


Better than when it does detach your head.

There seem to be about 77 different ways that can happen and 573 different ways to fix it, and if you do the wrong one, then everything's screwed for everyone, and the history log is useless or obliterated; there's no undo.

If you haven't flogged it enough, you can try to reflog it, but really the only safe thing to do is kill the clone, birth a new clone, and start over.


Did you forget to grep your man for release?


Agreed! But I'm confused, how does the "1s" work? Is that some kind of old-school definition of a short int literal?


Exactly. TFA has a bit more detail.


Not that old-school. It’s not depreciated or anything.


It is old-school, and while it's not technically deprecated that's only because it never made it into the C standard in the first place.


If you speak Japanese (or can tolerate a machine translation), Yusuke Endoh, one of the best IOCCC winners all time, is writing short summaries [1] of every winning entries over the course of this year. Recommended as a starting point.

[1] https://mame.github.io/ioccc-ja-spoilers/


Brilliant explanation.

Since its "hiring day"; I'll ask: If you were interviewing someone and they listed an IOCCC win, would you count that as a plus? would you have to go look at the entry first?

And turned around: if you've won (or even submitted an entry) to IOCCC, would you mention it when applying for work?


For sure, as long as that's not how they/I write code normally! :D It demonstrates very in-depth understanding of the structure of the language, just as any good writing demonstrates expert-level understanding of natural language.

Two caveats:

- A lot of this knowledge might be kind of useless (for example, how to create unreachable code which nevertheless compiles), but I expect it would be difficult to demonstrate equally thorough understanding of the syntax of a language using exercises or looking at previous work (which ideally uses the minimum of sophistication to achieve the necessary functionality).

- It proves mastery of the syntax, but not of idioms, security, maintainability, speed, or any other metric relevant for production code. These might be correlated, but I'd rather see/present some examples of these as well to be sure.


As an IOCCC winner I've had my winning entry verbatim on my resume for years. It's small enough to look like a decorative footer and it always garners comments.

Your question has another angle: why would I care to work for an employer who looked down on my IOCCC win? It acts as a filter both ways.


Has anyone ever tried to compile it? It doesn't work for me:

  gcc -w 1990/tbr.c
  1990/tbr.c: In function ‘main’:
  1990/tbr.c:7:50: error: void value not ignored as it ought to be
      7 |   e(-8)     ,gets      (1+(    c=q)     )||      exit      (0);     r(0,0)
        |                                                  ^~~~~~~~~~~~~
  1990/tbr.c: In function ‘e’:
  1990/tbr.c:22:43: error: void value not ignored as it ought to be
     22 |  3 ;}e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||exit(1):
        |                                           ^~~~~~~
Similar for clang. I'm sure there is an easy fix, but I don't know what it is.

The program in question, if anyone is wondering, was the 1990 winner of IOCCC "Best Utility" award. Source is here:

  https://www.ioccc.org/1990/tbr.c
The authors explain in rot13: "Guvf cebtenz vf n ehqvzragnel furyy."


Works for me with

    clang -std=c89 -Wno-implicit-function-declaration -fno-builtin tbr.c
Compilers are fussier (with good reason!) than they used to be.


Those flags work with gcc too. A deleted commented suggested adding `int exit();`, which also worked.


exit is a function returning void, which was traditionally coerced to 0 but anymore. Yusuke Endoh's patch [1] is available.

[1] https://mame.github.io/ioccc-ja-spoilers/patches/1990-tbr.pa...


No coercion needed. Pre-ANSI C does not have a void type, so unless otherwise specified the return type of a function defaults to int.


I've almost never had to write or read C in a professional capacity, but if I saw that the candidate was such a geek, it would certainly be a huge plus. There's a huge gap in professionalism and knowledge between people who choose software engineering as a trade because it pays well, and people who love it for the sake of it.

But there's a catch. Second kind of engineer is not only better, but also much more desirable and highly paid, so may be it's an indicator that you should check whether your salary range is high enough and your tasks are challenging enough for someone like that. For some (if not most) roles, 9-to-5, grunt work engineer that just closes tickets and doesn't write new languages in his spare time is really the best fit.


I've been hired at half of the FANG companies and I'm convinced I was hired not because of my direct performance in the interview questions, but I threw in bizarre minutiae about the problems that I've picked up over the years merely because I enjoy trivia.

I also failed an interview (or rather was not offered a job) at one of the FANGs, and I thought I did good enough on the interview portion, but it was the only interview where I didn't have the opportunity to drop some obscure trivia.


I think I did pass an interview once by pointing out to a compiler guy that an array is just a hash table with the identity hash function. Which I'd read in the Haskell manual the day before.


I hope that’s not how you’re implementing your arrays, though!


Having won the IOCCC definitely helps to boost visibility, since it is one extra place where prospective employers can look you up, and it's a fairly exclusive one.

I ended up doing some readability related work at my current job because of (in spite of) my IOCCC experience.


People who win or enter IOCCC are unlikely to be "one-trick ponies", but those who already have very deep knowledge of the language and possess significant creative/problem-solving skills. Fabrice Bellard is a notable winner, for example.


I would rank it with puzzle solving ability, which may or may not correlate with doing a good job.


> And turned around: if you've won (or even submitted an entry) to IOCCC, would you mention it when applying for work?

Yes, but typically as a passing mention. In that way it causes no harm for those who don't know IOCCC and gives me a plus for who know it.


Of course, but I'd be more likely to give the job to the person who could decipher such madness and explain it clearly any day over the author.

Code should be written to be understood by humans first and foremost. The person who can understand such deliberate garbage clearly and explain it well to those who don't understand, well, those people are the perfect human debuggers, in my opinion.


Longest sentence using only C++ keywords, once each:

"If new true friend not protected for explicit private union, break case and try using this".

All C++98 keywords, here.



It reminds me of a darker poem ... https://en.wikipedia.org/wiki/Black_Perl


I was once reprehended for wrting this:

for//ever

(;;){


That's going in my codebase some day


You know it's prose written by a programmer when they use "else" in a sentence where other people would say "otherwise".


My first thought was: "Expenses be damned, sire! We need barracks! Else where will our soldiers rest their mighty lances?" https://www.youtube.com/watch?v=oFQDeYXq_iw&t=21s

Then I realized that Civilization II was created by, well, programmers. Though I couldn't say who wrote the dialogue.



And the poetry looks a bit programmer-damaged too, now that I think of it.



In similar C-string trickery, consider this lovely bool-to-string function:

  /** @brief Construct a String equal to "true" or "false" 
  depending on the
      value of @a x. */
  inline String::String(bool x) {
      // bool_data equals "false\0true\0"
      assign_memo(bool_data + (-x & 6), 5 - x, 0);
  }
Source: https://github.com/kohler/click/blob/6fa978f0188bd0b8a266f65...

Context: This is the source code of the Click Modular Router, a system for implementing packet processing logic with a graph-like DSL. Both primitives, and certain complex logic, are implemented in C++; however, as this has to be able to run as a Linux kernel module or in userspace or as a BSD kernel module, it can't use the C++ standard library, and do has its own stdlib.


I don’t get why bool_data couldn’t be an array of two strings with x indexing into it…


Two pointer dereferences are slower than one - got to read from the top-level array, then use the pointer to read from the individual string. This way you can figure out the address of the string with about four very cheap instructions and zero memory accesses.

Plus cache locality.


> (-x & 6)

wouldn't (x * 6) get the same result?


* is an inherently more complicated action, and takes 3 cycles on x86 and from 3-5 cycles on ARM. & and - are stupid-simple and take 1 cycle, always. The real question is why this isn't done with ~. Possibly some weird embedded platform doesn't have an instruction for it?

I doubt this string conversion code is ever on the hot path for packet processing, but Click is in general written like everything is.


I wonder how you would go about writing something like this. I guess you'd start by writing sensible code, and then tweak and tweak until it was funny and weird and unrecognizable, but still functional?


I'm saddened this does not use the union nor float nor volatile types. It could have ended somewhat better, or perhaps somewhat more dramatically, I think.


As this is a purely creative endeavor, it's your prerogative to turn those feelings into inspiration for your own attempt - nothing sad about it :)


Now's your chance.

Exercises

...

2. Modify “signed char lotte” so as to include more C keywords.


Absolutely brilliant. And deciphering that C was a nice include, no surprise it won the competition.


How does it toggle the value of `get` between runs?

Lots of analysis but the article stops short of analyzing how the core logic works.


It doesn't. You're misreading it. A single invocation repeatedly prints './charlotte' and then loves me/loves me not.

Note in the example he gave on the line '$./charlotte 5'. This is the only line that starts with a prompt ($).


> get = !get;

from the original

> for (get = !get; !out; (char)*lie & 0xD0 - !not)


Scroll down and you'll see a deciphered

    get = !get
That's a toggle.


Just an idle rumination...

It is curious to me how when a programmer does something beautiful and creative, it is (rightly) revered by other programmers, such as this example.

On the other hand, if someone who is not a programmer but is an artist or a writer, dabbles in programming, it is often met with derision and extreme nitpicking by programmers.

In other words, there seems to be a bit of a double-standard, where in one's own discipline one is able to appreciate creativity and art, but if someone else uses dabs of one's discipline in theirs, one can no longer see the artistic merit and can only fixate on the technical limitations.


You're making a category error, the relationship is not symmetrical.

Comparing apples to apples, if the programmer dabbled in artmaking or writing, I'm confident they would get a similar reaction from accomplished artists or writers.

There are many, many, MANY examples of programmers attempting to write, and I'll stick a pin in this to say most of it is not good--if not truly bad--and in both disciplines the number of people who take the difference in expertise as an altruistic teaching opportunity are very few indeed.


Well, to be fair, there are many many many terrible examples of writers trying to write, as well. Sturgeon's Law says 95% of everything is crap. If one has the drive to write, they should try it. At worst, they've wasted some time, adding to the infinite pile of forgotten work. And at best, they might add something interesting to the world, with a different perspective than a writer's writer might bring.

Fwiw, this week I've been reading 'All Creatures Great and Small,' an autobiographical classic by a veterinary surgeon, and quite wonderfully written...

https://en.m.wikipedia.org/wiki/James_Herriot

And let's also remember that JM Coetzee, novel laureate in literature, began his career as a programmer.

https://en.m.wikipedia.org/wiki/J._M._Coetzee

And Ted Chiang was a writer of software documentation, before becoming known for his sci fi stories.

https://en.m.wikipedia.org/wiki/Ted_Chiang


> Comparing apples to apples, if the programmer dabbled in artmaking or writing, I'm confident they would get a similar reaction from accomplished artists or writers.

Yes, this is in-line with what I was, perhaps poorly, trying to articulate. The programmer dabbling in art may get a poor reaction from accomplished artists, much like the artist dabbling in programming may get a poor reaction from programmers.

But that same programmer who is dabbling in art may also get a good reaction from programmers, while that same artist dabbling in programming may also get a good reaction from other artists.

It's precisely that distinction between celebrating those who are in-discipline or in-group and deriding those are out out-discipline or in the out-group is what I am musing about.


It's not necessarily a tribal "in-group vs out-group" thing. If you're trying to impress programmers, you need to do good programming. If you're trying to impress artists, your need to do good art.


I believe this happens in most professions.

When an amateur announces they've created fine art and even dares put it up for auction at ridiculous prices, true artists complain. A lot.

When you architect a building, architects complain about all the things you did wrong. There's even a popular blog making fun of McMansions.

When you build a car in your garage, true car engineers will tell you it's dumb and you missed a whole bunch of important things.

But those are not the folks who are great at their craft. Those are the gatekeepers afraid of newcomers. The greats encourage new entrants because they know the pie can only get bigger.


This is a good point, but it is a bit different from the observation I was trying to make. What I am more observing is that if someone within your discipline uses elements of another discipline and brings it into yours, if it is done well, others who are in that discipline will appreciate it. Case in point: if a programmer incorporates poetry into their code.

On the other hand, if someone from another discipline uses your discipline as an element in theirs, those from whose discipline that element was taken from seem typically unable to appreciate the broader work of art, instead only fixating on how the materials from their discipline have not been used properly. Case in point: if for example a contemporary artist incorporates some programming in their art installation.


A lot of the magic of this post is that it runs and does cool things in addition to the dialogue. An artist incorporating programming into their art installation makes me think of what hackers often do in movies. It's a bunch of gibberish that's intended to look like code. Or technobabble in sci-fi shows, where it's intended to evoke science so smart the protagonist isn't supposed to understand it, but if you do know the field, you recognize it as gibberish. Or a physics t shirt someone buys you because "you're into science, right?" even though it's just a job to you and you're actually a biologist. Or maybe a tattoo of chinese characters that are beautifully drawn but are actually gibberish.

It's the difference between a thing and something intended to evoke that thing, which often comes off as a lazy caricature. If you can't see past the surface level, it evokes what is intended. If you can see past it, but you also see the intent, it's like a charade that falls apart. You know that if you were trying to evoke that same idea, you'd do it a different way that would still evoke the intended thing at the surface level, and additionally evoking the intended feeling in people who understand the subject matter being used.

In the case of OP, imagine if it were just poetry with indentation and parentheses and semicolons in places that make it look like code, maybe with some jquery mixed in with fortran and excel functions. If they mixed jquery with fortran and excel to juxtapose them or something, that's one thing. If they do it because "well that looks like code to me" it's another thing.

I think it really is a feeling similar to being lazily caricatured that drives people to criticize. It fails to evoke the thing the artist intends it to evoke to people who see below the surface.

(didn't mean to rant. you just got me thinking "out loud" and rambling)



Here's a thought. If a poet were presented with this code-poetry, would they appreciate it as much as a coder?

That said, I'm a programmer who took digital media art installation courses in school and I didn't find it to be that different from programming, just with different results/goals. https://cycling74.com/products/max isn't a toy programming environment any more than https://www.ableton.com/en/ is a toy environment or https://origami.design/ is a toy environment. They just have different goals, and perhaps different standards of quality?


I don’t think so. It’s a form of constrained writing (https://en.wikipedia.org/wiki/Constrained_writing).

In such writing, the challenge is to construct beautiful texts despite of artificial constraints.

They wouldn’t understand the constraints, so they wouldn’t be able to understand why nicer texts wouldn’t satisfy them.


Yeah that’s what I was trying to say.

When a wizard from a different house uses your magic, you gotta defend your holy right and exclusivity.

When one of your wizards uses another’s magic, that’s fantastic! No threat to your tribe and might even make it better.


Yes, I like this. That's quite a fun way to get the point I was trying to make across indeed!


> if someone who is not a programmer but is an artist or a writer, dabbles in programming, it is often met with derision and extreme nitpicking by programmers

I've honestly never seen this happen and have no idea what kind of person would react this way.


>> if someone who is not a programmer but is an artist or a writer, dabbles in programming, it is often met with derision and extreme nitpicking by programmers

> I've honestly never seen this happen and have no idea what kind of person would react this way.

Take a look at some HN user responses to when the Google Will Eat Itself art project was posted here [1].

[1] https://news.ycombinator.com/from?site=gwei.org

A couple choice examples of the kind of behavior I am talking about:

> I'm pretty sure it would be trivial to write a program that automatically generates modern "art" exhibit descriptions like this one.

> I'm not sure what's worse, the fact that this is a stupid idea - or the background

And so on...


You are correct but it happens in all fields/passions ...etc E.G. Jazz, you need to be a very good musician to create good jazz. A programmer could create something that creates jazz but jazz musicians will find it lacking, for want of a better word.

Got lost in a train of thought but I hope you understand what I'm trying to say.


Intent means a lot. I feel the Picasso quote fits here somewhat:

> It took me four years to paint like Raphael, but a lifetime to paint like a child

So you could ask why Picassos stylized paintings are revered, but kindergarteners works are not


The sentiment I've heard in many disciplines, but often in art, is that you have to have the skills to follow the rules before you can break the rules in meaningful ways.


This reminds me of the "Perl Poetry" found in the back of the Camel Book. Larry Wall's toes probably curled with glee to know his little language was postmodern enough to admit many examples of that sort of thing.


Could you say that with a type like signed char, it inspires to writing such poetry or plays? I would wager it didn't come from nothing, but from such a strange spark.


What is the me= !oxface supposed to read as?


I read it as "[you] double-time[d] me, oxface", with "ox face" being meant as an insult.


My favorite part are the ;{ emoticons.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: