Are you just starting to learn how to code? How exciting! And intimidating! No matter how long we've been in this business, we're always learning something new. The Gnar team discussed what basic advice we'd offer a developer at the beginning of the journey. Here's what we came up with.
- It will probably take you two weeks to somewhat understand what you're being taught today. Don't freak out if you don't get it right away.
- Read code every day. Just put your eyeballs on it, even if you don't understand it.
- Error messages are your friend. They aren't shaming you, they are helping you target something to fix. Get comfortable reading error messages and don't be discouraged when you get them; be excited that there's a (hopefully helpful) starting point for your debugging.
- Ask all of your questions, all of the time. If the answer doesn't make sense, it doesn't mean you were wrong for asking; it might mean that the question you had needs to be examined a little bit. Take the time to compare what you THINK you need to know, what the code is telling you, and what you're certain about. There may be information available to you that can lead you in a better direction. This is a skill that coders practice all the time, because we all feel lost on occasion. The trick is to find ways to feel confident that you do (or don't!) know something. That lets you learn it.
- Use your tools. There are so many things that have been built to help you figure out what's going on in your code, and learning how to manipulate them will make it easier to learn new things and crack harder problems. Figure out how to use Inspector consoles, debugger statements, linters, editor features, terminal tricks, helper libraries, and (eventually) tests. Each language has a slightly different approach to these tools, but ultimately the goal's always the same: making the work you do easier and more enjoyable by creating ways around obstacles.
- Try to build stuff on your own even if you think you're not very good yet. Exploring and practicing are the essence of being a dev. I've made so many different variations of to-do list apps just to keep me asking productive questions.
- A large web framework essentially takes a string input and returns a different string output. Seeing a simplified example makes it easier to not be so overwhelmed by the entire framework.
- When you get right down to it, code is simple. No magic, no elves, no wizards. Things are being compared, and the result of that comparison is either True or False. Learning to code is really about learning the basics of implementing these abstract flows in your mind, and then learning how to write and read them in code, in that order. This is why it is confusing: you have to conceptualize the solution in abstract logic, then work backwards to translate it into code. You may not be able to conceptualize how to build a pyramid, but at the end of the day it's a bunch of dried mud. I bet you can conceptualize dried mud.
- YOU CAN UNDERSTAND THIS. Just give it time.
How do I start reading code I did not write?#
Start from one thing the app does and follow it through the code, one call at a time. Pick a single page, find where its request enters the app, then read each method it calls until you reach the code that sends the answer back. Tools that jump from a name to its definition do most of the walking for you.
The list above says to read code every day. Here is one way to give each reading session a path. In a Rails app, it takes four steps.
- List the ways in. A route is a rule that sends a web address to the code that handles it. The
bin/rails routescommand lists every route, in the same order they appear inconfig/routes.rb. For each route, the Rails routing guide says you see its name if it has one, the HTTP verb (such as GET or POST) if the route does not respond to every verb, the URL pattern and the routing parameters. In development, the page/rails/info/routesshows the same list. - Open the action that one route names. A controller action is the method that handles one kind of request. In the guide's own table,
GET /photos/:idmaps tophotos#show: theshowaction of thePhotosController, which displays a specific photo. Open that action and read it top to bottom. - Follow each call to its definition. With GitHub's code navigation, you can jump to a function or method's definition in the same repository by clicking the call in a file. The same click can also find every reference to it.
- Scan the file's outline. GitHub's symbols pane lists symbols such as the functions and classes in your code. You can search for one in a single file or in every file in the repository.
That is one route. Tomorrow, pick another.
How do I read an error message?#
In JavaScript, read it in three parts, in order: the error type, the message and the stack trace. The error type names the kind of problem. The message says what went wrong. A stack trace is the list of function calls that were running when the error happened, one call per line. MDN's page on Error.stack says the call that directly caused the error is at the top.
The list above calls error messages your friend. Here is one, read line by line. This file, greet.js, passes an empty object to a function that expects a user with a name:
function greet(user) {
return user.name.toUpperCase();
}
greet({});Running it in Node.js 22.22.1 prints the error below. This is the part of the output that starts at the error, with the folder path cut from each file name. Node prints more lines after these.
TypeError: Cannot read properties of undefined (reading 'toUpperCase')
at greet (greet.js:2:20)
at Object.<anonymous> (greet.js:5:1)
at Module._compile (node:internal/modules/cjs/loader:1705:14)- The error type:
TypeError. MDN's page on this TypeError says: "There was an unexpected type. This occurs oftentimes with undefined or null values." Firefox and Safari word the same error differently, and MDN lists their versions too. - The message. "Cannot read properties of undefined (reading 'toUpperCase')" means the code tried to read
toUpperCasefrom a value that was undefined. On line 2, that value isuser.name. The object passed in has no name. - The top line of the stack trace.
at greet (greet.js:2:20)gives the function, the file, line 2 and column 20. That is where the error happened. - The next line down.
greet.js:5:1is line 5, the call that passed in the empty object. The lines after it point into Node's own files, which start withnode:. You did not write those, so skip them.
MDN's fix for this error is to test whether the value is undefined or null before you use it. That stops the crash. It does not tell you why the user had no name, and that is the question to chase next.
Ruby errors carry the same parts in a different order. Here is the same mistake in Ruby:
class Greeter
def greet(user)
user.name.upcase
end
end
Greeter.new.greet(nil)Ruby 4.0 prints this:
greet.rb:3:in 'Greeter#greet': undefined method 'name' for nil (NoMethodError)
user.name.upcase
^^^^^
from greet.rb:7:in '<main>'The first line gives the file and line (greet.rb:3), the method (Greeter#greet), what went wrong, and the error class at the end. The carets point at .name, the call that failed. The from line is the call on line 7 that passed in nil. The Ruby docs say Ruby raises NoMethodError "when a method is called on a receiver which doesn’t have it defined and also fails to respond with method_missing". Here the receiver is nil.
How do I ask a coding question someone can answer?#
Write it so someone can see your problem without seeing your screen. Say what you expected, what happened instead, the exact error text, and the smallest piece of code that shows the problem. Stack Overflow's help pages, How do I ask a good question? and How to create a Minimal, Reproducible Example, set out steps like these.
The list above says to ask all of your questions, all of the time. Here is one question written down, for the greet.js case. It follows three items from two Stack Overflow help pages.
- Write a title that sums up the specific problem in one sentence. Include the error message.
- Do not stop at "it doesn't work." Say what you expected to happen, the exact wording of the error, and which line of code produces it.
- Cut the code down to a minimal reproducible example: the smallest code that still shows the problem. Stack Overflow's guide to a minimal, reproducible example asks for code that is minimal, complete and reproducible. To shrink it, remove code a bit at a time until the problem disappears, then add the last part back.
Here those items are filled in for the greet.js case, with the expected value taken from a Node.js 22.22.1 run of the same function on a correct call, greet({ name: "ada" }):
- Title: TypeError: Cannot read properties of undefined (reading 'toUpperCase') in greet.js
- What I expected: greet to return the name in capitals, as
greet({ name: "ada" })returnsADA.greet({})has no name to return. - What happened: TypeError: Cannot read properties of undefined (reading 'toUpperCase'), at greet (greet.js:2:20). Line 2 of greet.js is the line that produces it.
- Code: the greet function and the
greet({})call from greet.js above.
Which debugging tools should a new developer learn first?#
Start with the first three tools the list above names: the console, the debugger and the linter. The console shows the messages your code logged. The debugger pauses your code at a breakpoint, a spot you choose, so you can see the value of each variable in scope at that moment. A linter reports patterns in your code, to make it more consistent and avoid bugs.
| Tool | What it shows | First thing to try |
|---|---|---|
| Console | Messages your code logged | Log a value to check the order code runs in |
| Breakpoint | Each variable's value at the pause | Click a line number in Sources |
| Ruby debugger | A debugging session in your paused Rails app | Put debugger in a controller action |
| ESLint | Patterns it finds in JavaScript code | Set it up, then run it on one file |
The Chrome DevTools Console has two main uses: viewing logged messages and running JavaScript. Developers log messages to make sure code runs in the right order, and to check a variable's value at a certain moment.
A breakpoint pauses your code in the middle of running. In JavaScript, the debugger statement calls any available debugging tool, such as a breakpoint. If none is available, it has no effect.
In Ruby, the Rails debugging guide says: "Rails 7 includes the debug gem in the Gemfile of new applications generated by CRuby." CRuby is the standard version of Ruby. Put debugger in a controller action, and the app opens a debugging session when it reaches that line. There you can type p and a variable name to see its value.
ESLint is a linter for JavaScript. Its getting started guide calls it a tool for identifying and reporting on patterns in JavaScript code, to make code more consistent and avoid bugs. After you set it up with npm init @eslint/config, it can run on any file or folder.
To try a breakpoint in Chrome, follow these steps from Chrome's Debug JavaScript tutorial:
- Open DevTools and go to the Sources panel. Open your file and click a line number to set a line-of-code breakpoint.
- Repeat the action that runs that line. When the code pauses, click Step into next function call to move through it one line at a time. Click Step over next function call to run a function without going inside it.
- Read the Scope tab for the value of each variable at that moment. To follow one value over time, add it to the Watch tab.
To see the same cause in Node.js, add a debugger statement above the line that calls toUpperCase and run node inspect greet.js. Type cont to run to that line, then exec user: Node prints {}, an empty object, so user.name is undefined.
How does a Ruby framework take a request and return a response?#
In a Ruby app on Rack, which Rails uses, a request comes in as one environment and a response goes out as three things: a status, headers and a body. Rack's README says that by wrapping HTTP requests and responses in the simplest way possible, "it unifies and distills the bridge between web servers, web frameworks, and web application into a single method call."
The list above puts a web framework in one line: a string in, a different string out. Here is the example app from the Rack README, a file named config.ru:
run do |env|
[200, {}, ["Hello World"]]
endenv is the environment, which represents the HTTP request. The Rack spec says an app takes exactly one argument, the environment. It returns an array of exactly three elements, which represent the HTTP response. Here they are the status (200), the headers ({}, empty here) and the body (["Hello World"]). The Rails on Rack guide says that when a request is made, the Rack-compliant web server parses it to create the env hash and calls the app with it.
The README runs it with the rackup gem. Rails sits on the same interface. The Rails on Rack guide calls Rails.application "the primary Rack application object of a Rails application." To see it in your own app, run bin/rails middleware. The guide says it shows the middleware stack, and its example from a freshly generated app is a list of use lines such as Rack::Runtime and Rack::ETag, ending with run MyApp::Application.routes.
What is The Gnar Company?#
The Gnar Company has built custom software since 2015 with a team of senior US-based engineers. Its case studies name the client, including WHOOP, Fitbit and the AARP Foundation. You can read them on Gnar’s Our Work page. The Gnar Company is rated 4.8 on Clutch, where its clients leave reviews.
The Gnar Company’s three services are Application modernization, AI transformation and Product engineering.
Contributors#
Learn more about The Gnar and our team.


