Coding and writing are more alike than you might think. I’ve been writing as a hobby for about 10 years. I’ve only been coding for a short period of time, but I’ve started to notice that being a writer helps me be a better programmer. These two skills are really not so different. Both coding and writing require some creativity, as there are as many different ways to code something as there are to say something in writing. And there are some very important principles that apply to both. I want to dive into the principles of effective writing and how those principles are applied to the skill of programming.
One of the most important principles of effective writing is purpose. Know what you want to say before you say it. Have a goal. Writing without purpose is not going to make anyone feel anything. It’s not effective. When coding, purpose is equally as important. You should know what you are trying to accomplish before you code anything. Thinking and planning are a big part of the process. Without purpose, coding can be a long, grueling, irritating process. When you code, knowing exactly what you want to do before you do it, you can get things done quickly and easily.
Be concise. It’s a very common piece of advice in writing. You go over your writing again and again, you revise and revise, until it’s short and sweet and to the point. Similarly, you want your code to be DRY (Don’t Repeat Yourself). You want it to be clean, elegant, and minimal. Brevity makes for readable writing and readable code.
Be precise. When writing is unclear, you have to read it multiple times to try to understand what it’s trying to say. And the same thing applies to coding — clear and precise variable names, method names, and file names are important. Being precise with your words, both in writing and in programming, helps others understand what you are trying to convey.
The simplest solution is usually the best one. This applies to both writing and coding. When you write, you want your writing to be clear and understandable. You don’t want the reader to have to pull out a thesaurus for every other word. And when coding, your code should be simple. The simplest solution to the problem is probably going to be the best one. If you follow the principle of simplicity, your codebase should be readable and understandable to other coders.
You may be someone who loves coding but finds writing very challenging. Hopefully keeping these four principles in mind will help you to be better at both and eventually even enjoy writing!