Don’t forget about character casing when comparing strings!

There are many issues I’ve experienced during the many, many years I’ve worked as a software developer. But one of the most recurring issues is, without a doubt, the mismatching of words due to character casing.

There are solutions to the character casing mismatch problem. For example, you can make your strings all lower case or upper case before comparing them. There are also many programming languages that have features to help with string comparisons.

The issue is no longer the lack of solutions to avoid this problem. The problem is that these solutions require that you, the developer, be proactive by being alert and aware of case sensitivity when making string comparisons. For example, in C#, you have the StringComparer class, which includes properties like StringComparer.OrdinalIgnoreCase to help you ignore the character’s casing when comparing strings.

As a developer, you have to be alert and know when to ignore character casing. While there are many simple ways and tools built into programming languages, sometimes knowing when to do this might not be obvious.

For example, if you call GroupBy in C# and select the value you want your list to be grouped by, it will consider values such as “Abc” and “ABC” as unique, which might not be what you want to do.

In most cases, if you group a list of items by a specific string value, your intention is probably to treat the same values “Abc” and “ABC” as the same. Therefore, you’ll want to ignore the casing as the values are the same in this context.

Issues like the one with GroupBy in C# can go unnoticed until it causes problems. For example, I ran into this issue and didn’t realize the mistake until I tried to add the values of that grouped list to a dictionary and failed. The dictionary attempted to use the values “Abc” and “ABC” as the dictionary key, but it failed since these aren’t unique.

So what can you do about this? Code defensively. Every time you compare strings, consider character casing sensitivity and avoid it easily by converting all your strings to upper case or lower case before comparing. Second, be aware of the use cases where you are calling a built-in function such as GroupBy or ToDictionary as functions like this might be case-sensitive within your programming language.

With the programming language C#, you can use overloads that explicitly specify the string comparison rules for string comparisons. It works in this language by calling a method overload that has a parameter of type StringComparison.

In the example below, I’ll be using StringComparison.OrdinalIgnoreCase for comparisons for culture-agnostic string matching. The example shows you how not ignoring case sensitivity might give you unexpected results.

Examples in C#

Let’s declare a list of books with author names written using different casing

var books = new List<Book>()
{
new Book { Name = "Programa en donde sea", Author = "Ricardo" },
new Book { Name = "Empieza a programar", Author = "ricardo" },
new Book { Name = "Xyz", Author = "Joe" },
new Book { Name = "Despues de la programacion", Author = "RICARDO" },
new Book { Name = "Blah", Author = "Foo" }
};

Let’s group the list of books by Author, but since we are not doing anything to ignore case sensitivity, the result is not what’s expected – It returns five records instead of three as it treats all variations of the name Ricardo as unique values.

var notAUniqueListOfBooks = books.GroupBy(b => b.Author);

Now let’s group the same list of books by author, but this time let’s add a parameter to make the string comparison case insensitive. The result is only three records, that’s because it treats all the variations of the Author name Ricardo as the same value.

var aUniqueListOfBooks = books.GroupBy(b => b.Author, StringComparer.OrdinalIgnoreCase);

Let’s now create a dictionary from the list of books. This dictionary will use the Author value as the key, and both the book’s name and author as the value. The result is five items in the dictionary, again, because it treats the each instance of the author name Ricardo as a unique value due to the difference in casing.

var notAUniqueBookDictionary = books.ToDictionary(b => b.Author, b => b);

Finally, we’ll try to create a dictionary following the same attributes above, but this time, we’ll pass the parameter StringComparer.OrdinalIgnoreCase to make sure the comparison is case insensitive.

The result if this last one is an error with the following message:

“An item with the same key has already been added. Key: ricardo”

This is because since we are ignoring the casing in Author, we cannot create a dictionary as the key values are required to be unique and by ignoring the case of the different variations of the value Ricardo, these are no longer unique. They all end up being the same exact value.

var aUniqueBookDictionary = books.ToDictionary(b => b.Author, b => b, StringComparer.OrdinalIgnoreCase);

