I'm Launching Street-Smart Coding: 30 Lessons to Help You Code Like a Pro (the Roadmap I Wish I Had Starting Out)

Street-Smart Coding cover
Street-Smart Coding: 30 Ways to Get Better at Coding Without Losing Your Mind

I spent five years in college learning to code.

A stupid dissertation delayed my graduation. But that’s another story.

Most of my five-year program didn’t prepare me for real-world coding. My real coding journey began at my first job, with one Google search: “how to get good at coding.”

I found a lot of conflicting advice:

  • “Use comments”
  • “Don’t use comments”
  • “Do this”
  • “Don’t do that”

Arrggg!

It took years of trial and error to learn what worked.

I had to survive on-call shifts, talk to stakeholders, and say “no” politely. More importantly, I had to learn that coding takes more than just syntax.

That’s why I wrote Street-Smart Coding— a roadmap of 30 lessons I wish I had when I started. For every dev who’s ever typed “how to get better at coding” into Google or ChatGPT. (Back in my days, I didn’t have ChatGPT… Wait, I sound like a nostalgic grandpa…)

Scrolling through the first pages of Street-Smart Coding
Preview of the first ~12 pages

Inside “Street-Smart Coding”

This isn’t a textbook. It’s a battle-tested guide for your journey from junior/mid-level to senior.

Some lessons are conventional.

Others were learned the hard way.

And a few are weird.

One lesson comes from a TV show. Nope, not Mr. Robot or Silicon Valley. That’s on Chapter #29. It will teach you about problem-solving.

You’ll learn how to:

  • Google like a pro
  • Debug without banging your head against a wall
  • Communicate clearly with non-tech folks

…and 27 more lessons I learned over ten years of mistakes.

Now they’re yours.

Get your copy of Street-Smart Coding here and skip the years of trial and error. For launch week only: Pay what you want—even $1 or $2.

TIL: How to Read Invalid Fields as Null with CsvHelper

In another episode of the Excel paradox of Coding

TL;DR: To read an invalid field from a CSV file as null with CsvHelper, create a map class and use Default() with useOnConversionFailure set to true on the appropriate field.

The cleanest approach

To honor the 20-minute rule and preserve my keystrokes, let’s say we need to read a CSV file with CsvHelper. By default, it throws an exception when it fails to parse a column, for example when it finds text on a numeric column.

Here’s how to read that invalid field as null instead of throwing an exception,

using CsvHelper;
using CsvHelper.Configuration;
using System.Globalization;
using System.Text;

namespace TestProject1;

[TestClass]
public class CsvHelperTests
{
    private class MovieRating
    {
        public string Name { get; set; }
        public float? Rating { get; set; }
    }

    private sealed class MovieRatingMap : ClassMap<MovieRating>
    {
        public MovieRatingMap()
        {
            Map(m => m.Name);
            Map(m => m.Rating)
                .Default(defaultValue: default(float?),
                         useOnConversionFailure: true);
            //           ^^^^^
            // If the field is invalid, use the default value
        }
    }

    [TestMethod]
    public void NullWhenInvalidFloats()
    {
        var csv = new StringBuilder()
            .AppendLine("Name,Rating")
            .AppendLine("Inception,9.0")
            .AppendLine("Titanic,ThisIsNotAValidRating")  /* <-- */
            .ToString();

        using var reader = new StringReader(csv);
        using var csvReader = new CsvReader(reader, CultureInfo.InvariantCulture);
        csvReader.Context.RegisterClassMap<MovieRatingMap>();
        //                ^^^^^

        var records = csvReader.GetRecords<MovieRating>().ToList();

        Assert.AreEqual(2, records.Count);

        var last = records.Last();
        Assert.AreEqual("Titanic", last.Name);
        Assert.IsNull(last.Rating);
        //            ^^^^^
        // Look, ma! It's null
    }
}

The magic happens in MovieRatingMap. The Rating map uses Default() with useOnConversionFailure set to true.

The manual approach

As an alternative, let’s read the CSV file manually while processing the records as needed,

[TestMethod]
public void ByHand()
{
	var csv = new StringBuilder()
		.AppendLine("Name,Rating")
		.AppendLine("Inception,9.0")
		.AppendLine("Titanic,ThisIsNotAValidRating")
		.ToString();

	using var reader = new StringReader(csv);
	using var csvReader = new CsvReader(reader, CultureInfo.InvariantCulture);
	csvReader.Context.RegisterClassMap<MovieRatingMap>();

	csvReader.Read();
	csvReader.ReadHeader();
	//        ^^^^^
	// Open the reader and read the header

	var records = new List<MovieRating>();
	while (csvReader.Read())
	//               ^^^^^
	// Read it by hand...
	{
		var name = csvReader.GetField<string>("Name");
		var rating = csvReader.GetField("Rating");
		//                     ^^^^^
		// Read the field as string...

		var parsedRating = !float.TryParse(rating, NumberStyles.Float, CultureInfo.InvariantCulture, out var parsed)
								? default(float?)
								: parsed;
		// Parse it as needed...

		records.Add(new MovieRating
		{
			Name = name,
			Rating = parsedRating
		});
	}

	Assert.AreEqual(2, records.Count);

	var last = records.Last();
	Assert.AreEqual("Titanic", last.Name);
	Assert.IsNull(last.Rating);
	//            ^^^^^
	// Look, ma! It's still null
}

