2005 Best Kiss

0 views
Skip to first unread message

Giovanni Sealy

unread,
Aug 3, 2024, 3:38:33 PM8/3/24
to nakibandio

No matter what your style of coding is, it should follow one rule: Keep It Simple, Stupid!
So what should I tell you about KISS? It really just means you have to keep it simple. Simple code is less prone to bugs, and is easier to read and understand for you and the people who'll be working on the code in the future (including yourself). And now you're probably thinking you're already doing that. Duh, why would you write complex code? Maybe you even think of yourself as not being a good enough programmer to write complex code! Let me tell you why this is probably not the case.

Keeping things simple is, ironically, not simple! It requires abstract thinking. It requires knowledge of the domain you're working on. It requires knowledge of the code, the framework, and the language you're working with. It requires experience. In fact, let me present you this quote by Martin Fowler:

Many programmers just get stuck in a certain train of thought, which isn't necessarily the right train of thought. In general, each programming task can be performed in countless ways. To fetch data from a database, you may write a stored procedure and call it using ADO.NET or Entity Framework (assuming you use .NET); or you may write the query in your code base using ADO.NET; or perhaps you're going to write a LINQ query with Entity Framework (or LINQ to SQL, or maybe you're still stuck with Typed Datasets).

Now, if we were going to count the ways in which you can write your SQL or LINQ query, you'd soon come to the conclusion that literally hundreds of ways exist to do something as simple as get data from a database. And that is usually just a small step of a bigger process, so count the different ways you can complete that process, multiply it by the different ways you can get data from a database, and the ways you can write this process probably gets close to an infinite number. Unless you're in Tenacious D, who just so happened to play the best song in the world, you're not going to write the best code in the world.

Still, when I inherit a project, I like to take a look at the line count in files I need to work with. If the line count is thousands of lines of code, then the file, and likely the entire project, probably isn't KISS.

Before you go and write me hate mail on why number of statements is a bad measure, let me explain why I think it's actually pretty valid. First of all, if people read our code, there's simply going to be less to read. Less to read means less for them to understand. Less is more, right? Second, less statements means less debugging! If there's a bug in your code, you'd rather check ten statements than a hundred statements.

Let's look at a real world (C#) example. Suppose we have a function that takes a string as input and returns a bool indicating whether the input is numeric (more precisely, an Int32). Here's what I think we can do. We can loop through the characters and use Char.IsDigit to check if every character is a digit. If we find one that isn't, we return false; otherwise, we return true. We can also use a Regular Expression to match the input with all numeric values. Last, we can use Int32.TryParse, which would actually give us the converted input as well, but we can discard it.

That already exposes a problem with the RegEx solution. RegEx is just difficult. It's great to solve some problems, but it already brings an initial complexity to the table that most programmers aren't familiar with.

In this case, we need to make sure the entire input is matched, and not just a part of the input. The programmer who used the loop with RegEx probably wasn't aware that the start and end of an input can be indicated in RegEx with ^ and $, so the [0-9] pattern would only work for single characters. Therefore, the RegEx solution is not KISS (even though it has the least statements).

Coincidentally, all these principles happen to be KISS. It's not easy to put them into practice, especially SOLID; but once you know them you can write better, maintainable, and above all simpler software. They might be open doors for you, but unfortunately there are some sloppy programmers out there who don't follow any of those rules. Don't be that programmer.

In this application, you pick a salesman and the application shows the customers of this salesman, how many orders he's made, how much money he has earned you, maybe how much provision he's getting, and other similar data. What would be KISS?

By just thinking about this a bit, we've eliminated repeating code before actually writing it in the first place. That certainly gets the overall number of statements way down. Additionally, the GetSalesManStatisticX methods are now simpler since they only do one thing (get the statistic).

So we should combine some of those functions for two reasons. First, and actually most important: getting data from the database can take a while. Doing this multiple times can be a huge performance hit! So always try to get a piece of data just once.

Second, if our functions are getting the same data, we are probably repeating our code. So we now have a few options. I won't say one is better than the other, but here they are. How about having a function that gets the data and passes it as input to the functions?

Depending on the complexity of the calculations, I would probably go with the first or third method (although there are some pros and cons to putting these calculations in your database as well). The takeaway here is that all proposed solutions solve the problem of doing multiple round trips and fetching the same data.

This is actually a real-life example. A project I worked on used the first method I illustrated, just separate method calls that all get their own statistic. Things didn't end well when the data became bigger and more statistics were added. Lots of repeating code and redundant database calls. It's not hard to see why this method was chosen, however, as it seemed pretty KISS at first.

That also shows that being KISS is not easy. There is not one way to do things, and it takes knowledge and experience to pick a good method out of the infinite options for writing your code. I've found that a little common sense goes a long way.

First of all, just read up on best practices! Here's a book I can recommend: Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin. If my recommendation isn't enough, John recommends it too in his book, Soft Skills! So be sure to read it. Also by Robert C. Martin is this series on SOLID principles, which you should really read and put into practice.

Second, be sure you Google for solutions before inventing them yourself. Googling effectively is a skill in itself. Sometimes I don't call myself a programmer, but a professional Googler! In these times, being a good Googler can really separate you from the flock. You can't know everything, but you can Google everything.

These have become a staple in our family, a favorite treat we deliver to teachers, friends, and neighbors, something my kids request for class treats. This is one of those recipes that has kind of become part of our family story, which makes me love them even more.

These look so yummy! Can't wait to try them. I love the cute holiday box you have them in. Would you mind sharing where you got them? Would love to have some like that to send around to neighbors this holiday season.

Um Kate, just FYI, you so don't have to wait for the kisses to solidify up again. I eat these but the PB chocolate kiss ones and they are the BEST while still a little soft. Like, I eat half the batch within the first half hour as they are coming out of the oven.
I can't wait to try these. I hope the kisses have made it to our little town grocer.

These are right up my ally. I have a question for you Kate and Sara- when you make your yummy sweet treats what do you do with the extras? I love to bake but always wish it just made enough for my fam to each just have one. I am a bit lacking in self control ?

Can I just say YUMM-O! I just saw your Cadbury recipe the other day and was bummed cause it is not Easter but now I can use my OTHER favorite candy- the deadly addictive candy cane kiss!! Thank you. (oooh, someone found cadbury eggs for Christmas?! I love your followers)

I made these for everyone last year but I used a butter cookie recipe and they were a huge huge hit! especially since I rolled them in red and green sugar before baking.. they were so pretty.
I'll definitely have to add y'all's chocolate version to my makings this year ?

Oh. My. Yum!! Chocolate and mint is a deathly combination. The hubs and I love it. And I love Sara's Cadbury cookie recipe. This sounds like a match made in heaven and I can't wait to try it! If it wasn't 11pm at night on a Sunday with our first snow of the season and practically bald tires on our SUV, I would SO go out and buy the candy cane kisses. I'm hoping the weather is decent enough to brave the drive to the grocery store tomorrow. Can't wait to try these!! ?

The opening weekend this year had to be the most picture-perfect weather day one could ever wish for in their wildest dreams. Bright sunny skies, temperatures in the 70s, and very little wind. Great for enjoying the lake, awesome for installing the dock, and wonderful for taking a cruise in the boat. As for an ideal fishing day, it too was almost picture-perfect, except if walleyes were the intended catch.

The high skies and flat calm conditions were at best, some of the most difficult conditions for consistent walleye success. That being said, walleyes are still catchable in tough conditions, but the methods used must be simplified and downsized.

So how did the big opening day fishing adventure with the grandkids go? Darn good! The 4-year-old hooked a really nice walleye on the jig and shiner combo. The fish never made it inside the boat, but the battle was epic. The older kids got to battle some small northern which were landed and released after some serious chaotic screams of delight.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages