## DEV Community

Buzzpy 💡

Posted on • Originally published at buzzpy.hashnode.dev

# Become a "Better" Programmer

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?

## 1. Coming up with the solution

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, 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.

...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 totally clueless. I recommend you to check this article about KISSing your code.

Oh, I was just gonna miss it. You can find a solution for the anagram problem here. It's not the perfect one, but it does the job!

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

Daniel Macák

It's fair of you to admit AI wrote part of your article, but I still think it's not a good approach. By the very way generative AI works, it produces a generic rehash of things somebody wrote before you. I believe that authors should present ideas in their own unique way, even if they synthesize works of other people or indeed ask ChatGPT themselves. Otherwise, what's the point of writing an article? That said, I think it's good to use AI to improve the formulations.

Buzzpy 💡 • Edited

I totally agree, @daelmaak . I did this test-article with ChatGPT to understand if there any way companies or publications can use AI to write for their blogs but apparently, we are not near that point— checking the part written by AI will show you that.

And yes, I promise you guys will never again see an article from me where at least 90% of the content will be from AI, I'm keeping my max. to 99%

Thanks for the comment, I appreciate your feedback! 🥰

Eckehard • Edited

#### I´m missing refractoring and reusing code?

If your code grows, you will reach a point where you start to feel you loose control. Too much things to keep in mind. That´s the point to start refractoring and reorganizing the whole codebase.

Eventually you will find some parts in your code that you find useful for other projects too. Building reusable units and useful tools can be quite laborious, but may pay back in the next project. If it is well organized, it may save you from solving the same problem again and again.

Sometimes you will find, you got stuck. Then, take a break, do something else. Maybe with a little distance you find a better approach. Even if you need to throw away a large part of your work, this might be the better solution:

### Remember: 5 days of debugging can save you five minutes of thinking!

Andrei Chevozyorov

Learn base principles of CS, like discrete math, linear algebra, calculus.
This will gave you opportunity to be creative in solving problems.

I really in love with success stories about decision tasks with math knowledge

Lymah

Nice post.

Maya Walker

This is a cool standard approach to any task in any direction! I analyze my marketing tasks in the same way

Buzzpy 💡

Of course! I used the same technique when it comes to branding, math or anything that's confusing.

Flowzai

Buzzpy 💡

You're welcome, @flowzai ! Thanks for reading..

kvetoslavnovak

ChatGP article?

Buzzpy 💡

Hello! I can assure, this is not fully written by ChatGPT. In fact, I have clearly mentioned that only the part on "Testing" code is written by ChatGPT (If you read the article from the beginning, you can observe a clear change in language and tone too). Besides, this article was an Test to find out whether AI can help us in technical writing.

If you are confused with the percentage, it's calculated by AI generated words divided by Total Content into 100%. Words written by myself is lesset than generated content which makes it a greater percent.

So I beg you, please don't call it a ChatGPT article. I put a lot of effort on my content even if its just 500 words and it just hurts when its called as an AI generated content.

kvetoslavnovak

Ok, thank you for your explanation.

Dmytro Klimenko

all I understood was the picture of Toby from the TV series The Office

Some comments have been hidden by the post's author - find out more