Developers Give “If Condition” a Name

Hey, you have been writing software for 10+ years. Can you give me advice, tips to improve my skills?

What if someone asks me that question?

I can go on and on with many things. And finally, they will be confused and lost. What if I have to give only one advice?

I will say

Improve your naming

I once wrote the naming matters. Today, I give another small tip on naming

Give your “if condition” a name

Let take a very simple code

public int CalculateFee(Customer customer)
{
    if (DateTime.Now.Subtract(customer.RegisterAt) > TimeSpan.FromDays(30))
    {
        return 100;
    }
    return 200;
}

The condition is, “If a customer has registered for more than 30 days, charge 100 (assume it is USD). Otherwise, it costs 200.

What is the big problem with that code? The problem arises when other developers read the code. He does not speak the same language as when you wrote it. He will, mostly, read the code with the C# language syntax and try to figure out the logic.

An “if condition” is a business logic. Therefore, it should be named properly.

Now, let refactor code and give it a name.

        public int CalculateFee(Customer customer)
        {
            if (CustomerRegisteredFor30Days(customer))
            {
                return 100;
            }
            return 200;
        }

        private static bool CustomerRegisteredFor30Days(Customer customer)
        {
            return DateTime.Now.Subtract(customer.RegisterAt) > TimeSpan.FromDays(30);
        }

Think about multiple operators condition. You will see a big benefit.

 

There is a huge number of conditions in every codebase. If you write a new “if condition” or you see them in your current codebase, give them a favor

An “if” is a business logic, give it a name. If you cannot name it, you do not understand it.

Other developers will thank you for that.

A small action but big impact.

Developers How To Be More Valuable

Developers love challenges, technologies, cool stuff. They are very creative. I heard people ask

  1. How to become a better developer?
  2. What technologies should I learn?
  3. What languages should I learn?
  4. ….

The questions go on and on. But, Yes. Always there is a “but”.

Are they the right questions to ask?

Everything only makes sense in its own context. So the post: Developers who are hired by companies to develop business software.

Broken Light Story

Mary has a broken light in her house. She calls a John come to fix the light. John fixes the broken light quickly. The job is done. He gets paid. However, Mary is not really satisfied. Because, John, while fixing the light, dropped dust on the floor. Mary has to clean it up.

Oops, again, the another light is broke. However, this time, she decides to try to reach Steve. Steve comes and fixes the light. Before claiming the job done, Steve cleans up the floor, he also does some check up on the other lights in Mary’s house. It costs Mary the same price as using John’s service.

Can you guess who will get more clients? Of course, that is Steve. Steve is more valuable than John.

So, what is the difference?

The same task, different delivery quality.

Oh! A nice story! But I am a developer. What is in it for me?

Yes. My friends, we can apply the same philosophy to increase our value. Remember this?

You get paid for the value you bring to the marketplace.

Our value is determined by

The quality of our deliveries define our value, not the tasks.

Developers’ Clients

Have you ever thought of who are developer’s clients? What? Do they have clients?

Yes. Yes. And Yes. There are.

Whoever use their deliveries are their clients.

QA/Tester

At daily basis, developers implement user stories, fix bugs. QA/Tester will verify their deliveries.

Code Reviewer

Given that a company has a code review process. Code reviewer is developer direct client.

Leader/Manager

Of course, they are your clients.

Other Developers

You are not alone in a project. Some other developers will use your code. They consume your API.

There might be more clients. You get the point.

A Better Question

What should I do to increase my value to my colleagues, my company?

Some might think of solving challenging tasks, implementing cool stuff. Yes. They are true. However, there are not so many challenging tasks in a company. Let’s take the “80/20” rule. There are 20% of challenging tasks.

You have to find ways to take advantages of 80% left to increase your value.

Increase Your Value

Here are some tips that can help you, developers, increase your value.

Comment Your Deliveries

These days we all use tools (Jira, Targetprocess, Trello, …) to manage projects. Your tasks are presented as Cards (User Story Card, Bug Card, Task Card). Each card has a powerful feature for communication: Comment.

You should take advantages of the comment feature.

