Top 10 Things Every Developer Should Know (Part 1)
Ten core ideas every developer should know: Git, reading error messages, Big O notation, recursion, HTTP, SQL injection, debugging, testing, floating point math and readable code. Part 1 of the series.
The 10 things, explained
- Version control
git commit -m "small, clear change"
Use version control for everything, even tiny projects. Git lets you go back in time, try ideas on a branch, and see exactly what changed. Commit small changes often, with messages your future self can understand. - Read the error message
TypeError: x is undefined (line 42)
Read the whole error message before you search for it. It usually tells you what went wrong, in which file, and on which line. The stack trace shows the path the program took to get there. - Big O notation
O(1) < O(log n) < O(n) < O(n squared)
Big O notation describes how your code slows down as the data grows. A loop inside a loop is fine for ten items, but with a million items it can take hours. Think about growth, not just today's test data. - Recursion
f(n) = n * f(n - 1) until n = 1
Recursion is a function that calls itself on a smaller piece of the problem. Every recursive function needs a base case, the point where it stops. Forget the base case and the program runs until the stack overflows. - How the web works
GET /page -> 200 OK
Every web page starts with a request and a response. Your browser asks a server for a page over HTTP, and the server answers with a status code and some data. Two hundred means OK, four oh four means not found. - Never trust user input
WHERE email = ? (parameterized)
Never trust input from users, forms or other systems. Pasting input straight into a database query opens the door to SQL injection. Use parameterized queries and validate everything on the server. - Debug like a scientist
guess -> test -> narrow it down
Debugging is the scientific method. Make a guess, test it, and cut the problem in half until the bug has nowhere to hide. Explaining the code out loud, even to a rubber duck, often reveals the mistake. - Write tests
assert add(2, 2) == 4
Automated tests let you change code without fear. A good test is small, fast, and checks one behavior. When you fix a bug, first write a test that fails, then make it pass. - Floating point math
0.1 + 0.2 = 0.30000000000000004
Computers store most decimal numbers as approximations. In many languages, zero point one plus zero point two is not exactly zero point three. For money, use whole cents or a decimal type. - Code is read more than written
totalPrice beats tp
Code is read far more often than it is written. Clear names, short functions and simple logic save hours for the next person, and that person is often you. Clever code is fun to write and painful to maintain.
Chapters
0:00 Intro
0:10 1. Version control
0:26 2. Read the error message
0:40 3. Big O notation
0:56 4. Recursion
1:11 5. How the web works
1:28 6. Never trust user input
1:45 7. Debug like a scientist
2:00 8. Write tests
2:14 9. Floating point math
2:29 10. Code is read more than written