Finally, using the examples above, if you wanted to group by Author, and then create a list of all of their books including the name and author values then you could try using ToLookup, and pass the StringComparer parameter to make sure the string comparison in case insensitive.

var aUniqueLookup = books.ToLookup(b => b.Author, b => b, StringComparer.OrdinalIgnoreCase);

The above will give you a dictionary where the key is the Author name and the value is a list of books including name and author. Also, by passing the StringComparer.OrdinalIgnoreCase parameter, we are making sure that the result is a unique list of values.

This the result of our book list when converted into a Lookup object in C#. There are three keys, all unique, and under each key we have a list of books that corresponds to the book’s author representing the Key value.

I hope this is useful, the code I used to test the examples above is all available here if you want to play with it and explore changing the values, parameters, etc. Cheers and happy coding!

Focus and avoid context switching

My day job as a software engineer requires a great deal of focus and organization. Writing code is one of the last steps you do in software development. Writing code only comes after gathering enough information and understanding what changes or features we need in an application.

Focusing on one task, but more importantly, one project at a time is critical. When working on more than one project at a time, there is a lot of context switching, which is terrible for you and your productivity.

Focusing on one task also allows you to fully immerse into the details of the project, expand your domain knowledge about the work area, and as a result, be thoughtful about the way you approach the project, its problems, and the solutions.

Context switching while doing any work that requires concentration decreases the project’s opportunity to succeed and your productivity as well. The result is a net negative, and I don’t see any reason to do it. The only reason we do it might be due to our inability to focus on one task or the constant interruptions that are common in the workplace.

Focusing today is more challenging than ever. We have many tools around us that trick us and push us to pursue distractions. The handheld devices we all have are the number one reason for this, in my opinion. These devices are the window into a lot of addictive content out there, and trying to stay focus while having these devices next to us requires a lot of discipline.

It’s not all our fault. We are the victims of advanced algorithms that know us well and learn how to get our attention. It takes a lot to turn off notifications and not open our favorite apps to see the latest micro-piece of content. But, it’s a very effective drug that works against us.

Of course, there are simple ways to minimize this. I, for example, have most of my notifications off. The only place where I turn notifications on is on my family chat. Other than that, I never get pulled in by an app since I don’t get notified about anything. So that works, but just a little.

There are other things I do to keep myself focused and stick to one task at a time. For example, I set up specific times (timeboxing) to do the other distracting tasks such as checking email, social media, the news, etc. I timebox these tasks and try hard not to allow myself to break that rule.

Timeboxing helps a lot. In the past, I spent a lot of time checking, reading, and replying to emails. Nowadays, I check email maybe once a day, and I do not respond to emails unless strictly necessary. I do the same for social media apps, and if you use an iPhone, the Screen Time feature can help you a lot with this.

For non-digital distractions, you can also use the concept of timeboxing. For example, at work, I set up “focus time” in my calendar to make sure people know when I will be available to join a meeting and when I am not. Setting focus time in your calendar sets the expectations of other people around you. It will make it easier for them to know when you might be free to talk, have a meeting, or help with some other task.

I break my workday into four areas, the first block of time, 7-9 am is OK for meetings and open tasks, from 9-12, my time is blocked for deep/focused work, lunch from 12-1 pm, and finally from 1-4 pm I have open it up for meetings and time to reply to email and other office messaging apps.

I started doing this more than a year ago, and it works very well. I get very few if any distractions during my “focus time,” which is enough to make me productive and more relaxed. Before doing that, I checked email constantly, responded as soon as possible to any message, and accepted all meetings at any time. Unfortunately, that caused my productivity to drop considerably and, with it, my motivation and energy.

Context switching is tough for tasks that require concentration. You cannot concentrate with the endless amount of notifications coming from our devices, from people around us, and from our lacking ability to concentrate. We have to set clear boundaries with ourselves and be assertive and disciplined to make sure we and others around us respect them.

Setting limits and structures around my life is not something I often do. I prefer to live the moment, be casual with what I do in life, and allow myself to do unexpected things. However, when it comes to working, whether it is personal or professional, setting boundaries and allowing yourself to focus on tasks is a game-changer.