User Story/Task

Usually, you should write

  1. Question: To communicate with the card owner or other developers in the team. There is another skill you need to learn here: How to write a good question?
  2. Technical Design: Write whatever you think they are valuable.
  3. Solution: So other can know what you have done to finish the job.

Bug

Usually, you should write

  1. Question: To clarify the bug.
  2. Done result: This is a crucial part. When you fix a bug, you should write in detail

How to write a “bug fixed” comment? There are at least 3 parts.

  1. Root Cause: What is the root cause of the bug.
  2. Solution: How you solve the problem. The more detail the better.
  3. Test result: Prove that you have tested your fix.

Think Before Code

I am serious. Here is what had happened to me many times.

  1. I got a bug to fix.
  2. I located the place that bug occurred.
  3. I added my code to the existing code.
  4. Compiled and tested just my scenario.
  5. QA claimed my bug passed. And congratulated me that there was a new bug. Guess what? Most of the time, it was me creating a regression bug.

The dangerous thing is fixing a small bug causes a critical bug.

Ask these questions before code

  1. How can I fix the bug without modifying existing code?
  2. If I have to modify, what are side effects? How many affected places I can think of?
  3. Do I understand the logic of the code I touch? At least at the method level, you should understand its logic.

Lesson Learned

You cannot grow if you cannot learn anything after each task. There is no silver bullet for learning. Each must find their own way. What you can do is to set your mindset.

After each task, you can ask yourself this question:

Hey! What do I learn from completing this task?

And you must be serious.

 

In conclusion, with the context of a company, being a software developer looking for ways to increase income (oh yeah cash, money), you should ask a better question.

As a software developer for 10+ years, I would like to offer you a new question

What should I do to increase my value to my colleagues, my company?

And 3 tips to increase your value

  1. Comment your deliveries
  2. Think before code
  3. Lesson learned

It is Lunar New Year. If you are looking for improvements, changes, those tips might be a good start.

Happy Lunar New Year! and Have Fun!

Small Things Matter: Naming

Naming is hard. But we can improve and make a difference.

As developers, we write code for a living. Most of the time, we pay attention to solving problems, learning new technologies; kind of new cool stuff. We tend to ignore or look down on small things.

There are so many small things. Well, in reality, everything is small things. Big is just a sum of small things. Naming is one of them.

Dear developers, what is on your mind when you heard about “Naming”?

  1. Project name
  2. Class name
  3. Method name
  4. Interface name
  5. Property name
  6. Variable name
  7. Hardcoded value

They are all matter. Why? Because they help us__human being__can read the code. They help us understand the logic by just looking at the signatures.

In the technical jargon, we call readability.

Let’s take a look at “Hardcoded value” and “Variable name”. They are pretty much the same thing. I have seen many places that developers name a variable: b1, b2, … They have the same problem:

They give no meaning at all

Number Cannot Speak

Take a look at this code. I am sure all C# developer knows

    public class BadNaming
    {
        public void CanYouUnderstandTheLogic()
        {
            Thread.Sleep(180000);
        }
    }

The code says that: Should sleep (block and wait the current thread) for 180000 milliseconds.

What are the issues with that code?

  1. As a reader, I have to convert 180000 to a meaningful concept that my brain can process, Ex: Second, Minute, Hour. As a human, we do not usually deal with milliseconds.
  2. What is the logic behind the sleep? Usually, developers will write inline comments. (Hint: You should do a quick search and will know that inline comment is not a good approach)

The number itself cannot carry meaning. It cannot speak what it means.

Give It a Meaning

Now take a look at this code. What do you think?

public void GiveMeMeaning()
{
    var sleepThreeMinutes = TimeSpan.FromMinutes(3);
    Thread.Sleep(sleepThreeMinutes);
}

The Thread.Sleep method can take a TimeSpan. Usually, developers forget that option.

With a little change, I can assign meaning to a number. The code can self-explain its meaning.

No matter what languages you are using, there are primitive types that convey, naturally, no meaning. When you use them, think about the other person (maybe you in a year) will read that code. They have to spend time investigate the meaning.

