Categories
Humor Programming

The real reason programmers prefer dark themes

Comic by monstika. Click to see the source.
Categories
Humor Programming

What coding in Light Mode says about you

This made me chuckle.

Categories
Meetups Programming Tampa Bay

Building a “Wordle” function, part 1

These slides capture what we worked on Tuesday night’s “Think Like a Coder” meetup: coming up with a first attempt at a “Wordle” function. Given a guess word and a goal word, it should output a Wordle-style score.

We came up with a solution that I like to call the “close enough” algorithm. It goes through the guess word one character at a time, comparing the current guess word character with the goal word character in the same position.

When making those character-by-character comparisons, the function follows the rules:

Here’s the “close enough” algorithm, implemented in Python…

def wordle(guess_word, goal_word):
    
    # Go through the guess word one character at a time, getting...
    # 
    # 1. index: The position of the character
    # 2. character: The character at that position
    for index, character in enumerate(guess_word):
        
        # Compare the current character in the guess word
        # to the goal word character at the same position
        if character == goal_word[index]:
            # Current character in the guess word
            # matches its counterpart in the goal word
            print("green")
        elif character in goal_word:
            # Current character in the guess word
            # DOESN’T match its counterpart in the goal word,
            # but DOES appear in the goal word
            print("yellow")
        else:
            # Current character DOESN’T appear in the goal word
            print("gray")

…and here’s the JavaScript implementation:

function wordle(guessWord, goalWord) {
    
    // Go through the guess word one character at a time
    for (let index in guessWord) {
        // Compare the current character in the guess word
        // to the goal word character at the same position
        if (guessWord[index] == goalWord[index]) {
            // Current character in the guess word
            // matches its counterpart in the goal word
            console.log('green')
        } else if (goalWord.includes(guessWord[index])) {
            // Current character in the guess word
            // DOESN’T match its counterpart in the goal word,
            // but DOES appear in the goal word
            console.log('yellow')
        } else {
            // Current character DOESN’T appear in the goal word
            console.log('gray')
        }
    }
}        

I call the solution “close enough” because yellow is a special case in Wordle. If the guess word is ATOLL and the goal word is ALOFT, the first L in ATOLL should be yellow and the second should be gray because there’s only one L in ALOFT.

We didn’t settle on the “close enough” algorithm — it was just enough for that night’s session. In the next session, we’ll refine the algorithm so that it matches Wordle’s!

Want to become a better programmer? Join us at the next Think Like a Coder meetup!

Categories
Meetups Programming

Slides from the upcoming “Let’s figure out how to code Wordle” meetup

Here are the first 15 slides from the upcoming Think Like a Coder! meetup, which happens ONLINE on Tuesday, Feb. 8 at 7 p.m. EST! The first slide summarizes what we’re going to be doing in JavaScript and Python.

The mission of Think Like a Coder! is to turn Tampa Bay into a place packed with skilled, successful coders.

And no, you don’t have live in Tampa Bay or anywhere nearby to participate in this meetup — I just happen to live in the Tampa Bay area.

One of the biggest challenges in coding is making the leap from knowing the theory — if statements, for and while loops, functions, classes, and so on — and the actual practice of using those things to make working applications.

Many jobs involve following the same procedure every day. The steps are laid out for you, and are often documented in a 3-ring binder (Neal Stephenson talks about 3-ring binders in his cyberpunk novel, Snow Crash). You don’t have to think about them. You succeed when you follow procedure, and you excel when you can follow procedure quickly.

Coding falls into that category of jobs where there isn’t a clearly documented procedure for every little thing. You have to figure out how to accomplish the goal.

This photo in the slide above from the film Apollo 13, where engineers had to figure out how to improvise a way to remove excess carbon dioxide from the ship’s air, using only the stuff that the astronauts had on hand. You can read more about it in the article The Greatest Space Hack Ever.

Yes, you need to know your programming language keywords. Sometimes, it even helps to know what’s happening at the processor level.

See that diagram on the left of the slide above? That’s what your computer is actually doing, under the hood. If you like, I can talk about it at an upcoming meetup.

You need to know how to apply those fundamentals, and that comes with practice.

You also need to learn how to see patterns and similarities, which will help you come up with solutions. For instance, did you know that Mortal Kombat is essentially a fancier version of Rock-Paper-Scissors?

With all that preamble out of the way, it’s time to tell you what we’re doing Tuesday evening at the meetup.

In case you haven’t yet played “Wordle”, here it is, summarized on a single slide, including a screenshot of the game I played on Saturday.

Sure, it’s a hot topic right now because everyone’s posting their Wordle scores on social media and because its developer just sold it to the New York Times in a “low seven-figures” deal, but it’s also good coding practice.

The meetup will run from 7:00 p.m. EST (UTC-5) to 9:00 p.m., so we’re NOT going to build a complete Wordle game. There just won’t be time, once you factor in introductions, setup, and Murphy’s Law.

What we WILL build — or more accurately, we’ll ***figure out how to build it*** — is the “referee”, or the thing that takes the player’s guess, compares it to the actual word, and provides the feedback.

That thing will be a function that takes two inputs — a guess word and a goal word — and outputs a value that represents those colored blocks. It’s a little trickier than you might think, and you’ll find out why…

Join us this Tuesday, February 8th at 7:00 p.m. EST (UTC-5) for Think Like a Coder! and let’s figure out how to code Wordle!

Categories
Meetups Programming

Okay, NOW do you want to figure out how to code “Wordle”?

In case you hadn’t heard yet, Wordle, that game that’s cause everyone to post their score tables all over social media…

…has been bought by the New York Times. For “an undisclosed price in the low-seven figures.”

Now I can’t promise that my upcoming Meetup will carve a direct path to your becoming a millionaire, but what it will do is help you sharpen those programming skills that could help you build career and financial security.

You may have memorized the bits and pieces of programming from your university, high school, boot camp, online class, or book. But there’s a difference between that knowledge and applying it to turn those bits and pieces into actual working programs.

That’s what my Meetup, Think Like a Coder!, is all about. In our next session — happening online on Tuesday, February 8 at 7:00 p.m. Eastern — we’re going to figure out how to write the underlying game engine behind Wordle, including:

  • What goes into building Wordle?
  • How do you break down a problem like programming Wordle into smaller easier-to-handle problems?
  • How do you tell the player which letters are “right letter, right place,” “right letter, wrong place,” and “completely wrong letter”?

Here’s the fun part: I haven’t completely written a working Wordle program yet. That’s because we’re going to figure it out as a group, just like you’d have to figure out how to turn an idea for an application into that application, which is something you’ll have to do in a developer job.

If you’re looking to get into coding or sharpen your coding skills, you’ll want to catch this session. It’ll be beginner friendly, but there will be some challenges if you’re more experienced (basic scoring is simple, but Wordle scoring has some interesting challenges). Join us at “Think Like a Coder” and learn how to think like a coder!

Categories
Humor Programming

Is your JavaScript code giving away your age?

Those are literally from the previous millennium!

I don’t use var to declare variables in JS, but there are still situations when a good ol’ fashioned C-style for loop is the appropriate construct.

Categories
Humor Programming

What scares many programmers?

For me, regular expressions are like the rules for boardgames that I don’t play that often: As the game progresses, I understand the rules and think I have a firm grasp on them, and when the game gets put away and I don’t play it for a while, I forget almost everything.

These days, I keep a couple of “interactive notebooks” with working code featuring useful regexes, paired with notes written in Markdown:

  • For Swift, Xcode Playgrounds does this well.
  • For other languages — Python, JavaScript, Kotlin, and C# — I used Jupyter Notebook.