Over Discounting Can Kill Your Brand and Destroy Perceived Value

When business is slower than desire, many companies believe discounts will bring customers who will return for more, but that strategy rarely works. New businesses and startups often believe that the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Top 7 mistakes to makes bugs in your code

Like any other developer, you don’t want to have bugs in your code. Low rate of bugs will make you look like a super hero developer, plus — there will be less time wasting on bugs, so you will have extra time for learning new things and to improve your skill. You could also keep in mind all the extra hours you might spend on bugs fix, and you could avoid some of it easily.

As an experience developer, and one who solved bugs of many others, I will give you some tips that will reduce your bugs. Those tips could be relevant for any OOP language (I am originally a C# developer).

Any variable being used in your code, and might have a NULL value — you must have check if it has a value before using it. In C#, the usage is : objectVar.HasValue. If you do not do so — in cases it is NULL, an exception will occur. You don’t want it to happend.

2. Check null value in views, SP

Same thing I said in the first point, is relevant in here too. As a developer, you must use database on a regular base. You should have at least some basic understanding about how it works.

A table field could be define as nullable or non-nullable vale.

If it is a non nullable, we have no problem here.

If it is nullable, you should check it. For example, when I have an nvarchar field in a view, instead of using:

select FirstName from WorkersTable

I would do:

select isnull(FirstName, ‘’) from WorkersTable

Be aware that, if you have two fields of type nvarchar, and you combined them when one of them is null and the other is not, then the result will be null. For example:

select firstName + ‘ ‘ + lastName from WorkersTable

If lastName is null, I might receive result as NULL (it may differ between databases…)

So this is why I will write the above query like this:

select isnull(firstName, ‘’) + ‘ ‘ + isnull(lastName) from WorkersTable

3. Short function

Each function/ method has only one assignment to do! No more, no less!

It has several advantages, such as easily finding and fixing bugs. But more important — the code is more organize and readable, when I have a method using several helpers functions. When a method is having 1000+ rows, you will get lost. When all is clear, problems will pop up during development time, so less bugs will be.

4. Use common methods and extension

If I recognize a functionality that is relevant for several places in my code, the right thing to do is to put this method in a separated place, like Utils class, and everyone will use it. Also, if it will make the code more readable — you should implement it as an extension. The extension method should also be located in a place where everyone could use it.

The advantages are — code is more readable and more easy for maintenance. It will automatically makes you write better code. In addition, once a bug was found in one screen in your project, you correct the relevant place and it will fix all other screen that uses this method. The meaning is — fixing several bugs, when actually you solved only one!

Or, maybe no one saw all the other bugs in the other screen, and up until they will… you already fixed it!

5. Think about time and space complexity

Always keep in mind that in the real world, the database will be bigger and many users will use your application at once.

Plan ahead your code, architecture and design accordingly!

6. Think about all cases of using the application

The product manager, product owner and data analyst should have think about all cases that could be for the user to using the application.

But, in many cases — there are things they didn’t thought of, while you did.

In that case, you should take care of this in your code, because if you don’t — someone else will think about it later, and it will be a bug that you need to solve!

7. Give meaningful names for methods, classes and variable

Again — readable code is more easy to maintain!

This is why you will be likely to have less bugs in your code, and if you will — it will be easier to fix.

That’s the common things I’ve saw. If you’ll keep those rules, you will have much less bugs. Keep in mind those rules, and keep in mind to KISS (keep it simple). You’r work life will be much easier that way!

Add a comment

Related posts:

Keeping Your Social Media Secure and Your Friends Safe

The steady flow of pings woke me up in the early hours of the morning well before my alarm was set to do the job. Notification from friends in other time zones had me wondering what on earth I was…

The Building Blocks of Culture

Culture is defined as the customs, arts, social institutions, and achievements of a particular nation, people, or social group. Culture is not one thing, but instead an end product, it’s the result…

Focus is the most precious skill that you should cultivate now

We are in an age of information overload. Distraction is a constant companion. The phone chimes with a notification alert, a mail pops-up, a colleague calls you for a quick question and your mind…