Elixir Update: No More LCs

Since I started programming in Elixir, I’ve been tweaking some routines to deal with playing cards. Chief amongst them is the deck creation function:

  defmodule Deck do

      def create do 
        # 52 cards, unless otherwise specified?
        lc rank inlist ['Ace',2,3,4,5,6,7,8,9,10,'Jack','Queen','King'], 
           suit inlist ['Hearts','Clubs','Diamonds','Spades'], 
        do: Card.create( rank, suit, Card.init_points(rank) )
        |> shuffle 
      end 

      [...]

  end

This routine uses the list comprehension syntax (‘lc’) to create a 52 card list. Each card is created in Card.create.

I saw on the Elixir mailing list recently, though, that list comprehensions were being deprecated. There was a new syntax floating about for that trick. And so it came time to rewrite the deck creation function. Now, it is this:

  def create do 
    # 52 cards, unless otherwise specified?
    for rank <- ['Ace',2,3,4,5,6,7,8,9,10,'Jack','Queen','King'], 
        suit <- ['Hearts','Clubs','Diamonds','Spades'], 
    do: Card.create( rank, suit, Card.init_points(rank) )
    |> shuffle 
  end 

Minor difference, but an important one. It’s like doing nested for loops instead of a bit of magic syntax. The list comprehensions aren’t long for this world, so it’s useful to write them out now.

The cards, you may recall, are maps. Initially, they were records. But then Elixir deprecated those, as well. What, I wonder, is next for this poor little function?

Building an Elixir Mascot

I’ve accidentally found myself in the midst of designing a mascot for the Elixir programming language. For kicks. And sometimes to avoid the work of learning more advanced parts of the language that I tend to stumble over. Hey, at least I’m creatively procrastinating!

Recently, I did a series of images of Batman villains done up in the style of the Elixir logo:

I referred to these in a couple of tweets as the Elixir mascot playing dress-up. But that’s a little presumptive. There is no Elixir mascot. There is only the teardrop-shaped icon on the Elixir home page.

The teardrop guy with the big nose and no legs is my concoction, utilizing the shape of the logo as the body of the characters.

But does it go far enough to distinguish itself from its antecedents?

The more I drew the Elixir guy (still unnamed), the more I realized where his ancestors came from. The lineage would have to start with the Shmoo from Li’l Abner:

Kind of a white teardrop shape with a longer neck. He had legs, but no nose and no arm.

Alex Toth designed the Herculoids tv series for Hanna Barbera a few decades later, and gave the world Gleep and Gloop:

Like so much of Toth’s designs, they were stripped down to their barest essentials. They’re vaguely teardrop shaped, but they only have eyes. It’s amazing to watch the cartoon with those restrictions and see how animated they could make those characters.

Then there are the Terries and the Fermies, the folks who live underground in Carl Barks’ classic 1956 story, “Land Beneath Ground,” From “Uncle Scrooge” #13.

They had the same body shape, though a little flatter at the bottom to give them the appearance of a heavier weight grounding them to the surface. Their arms are also a bit more human, and less cartoony. They’re lumpier. They have ties around what would be their necks, and even some hair sticking out of the top of their more rounded-off heads. They also have the longest and pointiest noses of all, modeled no doubt on a duck beak.

We take a sidestep for the next one:

I like the cuddliness of Tux the Linux penguin. I’m not sure how much of an influence this one image is, but it’s classic and seared into everyone’s minds by now, right? Kinda round, with feet floating in front of him. His wings become arms, their tips like hands.

But where I start running into troubles is with Java. (Who here hasn’t said that at least once in their lives?) Java has a mascot named Duke, who looks like this:

He has a pointed head, a vague tear drop shape, two arms and a big nose. He does, however, have five fingers and a white body with a black head. He also has two stumps to approximate legs. They work well, being a small modification of the original shape that can add so many more motions and positions to convey an idea.

His arms are black, which an earlier version of the mocked-up Elixir mascot had.

The more I drew my idea for an Elixir mascot, the more he looked like Duke. More differentiation was needed than just the rounded lower half, one less finger per hand, and a bit more of a curve in the top half.

That’s where I am today.

Here’s my new design concept. It maintains the same shape, but shrinks the nose down, which I think brings about the most comparisons to Duke. It also adds feet, but no legs. To match that, I’m removing the arms, too, and just leaving the hands. If properly positioned, the hands will inform the reader as to where the arms are. I will continue to emphasize the eyebrows, and make one eye slightly larger than the other to give him a little extra character.

As you can see in the pencils, I even made a little point in the back of the body where the lower round shape meets the top triangle shape. It should be fairly subtle, but I’m emphasizing it to get the hang of it now. I’m working with the feet to show action and motion, so we’ll see how that goes.

There’s still one major problem. How do we draw a female version of the mascot? Taking any of the traditionally feminine forms and applying it to a tear drop shape doesn’t work. You can’t just add a chest to a tear drop. You might be able to paint them on, the way a Lego character done a feminine costume by drawing it on top of a flat square surface. I could make the mascot’s lips redder and bigger, and add eye lashes, but those seem almost patronizing. It’s too obvious and too easy. Worst of all, it doesn’t work. It looks like the mascot is in drag. Not good.

I also miss the costuming possibilities that arms give me. They help define where a shirt hangs from the body by where the shoulders are.

On the other hand, I doubt there’ll be an Elixir animated series or action figure line, so maybe we don’t need to worry about all these details. Just make something cute that looks good on top of a web page or something, you know?

And, just like in programming, Keep On Iterating…

Thinking Differently About Errors

This is called intentional programming. You write code for the intentional control flow path which you expect the code to take. And you don’t write any code for the paths which you think are not possible. Furthermore, you don’t write code for data flow which was not the intention of the program.

This article about intentional programming was mind expanding and eye-opening for me. Yes, it hurt. But in a good way. It talks about the way Erlang handles errors in a way that eliminates the need to be a defensive coder and anticipate all possible fault scenarios. Smart programming.