Learn To Code By Breaking Someone Else’s Code

Learn To Code By Breaking Someone Else’s Code

One of the best techniques when learning to code is to reverse-engineer existing code. Code training company Treehouse explains how to “break” code to better understand how it works.

Photo by hackNY.

Nick Pettit gives an example on the Treehouse blog of wanting to learn about 3D programming in the browser and testing a line of a Javascript script, Three.js:

The following is a code example that uses three.js to create a light:


var light = new THREE.PointLight(0xffffff);
light.position.set(-100,200,100);
scene.add(light);

If you have some programming experience, you might be able to read this and figure out most of what’s happening here. If there are any blanks or assumptions you’re unsure about, you can test them with the following techniques:

  1. Delete one line at a time to see if it’s necessary for your goals.
  2. Delete one line at a time to better understand its function. Even if you think you know what a line does, try deleting it anyway to test your assumptions.
  3. Change variables and function arguments to see if you can manipulate them in a way that matches your mental model.
  4. Swap the order of various lines to see if things can be done “out of order” or if there’s some significance to the sequence of operations.

As you test each line, you’ll start to build a mental model and make corrections to other assumptions you made previously. Soon, the whole picture will start to make sense.

The key is to break one thing at a time and see what changes so you can understand the relationship between all the parts in the code.

Self-taught programmers may already know the great value of reverse engineering others’ code, but as Treehouse points out, this strategy doesn’t get enough emphasis. Thanks to generously shared open source code, you can learn just about anything by breaking it.

The Secret to Learning to Code [Treehouse Blog]


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments


2 responses to “Learn To Code By Breaking Someone Else’s Code”