Developer Relations

Why Open Source Can Improve a Programmer's Coding Skills?

2018-10-03
Developer Relations
en

I’ve been writing software for many years. Recently I realized that the more I get involved with open source technologies, the better my code becomes. This made me wonder: is there some correlation or causation here?

Reading Code Makes You Better

Early in my programming career, I understood that the more code I read, the better my code would become. I learned that when I had to maintain other people’s code, simple and clean code was almost always better than fancy or complex code—even with comments. On the other hand, when I spent enough time understanding complex code, I often learned new tricks. Either way, I improved.

This made me advocate for code reviews in places that didn’t have them. When there wasn’t enough time to formally conduct “code reviews,” I would browse repositories and read code myself. Of course, at that time I was limited by company resources from small teams.

Beyond Syntax

When you have to wrestle with the syntax of any programming language, that’s when you learn how to make the most of that language. A language’s syntax is often quite static, and if you make mistakes, your compiler will complain. Deeper lessons involve what language is best suited for what problems (“the right tool for the right job”), and how to write code in that language so it’s efficient and maintainable.

There are many ways to learn new languages: courses, tutorials, mentors, books, and so on. I usually combine these options to learn a new language. I noticed that when it comes to non-syntactic elements, these methods are often very similar.

Reading actual deployed code from others gives you more. Beyond regular structured learning, you need to learn patterns and practices. The “correct” way of doing things in a language isn’t always the most effective way. You’ll encounter edge cases, one-off transactions, and unexpected integrations. You’ll also find solutions to these problems, some good and some bad, but if you think carefully, this is where “recommended practices” come from. Today’s patterns are tomorrow’s anti-patterns.

You may have your own opinions on things like “always comment,” “put commas last,” “indent x spaces,” and of course you’re right. I have my own feelings about these and other aspects of coding too.

Sometimes when I read other people’s code, I get angry if I see them doing things wrong. But as I read more code, I started to understand that there are always situations common in other people’s code that I haven’t encountered in my own code, and my approach doesn’t have to be so rigid. I not only changed some of my views, but also learned to be more flexible.

Open Source is Everywhere

With the development of the open source movement, the amount of code available to read and learn has grown substantially. Websites like GitLab, GitHub, and BitBucket allow us to access fully functional applications, not just to read code, but to play with it. There’s very little I want to learn that can’t be found in open source code.

When I used to learn new programming languages, I focused on simple things like directory structure and naming conventions. But now, I look for different open source projects and can start piecing together common approaches. I rarely emphasize those types of things anymore.

There’s so much code available, but the quality varies greatly. When we want to learn, it’s often unclear which is good and which is bad. Just keep reading code, and slowly you’ll learn how to distinguish. Reading “bad” code can help you understand why it’s “bad.” The key is not to be afraid to try anything that looks right to you, and when you go down the wrong path, be able to admit mistakes, fix the problem, and move on.

Bad Code is Just Bad, Right?

Some would say “bad code is more abundant and more obvious than good code.” There’s a sub-reddit dedicated to bad code.

Over the years, I’ve written a lot of good code and bad code. When I see code I wrote before, my first thought is how could I write such garbage. This actually means I’m still learning. If I see my old code and think it looks great, then I haven’t improved.

So, how can we learn from bad code?

The More Bad Code You Read, The Better You Get at Spotting Bad Code

When you’re learning and searching for examples, you’ll find and use a lot of code that doesn’t work. Remember, just because it doesn’t work for your situation doesn’t mean it’s bad code. Learning how to make it work can make you better.

How Do You Know It’s Bad Code?

People love to criticize. Read comments, if you see a lot of “WTF,” then you’re probably looking at bad code, try to point out why it’s not good. Don’t just leave comments like “this code sucks.” Don’t pretend you know all the requirements behind bad code; there’s always a legitimate reason why it was written that way. If you know why it’s bad code, leave a constructive comment. Or…

Make It Good Code

Submit a pull request that makes the code better. Fix syntax, use better methods, add comments or fix indentation: these are all great ways to improve code. Add an explanation of why you recommend the change.

I find I learn more when I help others learn. If I think I understand a new topic, I’ll find someone to try to explain it to, which helps me understand and remember it more deeply, and quickly discover if I’ve written bad code.

Giving Back

Remember that open source works best when you participate. Code changes are welcome in most projects, but there are many ways to contribute.

Test open source code and file bug reports; help with documentation; write tutorials and how-to examples; join conversations—or just help spread the word. Everything makes a difference, and the more people participate, the better!

Resources

Here are some links to help you get started. Some I’ve used myself, some I haven’t had time to explore deeply. If you find something useful—or if there’s anything in this article that needs correction, please don’t hesitate to share with us.

Reposted from: Developer Relations »


Similar Posts

Content icon
Content