A warning to new developers. Understanding answers before copying them

A helpful answer can save hours, a deceptively unhelpful one can waste them or worse, introduce hidden bugs that go unnoticed.

As a new developer it’s tempting to go straight to stackoverflow at the first sign of an issue. This can save you hours of debugging to work out what the problem is and if used correctly is a great programming tool. The problem comes when you build too much reliance on stackoverflow answers or blog posts.

An example I saw recently was a beginner who was learning rails come across and error in their code. They had created a controller to create new posts, the error came when saving the post and an error was displayed that user_id was required because the Post model belongs_to :user. After some searching they found an answer online which stated that changing the relation to belongs_to :user, optional: true would solve the issue. Indeed, making this change would remove the error but it doesn’t solve the actual issue which is the controller is not saving the current user with the post. This kind of answer is worse than useless because not only does it not actually solve the issue, it seems like it does. This means later down the track the issue is going to come back. In this case the issue would arise again when attempting to display the username on the newly created post.

When you encounter an error you don’t know the solution to first think:

Usually just taking the time to really think about what is going wrong will lead you to the answer. If not then it’s time to search for an answer. If you find one then you must consider:

If you follow these steps you will avoid nasty issues that come from copying code that you don’t understand which can lead to some nasty security issues or just wasting time debugging them.

This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.

Looking for a fast and secure VPN? Check out Private Internet Access.