Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active January 19, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajan/07cda07e615afb2fa32a28232e9e4641 to your computer and use it in GitHub Desktop.
Save amirrajan/07cda07e615afb2fa32a28232e9e4641 to your computer and use it in GitHub Desktop.

History Repeated through Shuffled Cards

History is kind of repeating itself. This is the first time I've ever given the "you should really consider contracting cause you're better than this FTE BS" advice to someone that resembles my own "upheavel"/journey so closely.

Back in 2012, I had this very same conversation card shuffling conversation with my "mentor" near the time when I myself quit my job (more detail later as to why I put mentor in quotes). Greg Vaughn (my "mentor"), posed the same shuffle deck question to me.

And I freaking did a double take when you posted your response because that was basically the code I wrote to show him.

My Sparing Session with Greg

A bit of background about Greg:

He didn't know very much C# at all. So there was a horrible communication gap between us when it came to talking about programming concepts. He was (is) an incredibly strong Ruby dev. He showed me the Ruby version and from there it kind of went downhill. I thought to myself:

"He's an old ass fart (he was 35 I was 29) with a stupid ass script kiddy dynamic language. He doesn't even understand C#. How the fuck is he going to say that his version of shuffling a deck is better than my perfectly typed, extendable, easy to read C# solution?"

But his god damn Ruby implementation started to huant me:

suits = [:hearts, :diamonds, :clubs, :spades]

values = [:two, :three, :four,
          :five, :six, :seven,
          :eight, :nine, :ten,
          :jack, :queen, :king, :ace]

values.product(suits)
      .sort_by { rand }
      .each { |v, s| puts "#{v} of #{s}" }

This is the heated conversation I had with Greg:

None of this is statically typed! You have no idea if any of this is valid!

None of this is readable at all. It's dense and unmaintanable because of its dynamic nature.

You don't understand all the benefits of my C# version because your C# experience is definitely not anywhere close to mine. Especially since you don't have any experience with a statically typed language.

Greg:

Well I don't that much experience with C# you're definitely right. But I am proficient with statically typed languages. Like Haskell, OCaml, and Objective C. Read the first few chapters of 'Learn You a Haskell for Greater Good' and you'll see where I'm coming from.

Oh and Amir, do you know what a Haiku is?

Cool, I figured you did. The first time you heard that word, I'm sure you had to have it defined for you. But now, when anyone says Haiku, it doesn't cause the same confusion as the first time you heard it. The concept of product and map is similar to haiku. After you skim that book I recommended, you'll find that these concepts are no long foreign and you'll see an immense amount of clarity in the Ruby implementation.

So I entertained his request to read the book (mostly because I wanted to prove him wrong). But that's not what happened. And then I came back to him and said:

You're right Greg. I didn't know what I was talking about. Here is my new solution.

var random = new Random();
var combos = from value in new [] { "two", "three", "four",
                                    "five", "six", "seven",
                                    "eight", "nine", "ten",
                                    "jack", "queen", "king", "ace" }
from suit in new [] { "diamonds", "hearts", "clubs", "spades" }
select new { value, suit };

combos.OrderBy(_ => random.Next())
      .ToList()
      .ForEach(c => Console.WriteLine(String.Join(" ", c.value, c.suit)));

To which Greg replied:

Damn that's wordy for such a trival thing.

So I cleaned it up using extention methods and bending C# to my will (using C# 4.0):

var combos = from value
             in Oak.Array("two", "three", "four",
                          "five", "six", "seven",
                          "eight", "nine", "ten",
                          "jack", "queen", "king", "ace")
             from suit
             in Oak.Array("diamonds", "hearts", "clubs", "spades")
             select new { value, suit };

combos.OrderBy(_ => Random.Int())
      .Each(c => Oak.Print("{value} of {suit}", c));

To which he replied with:

Meh. Still kind of wordy. Also, what's Oak?

And bright eyed and bushy tailed I said:

Oh! It's an open source .Net project I decided to start based on what I learned so far. Keep an eye on it!

He wasn't too excited about it. He replied with:

It's kind of sad that the .Net framework/C# doesn't have these quality of life methods built in. Every other modern language I've used does. Even JavaScript.

So yea. There you have it.

RE "mentor" in quotes:

I never felt this exchange we've had over the past year is a mentorship, because you're a peer that just needs some "prespective".

There is a story called "Plato's Alegory of the Cave" that I've mentioned in the past. I'm just someone that's trying to remove the shackles of .Net/C# from your wrists... not sure if it's a mentorship... maybe more like a hostile intervention at times T_T. I feel moreso invested in your journey "away" from .Net since your story is already so close to mine. And I can only imagine what you'll be capable of a few months from now when you're "outside the cave".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment