DEV Community

Dhruv Joshi
Dhruv Joshi

Posted on • Updated on

🔥Top 10 Things You Should Avoid While Coding: Valuable Tips for Programmers

Coding is a hard (for some) and challenging field, and even professional developers can fall into common traps that can slow down their progress and hinder their success. In this blog post, I will provide valuable tips on the top 10 things you should avoid while coding to help you become a more efficient and effective programmer.

(These tips may feel common sense but may be helpful for beginners!)

Avoid Overcomplicating Your Code

Complex code can be difficult to understand and maintain. To avoid this, focus on writing clean, simple, and easy-to-read code that is easy to understand and modify.

Avoid Copying and Pasting Code

Copying and pasting code from other sources without understanding it can lead to serious errors and vulnerabilities in your code. Instead, take the time to learn how the code works and write your own code from scratch.

Worth reading:

Avoid Hardcoding Values

Hardcoding values in your code can make it difficult to modify or maintain. Instead, use constants or configuration files to make it easier to update values in the future.

Avoid Ignoring Error Messages

Error messages can provide valuable insights into what went wrong in your code. Always take the time to understand and address them to avoid future issues.

If you like reading the post, please hit like, follow and comment! Thanks. It motivates me to post more content like this.

Avoid Not Commenting Your Code

Adding comments to your code can make it easier for other programmers to understand your code and can also help you remember what you were thinking when you wrote it. Don't forget to add comments that explain what your code is doing and why.

Avoid Using Outdated Technology

Using outdated technology can lead to security vulnerabilities and compatibility issues. Always use the latest technology and keep your software up-to-date.

Avoid Not Testing Your Code

Not testing your code can lead to bugs and errors that could have been easily prevented. Take the time to test your code thoroughly before deploying it.

Avoid Over-Optimizing Your Code

Over-optimizing your code can lead to slower performance and reduced readability. Focus on writing code that is easy to read and maintain, instead of overly-optimized code.

Avoid Not Backing Up Your Code

Not backing up your code can lead to the loss of hours of work. Always back up your code to a secure location, such as a version control system or cloud storage.

Avoid Not Asking for Help

Asking for help when you're stuck is not a sign of weakness. It's important to recognize when you need help and seek assistance from your colleagues or online communities.

Last Things...

By following these valuable tips, you can become a more efficient and effective programmer. Remember to focus on writing simple, clean, and easy-to-read code that is thoroughly tested and backed up regularly. And don't forget to ask for help when you need it! By avoiding common mistakes, you can save time and avoid costly errors, helping you achieve success in your coding career.

Are you a software engineer and looking for job change or finding start, head to here: Click here!

If you are stuck somewhere into a complex project or got an idea to start a project with then reach me here.

Top comments (10)

aarone4 profile image
Aaron Reese

Avoid over simplifying your code. The code needs to be as complex and the business case needs but no MORE complicated. Follow conventions established in the industry, language or corporate culture as this leads to less cognitive load for future readers.

Copy and paste when it is appropriate to do so: save on cognitive load to implement a pattern or configuration. Do not copy-paste within your code base more than once. If you have to use it a 3rd time, refactor.

Hard coded values. YUP. No argument there. Make sure you put the values in a config file and DO NOT put the config file into source code control but DO PUT a sample config file into SCC.

Always assume errors and code defensively. Your database may be slow, the API may be throttled, the user may have entered garbage in your form. But use a convention so that the happy path is easy to follow: abort early from errors, throw exceptions and handle issues in function calls to keep error processing out if the main thread

DONT comment your code. It should be perfectly able to grok the logic with clean code principles: properly named and scoped variables, classes, functions and file names. DO add comments for WHY, but not HOW or WHAT. Don't leave derelict code wrapped in comments; those are the responsibility of the source code control

Use long established, stable, reliable legacy code that has all the edge cases dealt with. Keep abreast of any security or performance issues in packages you use. Where possible use one version across your codebase. There is nothing more annoying than having solution seven different versions of Angular:)

Write your tests before your code. Firstly it ensures you understand the business problem you are trying to solve, secondly it will force you to write testable code.

dhruvjoshi9 profile image
Dhruv Joshi

Thanks for this!

margarizaldi profile image
Marga Rizaldi

Your comment is only motivated by debating purpose, to tackle someone so you will look better huh?

What's the point of "The code needs to be as complex .... but no MORE complicated." compared to the "avoid over complexity" from the post?

Then the post suggests not to copy codes from other source unless we understand it to avoid any unwanted issues, that should be clear that the case is from "other source" like stack overflow etc, then how could you think about "cognitive load"?

For config, what's wrong with it to be in the source code? Any config can be included or put everywhere as long as no credentials there.

See? One paragraph above is an example of "pointless argument" like what you did, I wrote that for you to let you know how it feels.

The same for errors, outdated tech, etc. you just wanted to argue with, again, pointless arguments.

Finally, the post talks about tips (and preference) so we don't need to be that hard to argue every single point, which is childish and embarrassing.

Thank you.

aaronre16397861 profile image
Aaron Reese • Edited

wow, passive agressive or what...
Of course it is for debating purposes, that is one of the objectives of DEV as a community. The point of my reply was to stimulate debate and to also alert less experienced members that these points are not absulutes.

Complex and complicated are not the same thing; in fact the more complex your code the LESS complicated it needs to be. Complex relates to the business requirements and the code glue for your particular stack. Complicated relates to how you approach the code base: Are you applying SOLID principals, do you have separation of concerns between front and and back end code, Are you putting different levels of functionality in separate files and namespaces etc.

Copy-Paste. Yes you should understand code you are C-Ping but I wouldn't advocate writing my own if there is tried and tested pattern already established. Just look at all the packages available in NuGet or NPM that have been battle-hardened by use in thousands of projects. That's not to say they are infallible (left-pad anyone??) but you are way less likely to get into trouble with them and you won't waste months of development time when you could be adding value.

Config should NOT be in source code control PRECISELY because it CAN contain sensitive information. If you start splitting CONFIG into safe config and risky config you are asking for trouble. I did say a SAMPLE config should be included so that future devs and anyone building the system on a new platform knows what shape it should be. Also, when deploying to production, you will should pull down from the head of the repository and having the config file in there will overwrite all your production settings with the Dev settings - not good.

For Outdated, I was trying to make the distinction between stable, known technologies that could be considered boring and the 'cutting edge' that we mostly like to work in. JQuery is still a valid choice for many projects even though many of the functions it was leveraged for are now available as native APIs in the browser. CodeIgniter is a perfectly fine MVC framework for may projects: they don't need the complexity of Laravel or Symphony.

Why is providing a counter point to every case childish? I'm not embarresed to be open to expaniding my knowlege and understanding.

yolocat profile image

Perfect explanation!

labsquokka profile image
Quokka Labs

Useful tips @dhruvjoshi9. thanks for sharing

dhruvjoshi9 profile image
Dhruv Joshi

Thank you!

gjeotech profile image

Lovely.. thanks 👍

sique976 profile image
San D.

Great tips! Very well!🙂

dhruvjoshi9 profile image
Dhruv Joshi

Glad you liked it!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.