Looking at others code

Is it bad looking at other people code?

it depends.
I look at and reference other peoples code all the time through Google and other resources. I do not use it until I understand what it is doing and why.


Thank you very much sir

it depends

if you copy a solution to freecodecamp exercises in order to understand it later then you lose out on the main benefit of the exercises which is to give beginners an opportunity to gradually develop problem-solving skills

if you look at code that is somehow better than your solution you miss out on practicing iterative development which is to quickly get a working solution first then review and identify or measure areas of improvement - then actually make small incremental enhancements

What is your motivation or need to look at someone else’s code?

No need just wondering in case I can learn it from them and apply it to my own code

I feel developing problem-solving skills is essential and way more important for someone learning to program than copying coding techniques from other people

I understand and I totally respect your opinion bro

I think that looking at somebody else’s code might point you to right direction or show you how to solve problem more elegant (it depends of course). Stealing the code is not good, but learning on it is OK :slight_smile:
It’s my opinion


Yes, read other people’s code all the time, particularly if it’s good code. Read it to see how something is done that you’re stuck on, or different ways to do something that you wouldn’t have thought of. You do need to figure out how it works and why it works, not just copy blindly. You can do all the tutorials and practice exercises and toy projects you want, but you need to see how other people have solved problems. In particular, the thing most exercises don’t or can’t teach is how to structure code for real-world projects.

A large chunk of any dev job involves understanding other peoples’ code (writing code is normally done less often, sometimes much less often, and is generally the easier part), get used to doing it now.

Eg, I’ve been a JS Dev for years now, the things I think that taught me more than any book, tutorial or exercise were the source code to underscore:


The source code to its child project, underscore-contrib:

The source code to Backbone:


Both of those projects have been superceded now (Underscore by Lodash, Backbone by different frameworks like React and Angular), but the code is really good. The functions Underscore provide make most of the FCC algorithm exercises trivial; in a sense I have “cheated” on them by learning how to write, say, a useful range function, by reading that source code, then applying that knowledge 5-6 years later when doing the FCC exercises. Similarly I could say I “cheated” when I learned how to use generators in JS: the way I learned how to use them was to copy code verbatim from Python’s Itertools library and translate it to JS: I don’t know Python at all well, but this allowed me to use Python tutorials to learn the JS version - at the time I wanted to learn to use generators, they were a new feature in JS, so there were few resources, whereas they’d been around for a long while in Python.

As an example, there is a challenge “Falsely Bouncer” in the FCC algorithms section. Many languages provide a function/method for lists/arrays, normally called compact, which does exactly what the challenge asks for. Underscore has an implementation of compact:

//Trim out all falsy values from an array.
 _.compact = function(array) {
   return _.filter(array, _.identity);

Which, when you dig through the code, is the same as:

var identity = function(x) {
  return x;

var compact = function(array) {
   return array.filter(identity);

Which is the same as

function compact(arr) {
  return arr.filter(x => x);

Which if I change the name of the function, is a possible answer for the falsey bouncer problem. Putting myself in the position of a learner, I still need to understand why it works. But now, I can ask “I have this function which works, it removes the falsey values. Why does it work?” That is a good question which, for someone who understands coercion in JS is very easy to answer well.


Thanks Dan. I’m new to coding and you have made me comfortable with using solutions to learn from. Roger