This advice is not only about being more productive. Focusing on tasks is also less stressful and much more enjoyable once you learn how to do it. I hope this is helpful for you, and please, if you have any other suggestions, questions, or any feedback, please let me know here in the comments. Cheers.

Sobre criptomonedas, la blockchain, y su uso actual.

La idea detrás de BitClout es interesante, otros usos de criptomonedas y la blockchain vienen pronto, estos tendrán más sentido para personas en general. Lo que sí no me gusta es la idea inicial de BitClout, en donde compras y vendes criptomonedas basadas en la especulación solo en la reputación personal de los usuarios.

Por lo pronto, Bitcoin sigue siendo la criptomoneda más popular y más aceptada por organizaciones e inversionistas/especuladores – solo espero que la minería Bitcoin y Ethereum se vuelvan más eficientes y no desperdicien tanta electricidad.

Y del token nofungible (NFT) ni hablar. Entiendo que el arte en general tiene cierto valor intrínseco, pero los objetos digitales que se están vendiendo como arte NFT no es la meta de la blockchain o de las criptomonedas, de eso estoy seguro. Es un buen ejemplo de como podemos asociar objetos con un registro único y descentralizado, vamos, una nueva y mejor manera de mantener un libro mayor universal en la nube.

Tiempos interesantes.

What is fear?

Today I experienced something that I haven’t experienced in a while, fear. My wife made a reservation at a local boathouse to go paddleboarding and kayak this morning. I am the one who chooses the paddleboard due to an excellent experience I had in Honolulu a few years ago.

All week, I have been waiting for this, I was excited, and I was ready to get on that paddleboard and own it. My previous experience with it was in a very manicured and very calm laguna next to the ocean in Waikiki. Since the water was tranquil and not too deep, I felt comfortable on the paddleboard from the very moment I got on it. That was my experience, my only one.

This morning we wake up, eat breakfast, drink some coffee and water, and head to the boathouse to get our equipment and onto the water. This boathouse is located in a bay in Bellevue, WA. Its name is Meydenbauer Bay Park, and it’s the home of a beautiful beach, boat docks, a beautiful picnic area, and of course, the boathouse.

After signing up the usual release forms where you promise not to sue anyone if you die there, we walked directly to the beach to get on the paddleboard and kayaks. The first question I got from the staff at the beach is, “have you ever been on a paddleboard?” and of course, my answer is an energetic, yes! and then he recommends to stay on my knees until I can pass a bridge, and then after that, I can stand up and go on my way.

Just a minute or two later, I pass that bridge, but since I feel comfortable on my knees, I decided to stay like that until I get out of the beach area. I don’t want to scare away swimmers with my paddle-boarding skills now, do I?… or perhaps this is when I start to feel nervous, it’s evident to me now that this isn’t going to be like my Hawaii experience.

We are in a bay, not a lagoon. Boats are coming in and out, passing by, swimmers, kayakers, other paddle-boarders, ducks and their ducklings, and even one or two seaplanes nearby. This is different, it’s alive, and everything moves. I decide to stay on my knees on the paddleboard a little longer. My two sons are nearby in the kayak; they are having a good time. My wife is a bit far from me on a “pedal” board, it’s like a paddleboard, but with pedals and handlebars, she looks nervous, but she’s also enjoying it.

After over 30 minutes of using the paddleboard while on my knees, I end up near the moorage surrounded by boats of all sizes; the water is quiet, a lot calmer than around the beach where I started. But, my mind wonders, telling me to stop being a baby and get up and paddle. After all, this is a “stand up” paddleboard; the idea is to use it while standing.

Several minutes go by, and then I try to “park” the paddleboard near a dock. My idea is to hold on to the dock while I try to stand up and then just take it from there. As soon as I try that, the paddleboard moves from under me, and I almost fell. Fear increases, and I am ready to give up. My mind wanders a bit more, and then I imagine trying to get up near the dock but falling and hitting my head in it, then drowning and dying in a very freakish way.