I just pick a small corner of the problem with the hope that you get the idea and pay more attention with your code. Someone will thank you and call you a professional.

Professionalism is nothing than caring for small stuff.

Dear Leaders

At any point in time, one is leading or being led by someone. Everyone is a leader within a context. You might be led by a leader in your company. Mostly because you are the bottom of the organization. However, when you are at home, you lead your family. If you are a wife, you lead your husband (sorry guys, it is just the fact). If you are a husband, you lead your kids (how dare you lead your wife 😛 ).

I just take a small context for this post: You lead a development team. Take a more common scenario that I have seen:

You lead a developer team.

A leader can be a technical leader, a scrum master, a manager, … The context is pretty much the same: You take care of a team.

There Small Things

Three things I consider the most important: Accountability, Mentor, and Cheer Leader.

Accountability

I like military principles. When a soldier is in a battle, his captain and comrades are his life. He trusts them. I know, in our IT job, most of the time it is not a Dead-Or-Alive situation. That might be a reason why leaders do not care so much about building accountability.

Mentor

Did you forget to help your member growing? Deep inside, everyone wants to grow. They want to be useful. They are expecting someone to guide them, to help them in a positive way. That is you__leader.

Should you add “Mentor” in your responsibility bell? Your call! I highly suggest you should.

By helping other, you are helping yourself. You help them grow, they will lift you up.

Cheer Leader

Well, this is not a football match. But you get the idea. Make the team closer, talk more to each other, discuss openly.

Working is not easy. There is stress. But, there should be joy most of the time.

Another Sand in the Sea

There are thousands of articles, books, seminars, classes … about “Leader and Management” topic. They are useful resources. I have read some of them. The more I read the more confuse I am.

Finally, I found out: Hey, wait a minute! There are too much! Maybe I should start with 3 small things and change my mindset.

Everyone has deserved a chance to grow. So I am!

 

Oh New Year, Again! Let’s Make Wishes

New year alway comes. I guarantee you. Welcome to another Lunar New Year. Everyone makes wishes. They wish for themselves, for their family, for their relatives. Everyone has good intention.

Yes! I do. I make wishes every new year. Actually, some years ago, I had made vows. Kind of

  1. I vowed I will quite smoking
  2. I vowed I will drink less
  3. I vowed I will save money
  4. I vowed
  5. …….

I just forgot one important vow:

I vow I will make the same vows again, next new year

I am not saying that process is good or bad. I just wonder why I did that again and again. I know some people do the same thing.

So, let’s explore some theories behind this question

Why do people make vows every new year?

No Cost

You do not have to pay anything for your wishes/vows. And if you do not say it out loud, you are safe. No one knows.

Feel Better

Oh God, It is TET (our Vietnamese name for Lunar New Year). TET is the time for parties with beer, food, hanging around with friends. I might feel better if I make some promises to myself. Kind of, Well, it is ok to relax. I will be a better person after TET.

Make up for a Bad Year

Sometimes, I screw up with the current year. And there is a feeling of “nothing can be done this year”. I just let it go and make a promise for the next.

Screw up and Wish for a better one without taking any action. That’s kind of thing!

High Emotion

People are happy when TET (except some special circumstances). Happy people make promises. They believe in a bright future.

Think about your childhood, if you want to ask parents for money, you know when to ask. Of course, when they are happy 🙂

What happens after TET?

—————–>

Nothing happens! Period.

People come back to their real life. Fight for a living. Have some more parties. … And then finally they realize:

Oh Shit! TET is coming. There is no time for me in this year.

The cycle begins.

Ok. Enough talking! What should we do instead?

This year (2017), I decided to do

  1. Have a list of small things to do.
  2. Make a small plan for them
  3. Start them immediately (Write this post is a part of the actions). Take action!
  4. Have a good time in TET with beer, food, visit parents, relatives, friends, …
  5. Back to work immediately after TET.

My friends, maybe it is the time for you to reconsider what you have been doing for years. No matter what actions you take, they are yours. And you are always right with your decisions.

Everything has its cost.

The cost of a wish is the time.

Happy Lunar New Year! Beer Up.