DEV Community

James dengel
James dengel

Posted on

3 2

Why "copy, paste, fixed" needs to change to "copy, paste, why"

By "copy, paste, fixed" I mean copying a few lines you don't understand into your code that fixes an issue. I am going to present an argument why we need to change our approach to "copy, paste, why".

When we are young we learn by copying actions, my daughter will say:

"My baby needs to go to sleep Daddy!"

She has no idea why the baby needs to go to sleep (at 7 or 8 in the morning) but she is learning by copying our actions and talk by saying that our baby (her) needs to go to sleep.

When we are adults, we have more insight into learning, we can look at something and try to ascertain why something occurs. We know that we only really "need" to go to bed when we are tired, or when it's late and you know you have to wake up early, or it's good for us to have regular and undisturbed nights sleep.

Basically when we are young we learn by "copy, paste, fixed".

But when you are an adult you can "copy, paste, fixed" but sometimes this will lead us down the wrong path (Like putting the baby to bed at 8 in the morning)

Take for instance a common gotcha in Python 2.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)

You do a search as this is confusing and hit upon someone suggesting:

string.encode('utf-8')

You go whoo, problem fixed move on.

WAIT, WAIT, WAIT, WAIT

Try "copy, paste, why",:

We apply the fix and it works, now we ask why ?

5 minutes later:

"Oh all strings in python 2.7 are assumed by default to be ASCII, oh I was so naïve."

10 minutes later:

"Oh between Python 3 and Python 2 string are handled differently as this was causing confusion generally"

15 minutes later:

"Ok I didn't even know about the unicode type in python 2"

Obviously there are times when you don't have 15-20 minutes to spare for every possible issue, but get into the habit of asking why will make you a better developer.

Let me know if you try this approach rather than "copy paste fixed" and how you get on.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay