Quote of the Week

"Refactored code either dies a hero or lives long enough to see itself become the legacy". - Mathieu Ferment

Removing the IF in the code

Yesterday I came upon this interesting read on the Anti-If pattern. It has some good tips on how to remove if-statements from your code. As I primarily work with ColdFusion, I thought it would be good to document a trick I learned to eliminate if-statements.

[More]

Nachos, not just chips and cheese

Recently my mother- and brother-in-law came for a visit. Usually during these visits I break out 3-4 dishes and a big breakfast or two. For some reason, that didn't happen this trip. We ate out several times and slept in most mornings. But one evening my wife decided we needed to have nachos for supper. She is convinced her brother thought we were serving chips with cheese sauce. Oh how wrong he was. See, we have nachos at least twice a month in our house. We know how to make a meal out of them. He must have enjoyed them beyond the clean plate as my mother-in-law asked for the recipe!

[More]

ColdFusion Tips: Identify common items in 2 lists

It's been forever since I've written anything here. I know, I'm such a slacker and I have no excuse. But after discovering the ColdFusion solution I'm about to share, I knew I had to write about it.

Yesterday as quick test I attempted to create a solution for the following: Given 2 lists of names, create a 3rd, sorted list that contains ONLY those names that appear in both lists.

Pretty straightfoward, right? Before I show my first attempt I think it is important to understand that I always strive to answer "yes" to 3 questions when creating a solution:

  1. Does the solution accomplish the goal?
  2. Is the code easy to read/understand?
  3. Is the code performant?

My straightforward solution became:

view plain print about
1friends = "Chris,Ashley,Joe,Mike,Ritch,Jennifer";
2family = "Ashley,Jennifer,Nancy,Mae";
3framily = "";
4for( name in friends ){
5    if( findNoCase( name, family ) ){
6        framily = listAppend( framily, name );
7    }
8}
9framily = listSort( framily, "textnocase" );

In essence, loop through all the names in list "one". If the name also appears in list "two", add it to "common". If one of the lists was shorter (as "two" is)

I think my solution checks all those boxes. But looking at it I just knew there was a better approach. I played around with map but it didn't feel better, just more difficult to read. Then I unearthed array.retainAll(). As a ColdFusion developer I had never heard of it. It's not a method included in the documentation at CFDocs Array Functions.

Dear reader, retainAll() is a JAVA method, called in the format array1.retainAll(array2), that retains only common array elements of array1 and array2. Exactly what I wanted to do!

I changed my code to:

view plain print about
1friends = "Chris,Ashley,Joe,Mike,Ritch,Jennifer";
2family = "Ashley,Jennifer,Nancy,Mae";
3framily = listToArray( friends );
4framily.retainAll( listToArray( family ) );
5framily = listSort( arrayToList( framily ), "textnocase" );

This code accomplishes the goal and is mostly easy to understand. 2 of my 3 requirements for an acceptable solution.The use of retainAll() may not be clear for any CF developer with no java experience (like myself). But this can be mitigated by adding a comment, so I don't consider it a bad thing.

But how about the third question? How does it perform? Better than the original!

The average run-time over 10,000,000 iterations: Loop-based solution: 0.006364ms RetainAll-based solution: 0.0044926ms

It would be premature optimization to choose the retainAll-based solution based solely on the runt-time numbers, though. At that speed, the difference is really negligible. For me, the retainAll-based solution is the better choice because the code is more concise and easier to debug/maintain.

Slacker!

I feel like such a slacker! Here I have this perfectly good blog and I never use it. I need to find a way to change this. Maybe it's time for this space to undergo major reconstructive surgery and become something new.

Easy 20 Minute Chicken and Dumplings

Tonight was chicken and dumplings for supper. I mentioned this to a friend who had a simple reply: "I want the recipe". I thought surly I had blogged it already but apparently not. So here I give you my EASY 20 min chicken and dumpling recipe.

[More]

Interesting take on programmers

I was reading this article earlier and found this quote interesting: "You are a wizard harry. Programming is basically magic. Think about it - we study hard and pore over our books of lore (the computer + internet), to make spells (programs). Wizards can teach other wizards how to cast their magic. We can make things happen in the world spontaneously, and create wonderous devices anyone can use. (Like the internet and mobile phones). These devices can do things that would be impossible without our skills."

Yeah! Programming is just like that!

The surreal world

The one piece of custom code I added to the blogCFC engine that I wanted back was the ability to customize the keywords on an individual entry. I wrote that code 3 years ago and certainly don't recall what I did. However, it was easy to add back in.

I wrote a blog post about it! It was quite surreal to read my own blog post on how to update blogCFC to do what I wanted. But, it took 5 mins and boom, it was back in place!

I'm back...

So, while playing around with some settings I inadvertently hosed my blog installation. Well, it's back and I think all the posts were recovered. I know I'm missing some code updates I made, but that's ok.

I've had a problem with posting entries. It just doesn't occur to me to post things. Hopefully, this will not be the last post of the year.

Taco Soup Recipe

As the temperature begins to drop one of our go-to dishes for a quick, tasty meal has become taco soup. It's one of those 1 pot meals that really warms you up and only take about 45 minutes from start to finish. This recipe feeds 10, but we typically scale it back a little.

  • 2lbs ground sirloin, browned and drained
  • 1 medium onion, diced
  • 1 can green chilies
  • 1 can whole kernel corn
  • 1 package Ranch dressing mix
  • 1 package Taco seasoning
  • 3 cans diced tomatoes (I like at least 1 can of fire-roasted tomatoes)
  • 1 can pinto beans
  • 1 can hot chili beans
  • salt and pepper to taste
  • 1 1/2 cups of water

Mix all the ingredients together and simmer for about 30 minutes or until you can no longer resist the aroma emanating from the kitchen.

It doesn't get much simpler than that!

Even though this recipe includes green chilies and chili beans, it's pretty mild. So, here's some suggestions to take care of that:

  • Use "hot" taco seasoning (really, this should be a given)
  • just like when making chili, adding a diced chili pepper or 3 is never a bad thing
  • add some red pepper flakes
  • a dash of Sriracha sauce (ok maybe 2 dashes)
  • a couple tablespoons of hot salsa

I like my bowl with a plate of tortilla chips and a cold beer.

Previous Entries / More Entries