Hardog's blog

trace forever

Group: 572218159
Email: 1273203953@qq.com
Location: hangzhou·zhejiang
GitHub: https://github.com/hardog

原文链接: I know how to program, but I do not know what to program

编程新手知道如何编程却往往不知道通过什么途径以及方式来达到锻炼自己的目的, 文中给出几点建议:给开源项目做贡献、做个简单的游戏、按照自己的方式去重复造个轮子. 编程是个创造性活动, 编程中需要经常实践与创造性结合!

There is a recurring theme I see with novice developers. They’ve put in their time to learn the basics of a programming language or two and they feel pretty comfortable doing programming exercises, but they don’t know how to apply what they’ve learned. It usually comes in a phrase similar to “I know how to program, but I don’t know what to program.” The responses are typically “do programming challenges”, “contribute to an open source project”, or “make a game.”

Doing programming challenges is good mental practice, but they do little to help someone learn how to create a new program. Contributing to an open source project is a step up. You might learn about how a real project is structured and improve your skill with the programming language, but won’t learn much about the full lifecycle of a project. Some projects are very complex too which can be intimidating for a novice. Making a game is another step up. Games are fun! I started by programming games in QBASIC. The same dilemma arises though. “I want to make a game, but I don’t know what to make.”

As someone who teaches music students as well as programming, I have recognized the same pattern with music students. “I know all the chords, and my hands feel comfortable, but I don’t know how to write a song.” With music, we actually have a good answer. There is a path for learning to create. Musicians don’t typically just start writing their own music from the beginning. Some musicians never progress to composing music and spend their whole life only playing music from other people. In the programming world, the attitude is a little different though.

In the software community the general attitude is “don’t reinvent the wheel.” It’s almost frowned upon if you rewrite a library when a mature and stable option exists. While it is a good rule in general, novices should not be afraid to reinvent the wheel. When it is done for learning or practice, it’s totally OK to make a wheel! It is an important part of learning. For example, write your own version of ls, mv, wget, or cowsay. If you want to go the game route then make clones of Pong, Tetris or Space Invaders. They don’t need all the same features or have to be exact replicas, but you start with your goal and a blank slate, and you make it happen.

Don’t get the notion that you need to have the best idea ever before you write a program either. I’ve seen the same mentality with musicians. Trying to create a masterpiece on their first attempt, putting all their energy in to one song and not seeing a bigger picture. The bigger picture being, you will write LOTS of songs over time, not just one! The first song you write will probably be bad and you will probably toss it. That’s OK! Don’t try to want to write the most epic 10 minute blow-your-face-off legendary piece of music on your first attempt. You need to learn the process of songwriting, learn from your own experience, and put in the hours every week practicing. You’re going to write bad programs before you write good ones. Get over it, get through it, and get the experience so you can start to improvise on demand in any key.

There is a reason we tell people to start with a “Hello, world.” Because at that point in their journey, accomplishing that means that have conquered a certain number of fundamentals. You understand how to compile, how to run, how to call a function and pass it parameters. Writing a clone of an existing program is another big step, almost as important as the hello world step, only at a different stage of your journey. When you are done with it, you have overcome certain challenges. You had to figure out where to start, how to plan it, how to organize it, how to deal with the bugs, give it a personal touch, and package it up at the end so it is a usable thing. Even when cloning a simple program, you are learning all of the process.

You might be wondering how cloning existing programs will help you come up with new ideas though. Well, like music, it requires creativity. With music, how does playing someone else’s song help you learn to write your own music? Well, you have to understand how other people do it first. You have to understand how they structure things and what patterns they use. After you’ve done this enough times you start to see the bigger picture and then you have a wealth of knowledge to draw upon. You put together little pieces you learned from different places and re-use some of the patterns you saw. You might tweak the patterns, combine them, or break them completely. As they say, you need to learn the rules in order to break them. In programming we have common patterns like MVC. That is one stable and accepted pattern for writing software. In music, we have common progressions. For example I-V-vi-IV. Of course that’s not the only one, but it’s a good one to know!

In short, it’s a combination of experience and creativity. Creativity is an aspect people often overlook in programming, but it is crucial. Have you ever noticed how many programmers are also musicians? Music involves a lot of technical analysis, structure, and patterns although many people consider it a purely creative endeavor. Programming is often seen as a strictly technical act although it is mostly a creative endeavor. You can foster creativity by cloning programs. As you make them, you will find yourself thinking of new ways to tweak the program or maybe even a personal feature to add. It will also inspire ideas for totally new projects. The creativity comes out along the way, but you need to learn to play some cover songs first.

Over time, you’ll see how you can apply programming to almost everything. You can automate tasks and tackle practical problems. You’ll have no problem coming up with a big long list of things you’d like to make but won’t have time for. You’ll also be able to solve problems on the fly. “Oh, there’s an Excel spreadsheet with 100 sheets that needs to be reformatted, split in to separate files, and converted to a csv? Coming right up!” Don’t get hung up on trying to come up with the next best thing. Write programs that you will use. The ideas for other projects will come along the way.

How many of you have been in the situation where you think “I don’t know what to program?” How did you handle it? What advice would you give to others in that situation?