The water is calm around the docks, all the boats here are mooring, it feels like the appropriate place for me to try to stand up on the board. So I move away from the dock. I don’t want to hit myself with it if I fell. I then realize that my wallet and phone are in my pocket. If I fell on the water, I think I’ll be fine since I am wearing a life jacket, but my phone and wallet will probably go to the bottom, and I’ll lose both forever.

I start to convince myself that this is a bad idea. And at the same time, I want to get up and try it, then show my wife and kids how awesome I am. I take my sandals off, thinking that it is more natural to be standing without them as if I will have a better grasp with my toes and get a better balance. I move my left knee up, placing my left foot on the board as if I am proposing to someone, I do the same with the other leg, and just like that, I am up!

After getting up, I feel happy for a second, but both of my legs start to shake vigorously, and while the water is calm, my legs are moving the board with all the shaking. I know it is fear and not a lack of balance. My first thought is to go back on my knees and just continue enjoying my paddleboard adventure that way. But I don’t do that. Instead, I try to use the paddle to see if moving the board forward will help. It does a bit. Then I concentrate on my breathing, trying to calm myself down, and it works.

Standing on a paddleboard
Standing on the paddleboard

After what felt like an eternity, probably 2-3 minutes with both of my legs shaking, it suddenly stops, the shaking is gone, and my body feels more attached to the board. I feel stable standing up on this paddleboard. I start paddling towards the beach area again, I see a boat coming my way, about 30 feet from me, and I know that soon, I’ll be feeling the ripples and wakes behind that boat. The first thought is to go back on my knees, but I don’t do that. Instead, I get closer to a moored large boat to my right, thinking that if I stay away enough from the passing boat ripples, I’ll be OK.

The boat passes, and the ripples and wakes get closer and closer. Finally, I am next to a still and huge boat, thinking that the water will be calm there. Once the ripples and wakes start to reach me, they are weak, and I manage to stay up and dry. And then a few seconds later, I feel a vigorous shake, it’s coming from my right side… it’s the ripple and wakes bouncing off the bigger boat, causing new and stronger waves and wakes right next to me. I try to move away faster, I manage to stay up, and all is fine.

A few minutes later, I am near the beach. My sons and my wife take pictures from the water, I get closer to show them how I am standing up, and while they don’t seem to be amused, I feel proud of myself. I know that this simple water outing today was tremendously helpful for me. The experience of fear and then overcoming that fear will have substantial positive ripples and wakes in my future.

So what is fear? I think it’s what happens to you right before you experience something new. It’s a profound learning experience, and hopefully, a positive one.

Have a great weekend and a safe 4th of July. Cheers!

Use your natural competitive advantage

We all know the story of the turtle and the rabbit. We know that the rabbit had a significant competitive advantage over the turtle. However, the moral of that story is not about competitive advantages; instead, it is about never underestimating a weaker opponent.

This post is about competitive advantage, and just like the rabbit, I’d like to think that we all have something in us that we can use to our advantage, that is, if we are self-aware and do not fall asleep on our laurels, the rabbit did.

Do you think you have a competitive advantage? Of course, you do; everyone does. The hard part is knowing what that is and then finding specific ways to use that advantage to help us progress in our lives.
A natural competitive advantage is, in my opinion, something that we can often do better than others, something that we naturally are attracted to it. Therefore, we are good at it.

During my professional experience, I realized that while I was not the best programmer, I was always good at communicating with people who weren’t technical, clients, partners, coworkers, etc. Having the ability to communicate equally with technical and non-technical people helped me find the answers I needed to do my job better. It also placed me in a good place as a bridge between non-technical people and other programmers like myself.

I am also very patient, and this has helped me over the years by allowing me to work on frustrating projects with frustrating people and do it without becoming cynical or upset. Patience is a significant advantage, especially since you have to be not only patient but receptive and often generous with your time. That is one of my natural competitive advantages.

Maybe you are a good teacher, a good writer, or are great at drawing; use it to your advantage. Find creative ways to do it, apply that hobby or skill to your professional tasks. You’ll be surprised how much of your abilities and even hobbies you can use for professional purposes.

Use your strengths as your natural competitive advantage. You do have them, and it’s just a matter of realizing it and putting them to work. Use your natural competitive advantage.