A lot more work! We have full control, but it’s less clean.

In case you’re wondering, I asked Copilot about this but, with a straight face, it hallucinated suggesting a flag on CsvConfiguration, which didn’t even exist.

For scenarios like this, you still need strong debugging and code reading skills. I cover those skills and more in Street-Smart Coding—A roadmap with 30 lessons to help you code like a pro.

Jesus on prototyping, C# union types, and taste

Hey there.

Here are 4 links I thought were worth sharing this week:

#1. After a long wait, C# union types are here (10min). Well, in the next C# version. If you’re new to union types, I wrote this guide (9min) when Microsoft announced the feature.

#2. If you’re new to a codebase, run these Git commands (5min) before reading any code. Treat it like a crime scene: gather evidence before touching anything.

#3. When AI makes code and text free, the only skills left are taste and judgment (10min). I liked the exercise of “fails because.”

#4. Did you know that Jesus taught about prototyping with an LLM? Here’s his advice (3min).


And in case you missed it, not much about coding on my blog, but I wrote about the secret to surviving 30 years in one job (and to live a happy life) (3min).


(Bzzz…Radio voice) This email was brought to you by… Street-Smart Coding, 30 lessons to help you code like a pro. From Googling to clear communication, it shares the lessons to help you stand out in the age of AI.

See you next Friday with more links.

Keep coding smartly.

Cesar

The Real Effect of a Daily Writing Habit

My first writing class shocked me.

Its main lesson was to write every day. It was a webinar pitching a writing course. But it made me revive my blog after abandoning it for months.

Since November 1st, 2024, I’ve been writing daily. If I miss a day, I write two posts to recover the streak. More than once I’ve thought I’d run out of ideas.

Writing daily makes you pay attention to the world. You see the world through your writer’s glasses. This is my favorite side effect.

As Robert Greene says, “it’s all material.” A conversation could be a mini-story. A failed delivery, a business lesson. A visit to the grocery store, a life lesson.

Writing daily is a habit that has truly changed my life.

Write Not to Be Read (Yes, You Read That Right)

Almost nobody reads online.

We don’t deserve attention, especially when content is free and abundant.

Smart Brevity says we have a few milliseconds to earn attention:

Most people will only read your headline, subheaders, and bold sentences. Tell them what they need to know if that’s all they do.

Christopher Butler writes in Earning Attention,

“Here’s another 80/20 framing–80% of your audience will never do more than scan your information; 20% will go on to read it.”

Write as if nobody is reading, but everybody is skimming.

The Secret to Surviving 30 Years In One Job (And to Live a Happy Life)

In a line at the grocery store…

“Sorry, did I mishear, you said you’ve been here 35 years?” I asked her.

While waiting, I skimmed the books on the shelves and overheard the cashier talking to the client in front. When it was finally my turn, I couldn’t help but ask her.

“30! I have 30 years,” the cashier told me. “The girl at the bakery section has 35. She was about to leave last year. She’s leaving next May.” It was April.

Staying for so long at a place…

Curious and surprised, I asked her, “How did you manage to stay so long at a single place?” To me, 30 years at the same job sounds like a life sentence.

“Take it easy!” she said while smiling. “Don’t let anyone ruin your day!” She kept scanning items without pause. “How long have you been in your job?”

Earlier that day, a pointless task from a freelancing client made me want to throw my laptop against the wall. Her words came at the perfect time.

“I got bored or they got bored of me. The longest I’ve stayed at a place is 5 years.” That was at my last full-time job as a coder. I burned out while waiting for a promotion. Months later, the company laid off almost everyone, including me.

“You have to take it easy. There are clients that…“ she said while shaking her head.

When someone does it…

“There’s only one who ruined my days…“ The smile on her face disappeared.

“A boss?” I asked her while expecting to hear some gossip or horror stories from working at a grocery store.

“My first husband… That one sucked the life out of me. That’s why I left him.” Beep… Beep… She kept passing the products all that time. “I was skinny… When I left him, everybody said they could see the change.”

Years ago, 30 years in one place sounded like a career wasted. Now I know some people thrive in structure. Others in change. Others take a boring job to fuel their hobbies. Whatever your path, smile, take it easy, and never let anyone suck the life out of you. And if it’s your partner or your job doing it, leave them.