Become a "Better" Programmer

A short guide to solve problems in a "Better" way.

·

7 min read

Become a "Better" Programmer

Image description

Hey there, Buzdies! As far as I learned from being in tech for around 3 years, becoming "better" in programming isn't all about mastering a certain programming language or several languages— it's all about how we think. No matter how vast your tech expertise is, to solve a problem, you have to follow "better" ways when working on programming challenges, projects, or whatever. And that's what we cover in this blog post.

TL;DR?

Image description

1. Coming up with the solution

Digital Art Solutions Clipart, HD Png Download - kindpng

As a beginner, I tried to process the steps of solving the given problem at the same time I was reading it. And yes, it leads to a lot of consequences. Consequence Number 1 is you messing up the whole thing— you are not doing any of both tasks correctly, neither understanding the problem nor thinking about solving it. I'd be able to solve it eventually but in fact, it would take me a lot of time.

So how do you do this correctly? Let's take the "Anagram" problem into consideration.

Given two strings a and b consisting of a set of characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, act and tac are an anagram of each other.

Step 1 is to read it twice: don't think about inputs, data type conversions, iterations, conditional statements, how much caffeine it would take to solve it, or anything, just read it. When reading for the second time, you can highlight important points to consider. For example, you can highlight properties needed for a string to be an anagram.

And then comes step 2: Break it down! I love notebooks when it comes to this. Scribbling with a pencil is the best way to solve problems, small to big (choose a good pencil with that perfect sound). Write the first algorithm you get in your mind. It can vary from the correct one if you're just starting but when you improve your problem-solving skill, the first one is often the correct one (which means it WILL work).

When reading the above task, the first thing that came to my mind is as below.

Image by the author

Remember: Don't try to apply any syntax rule(S). You will get to it eventually. If you get the correct syntax (variables for example) even without thinking about it, that means you're really into coding.

And finally, step 3— writing the code. If you're a beginner, I suggest writing the code in the notebook itself, as it helps a lot in modifications of the code. You can write down the code like this, and if you feel like there are more modifications to be done, write down that modified code, and if you still feel like you can refactor that code, Cool! Note down that piece too. Compare, notice, modify!

In the end, you'll have the perfect solution— the PERFECT one, and it didn't waste a second of your time, and it's a joy to code on paper. Us programmers need a break from the keyboard sometimes, you know.

2.Writing the code

Once you get the solution right, writing the code is easy-peasy-lemon-squeezy. But this is about being BETTER at programming, so let's cover a bit about this part too.

Tip #1: Meaningful (and beautiful) Names We love 'em, don't we? A properly named code has a higher readability and we can easily understand what's going on by reading the code, no comments are needed. It will help your team a lot as well as you.

Image description

...and hopefully, you won't get yourself stuck in this situation.

Also, try to use CamelCase for variable and method names as it increases readability as well as the "beauty" of your code.

numberOne = 14 # Camel Case
number_one = 14 # NOT camel case,
                 # whatever it's called

Tip #2: Good Comments Make Good Moments Every single programmer on the earth is tired of comments that explain "WHAT THIS IS". Your comment doesn't need to explain what you're doing; explain why you are doing it.

For example, if you comment like this, it's an obvious sign you are a jerk.

def anagram(word1, word2):
    word1.lower() # converting given input to lowercase
    word2.lower()

    word1_list = list(word1) # converting input to a list of chars
    word2_list = list(word2)

Even non-coders might be able to say what you've done in that piece of code. But the following example, of course, is from a good programmer,

def anagram(word1, word2):
    word1.lower() # so that this doesn't differentiate between lower and upper cases
    word2.lower()

    word1_list = list(word1)  # to split the letters— easy to sort and find len
    word2_list = list(word2)

Tip #3: Follow the KISS Principle Keep it simple, stupid. It's not only about simplifying the code either. You must be able to take a step back and view whatever you just did from another person's view, who is clueless. I recommend you to check this article about KISSing your code.

Testing your code

So, you've poured your soul into crafting that perfect solution, your fingers have danced across the keyboard to give life to your code, and now, it's time to put your creation to the ultimate test. Brace yourself as we unravel the secrets of testing, bringing your code to a level of excellence that even algorithms would tip their virtual hats to.

Tip #1: Comprehensive Test Cases - The Sherlock Approach Picture yourself as the Sherlock Holmes of code testing. Investigate every nook and cranny of your program with a diverse set of test cases. Consider the usual suspects - the common use cases, the tricky edge cases, and the dark alley of potential errors. A comprehensive array of test cases ensures that your code stands tall and proud, ready to face any challenge.

Tip #2: Automated Testing - Your Code's Personal Butler Why manually perform tasks that your loyal servant can handle? Enter automated testing, your code's personal butler. Tools like pytest for Python or JUnit for Java tirelessly execute your tests, providing rapid feedback on your code's functionality. Sit back, relax, and let automation be the backbone of your testing regimen.

Tip #3: Unit Testing and Integration Testing Think of unit testing as the superhero examining each component's prowess in isolation. Meanwhile, integration testing steps in, evaluating the dynamic interplay between these components. A harmonious balance between the two ensures your code doesn't just play well with itself but shines in the grand orchestra of system functionality.

Tip #4: Boundary Value Analysis - Navigating the Edges Navigate the edges of your code's universe with Boundary Value Analysis. Test those inputs that linger on the boundaries of acceptable ranges, uncovering vulnerabilities that might be hiding in plain sight. It's akin to exploring uncharted territories, where the true mettle of your code is put to the test.

Tip #5: Continuous Testing - The Ever-Vigilant Guardian Imagine an ever-vigilant guardian standing by, ready to protect your code from regressions and unexpected pitfalls. Welcome to the realm of continuous testing. Tools like Jenkins or Travis CI tirelessly run tests whenever your code changes, providing real-time insights and ensuring your code's integrity remains unblemished.

Tip #6: Peer Reviews - The Code Conclave Gather your fellow developers for a code conclave. Let peer reviews be the crucible where your code undergoes a baptism of scrutiny. Constructive feedback from your coding comrades not only fortifies your codebase but also hones your skills, creating a culture of collective improvement.

In the world of programming, testing isn't a mere step; it's an odyssey, an ongoing quest for perfection. Embrace these testing tips and best practices, infuse your code with resilience, and let your programming endeavors stand as a testament to the artistry of a true code artisan.

Summing Up

That's all in my mind right now. Hope you learned how to work like a "better" programmer on a project, challenge, hackathon, or whatever!

Side Note - I'm currently testing how ChatGPT can assist us in technical writing. Please be kind enough to share feedback about this article, as AI has written over 56% of this article (not to mention that part can be recognized easily). View ChatGPT Chat

Image description