Code makes the world go round.
It’s what powers every website we visit, every piece of software we use, and every app on our phones.
But what is code? Can I learn to make my own code? Is there such a thing as bad code? And if so, where can I find examples of good code?
What Is Code?
If we wanted to be technical, we’d say that code is essentially a system of words, letters, figures, and numbers that convey specific ideas in a way that someone’s digital device can read, interpret, and execute.
But that’s not a really helpful definition, is it?
Code is simple, really.
Code is just a kind of computer-centric language that your computer understands.
You tell your program to display a dashboard and ask the user for information, the user types in their info, then your code does whatever you tell it to do with that user information.
Coding is merely the act of writing, testing, and debugging code.
Meaning the more you write, and the more you consume good writing, the better you will be able to write.
What Makes Good Code Good And Bad Code Bad?
So it makes sense that, if you practice writing code, you’ll become better at writing good code. It also makes sense that if you read good code, you’ll pick up on how to make your code better.
But what does good code even look like?
While there may be specific “best practices” that’ll change from language to language, there are still certain best practices that are fairly universally accepted.
Here are some of the things that universally make good code good and bad code bad.
Good code is readable
Good code is easy to read.
Or at least it’s as easy to read as the code allows.
Languages like Python look a lot more similar to English than Java does. But that’s not what we mean when we’re saying good code is readable.
What we mean is that good code is indented so you can see what lines of code go together. Elements of code are all wrapped in the same way so at no point is it confusing what any one tag is doing. Comments explaining what specific lines of code do are plentiful.
Good code is easy to read because the way it’s written is clear, concise, visually pleasing, and consistent.
Bad code is unnecessarily complex
Let’s say you’re designing a webpage. You might have different elements of your page that you want to look a certain way. Maybe you want every other paragraph of text to be a certain color.
Let’s say blue.
You build out your page, write some CSS code that makes every other paragraph of text blue, and you hit the publish button. A week later, your boss wants to change that blue text to green for some reason.
When you go back into your code, are you changing one line of code or multiple lines of code? If you have to change one line of code, then your code is probably pretty good. If you have to change the code on each and every individual paragraph with blue text, then your code is probably unnecessarily complicated.
So if there’s a simpler way of writing your code that lets you do less work in the future, there’s room for improvement in your code.
Good code is scalable
Good code should be able to scale with you.
If you’re building software to handle a specific problem, but as other details such as your data set change, your code slows significantly, then you have bad code. But if your software is able to solve the problem at a similar speed, no matter how much your data changes, then you have written some good code.
Scalable code is code that has been written in such a way that it doesn’t get easily overwhelmed. It’s efficient and solves problems or performs tasks as quickly and as frequently as they pop up.
Bad code doesn’t have logical functions
A function is a self-contained module of code that exists to accomplish a specific task.
But what does that mean?
Let’s say you built your own word processing software. You’d probably have a spell check feature somewhere in your code. That way you could write in your word processor and get automatically flagged every time you misspelled something.
That spell-checking feature is called a function.
Now if your function was called “spell_checker” that would make sense.
That tells other programmers exactly what that function is and does anytime it pops up in your code.
But if it was called “cherry_soda” that wouldn’t tell the programmers anything about the function.
Simply put, that’s bad code.
Where Can I Find Good Code?
So where can you even find good code? There are plenty of git repositories out there that are worth looking at as well as blogs, chat forums, and beyond.
ere are a couple of our favorite places to find good code.
GitHub is probably the most popular software development and version control hosting company in the world. Millions of developers use GitHub to work together on a variety of different coding projects day after day. A lot of these projects are public-facing, meaning you can actually see the code. There are even open-sourced projects where you could actually have the opportunity to contribute to the code.
If you’re looking to find example after example of good code, GitHub should be your first choice.
Bitbucket is another Git-based repository like GitHub. While it’s not as big as GitHub, BitBucket is still used across the world by different commercial enterprises. This also means that it has a lot of public-facing commercial code to look at and make sense of.
StackOverflow is one of the most popular question-and-answer websites for both professional and amateur programmers. If you’re wondering “Why doesn’t my code work” or “Why does my compiler keep giving me ‘Error X,’” chances are really good StackOverflow will be one of the first search results that’ll pop up if you look for an answer on Google.
StackExchange is a StackOverflow property and it’s another great resource for looking for examples of good code as teams of users who are working together to make their current code even better. If you’re going to get into coding in any serious fashion, you should probably just have StackOverflow and StackExchange accounts just in case.
You can also look to sites like Quora, Reddit, and chat services like Discord to find a bunch of different coding communities as well. And if you’re a web developer, you could always just look at the source code of your favorite websites. There may be some restrictions to what you can and can’t see, but you’ll be able to see a lot of the front-end elements with a simple right-click.
And don’t forget about dear, old Google.
Google is a programmer’s best friend.
How Can I Contribute To Good Code?
So let’s say you’ve been reading a bunch of code, and you’ve been leveling up your own coding skills. You may now feel like it’s time to start contributing to one of the open-sourced projects you’ve been looking at.
But where do you start?
Below are a couple of tips to help you get started when you feel like you’re ready to contribute.
Offer to write comments
There’s a lot of code that could stand to be made better. One of the biggest impacts you can have on a coding project is adding comments to the text so that way it’s easier for contributors to parse through the code and know what does what. It’s also an easy way to get access to a project’s code when no one really knows who you are. Adding comments as a volunteer will help you level up your ability to understand code, while adding real value to the project, without risking breaking the project.
That’s called a win-win-win.
Code is only as good as it has been tested. Writing tests to find out where a project could stand to be improved is a great way to provide real value on an open-source project while also learning more about good code itself.
If you’re feeling really brave, and you’ve established a portfolio enough to get access to the project, you can work on fixing the bugs in the program’s code. Everyone loves someone who can find and fix problems so they don’t have to worry about them.
Want To Learn How To Code? Devmountain Can Help!
Interested in learning how to code?
Devmountain can help.
Whether you’re looking to break into the tech industry, level up your current skill set to get that promotion, or you’re wanting to make your app idea a reality without the overhead, we’re here to help you get from where you are, to where you want to be.
Check out our Devmountain courses today.