How the Writing Process Can Help Beginners Learn to Code

Learning to write code is challenging, and it takes a great deal patience. The learning curve is steep. In addition to learning the concepts and vocabulary of a programming language (such as key words and methods), programming languages have structure — code blocks and indenting — as well as syntax — semicolons and curly brackets, and let’s not forget all the frameworks and libraries you need to pick up along the way.
How do you become fluent at writing code when there are so many elements to learn? Great writers, regardless of the genre, have one thing in common: they write. Writing, in other words, takes practice. Skilled writers often follow what is called the writing process, which provides structure and strategies to follow while working. In this post, I will explain the writing process using a code challenge from Code Wars.
Practice
First and foremost, you must practice. Even if you devote a mere 20 minutes a day to practicing, you will see definite improvement. There are plenty of websites to find practice problems such as Hacker Rank, Rosetta Code, and Project Euler, but my favorite is Code Wars. It is easy to use and highly motivational. The more problems you solve, the more you level up and unlock honors. For this blog post, I am going to focus on an entry-level code kata from Code Wars called Credit Card Mask. The purpose of the kata is to take a given credit card number and return that number “masked” where all but the last four digits are printed as hash tags (“#”).
Prewriting (also called Brainstorming)
The first stage of the writing process is prewriting, where you take the time to think through the logic you need to solve the problem and plan your steps. The purpose of this stage is to work out your ideas on paper — not to write the code. While you are prewriting, outline the steps you think you will need. Often during prewriting, I draw out the end result and think backwards through the steps. Here is my drawing for the Credit Card code challenge.

Drafting
Now that you understand the logic and the flow of the program you are writing, it’s time to get it onto the computer screen. In other words, translate your prewriting into a first draft of the program. The goal here is to make your program work to some degree. Don’t worry if it is messy and cumbersome. Write your program incrementally so you can test each line before you move forward. My first draft of this program works, but needs to be revised. We will handle that in the next step.
Note: While I’m working with Python for this example, these steps can be applied to any programming language.

Revising & Editing
Once the steps are working, it’s time to review your code and make any necessary changes. In the world of writing, we call this revision (when working on the concepts or organization of our writing) and editing (when working on grammar and punctuation). In the world of programming, we call this refactoring, where we improve the code without changing the desired behavior of the code.
Refactoring is an advanced concept. For now, focus on a few key ways to improve your code. Start by checking your readability. Will another programmer understand your code? Are the variables clearly named? Now, check your logic. Are you using all of your variables? Do you have unnecessary conditions? What can you condense? With that in mind, take a look at my second draft for the credit card challenge. Can you analyze what has been revised? Why was I able to remove the for loop? Do you think this version is “cleaner” than the first?

Publish
The last step in the writing process is publishing your work. This step should not be overlooked because it is a valuable opportunity to receive feedback on your code and suggestions for improvement. Use GitHub or something like repl.it and share it, post it on your social media accounts. Consider all the feedback you receive when improving your code.
Finally, when you post your solution to Code Wars, you unlock the ability to see what other users have submitted. Studying these alternative solutions will give you a huge advantage in learning. Coders from all over the world are posting their solutions, and chances are, those solutions are nothing like yours. Compare and contrast those solutions and then experiment with new ideas. When you are happy with your final solution…. It’s time to choose your next challenge.
If you found this post helpful, please let me know.
Do you have another writing strategy that is effective? Share it in the comments below.
✉️ Subscribe to CodeBurst’s once-weekly Email Blast, 🐦 Follow CodeBurst on Twitter, view 🗺️ The 2018 Web Developer Roadmap, and 🕸️ Learn Full Stack Web Development.