# How to learn to code from scratch

You can teach yourself programming without a technical degree if you write code with your own hands from the first week instead of only watching lessons. Below is how to choose a first language, what to install, which order to take topics in and how to tell that you are really making progress.

## Which language to choose first

Your first language affects your path less than it seems: variables, loops and
functions work much the same everywhere, and a second language takes a fraction
of the time the first one did. Choose by what you want to be doing in a year:

* websites and interfaces in the browser — JavaScript together with HTML and CSS;
* automation, data analysis, machine learning — Python;
* large server systems, banking and enterprise projects — Java;
* no goal yet — Python: its syntax is simple and there is little boilerplate.

Do not switch languages in the first three months. Difficulties at this stage
almost always come from programming itself, not from the language you picked.
Each of these directions has its own plan:
[Python](https://skillok.org/topics/learn-python-from-scratch),
[JavaScript](https://skillok.org/topics/learn-javascript-from-scratch),
[Java](https://skillok.org/topics/learn-java-from-scratch).

## Your workspace in one evening

You need three things: the language's interpreter or compiler, a code editor and
a terminal. For Python that means the installer from python.org and an editor
such as VS Code. Check that everything works with the shortest possible program:

```python
name = input("What is your name? ")
print("Hello,", name)
```

Install Git right away and create a repository for your practice code. Each
solved task is a commit with a clear message. In a month you will have a history
that shows how you progressed, and later it becomes the base for a portfolio.

## The order of topics for the first three months

Take topics strictly one at a time and do not move on until you have solved
several tasks on your own:

1. Variables, types, input and output, arithmetic.
2. Conditions: `if`, comparisons, logical operators.
3. Loops: going over numbers and strings, accumulating a sum.
4. Functions: parameters, return values, scope.
5. Lists and dictionaries: searching, filtering, counting.
6. Working with files and handling errors.

After each topic, solve five to ten tasks on a site with automatic checking. A
task counts only if you wrote it without hints; if you peeked at the solution,
come back to it three days later and solve it again.

## First projects: small and finished

A project teaches what tasks do not: splitting work into parts, reading error
messages, finding answers in the documentation. Start with programs of 100–300
lines:

* guess the number, with an attempt counter and a high-score table in a file;
* an expense tracker: enter spending, total it by category, save to CSV;
* renaming a hundred files in a folder by a pattern;
* a console to-do list where you add, delete and mark items as done.

Every project should have a README: what the program does, how to run it, an
example of it working. Interviewers notice this habit immediately.

## How to check yourself without a mentor

Automatic checks on practice sites answer the question "does the code work". The
rest you check yourself:

* Write tests for your functions — at least three checks: a normal case, empty
  input and a boundary value.
* Reread your code a week later: if you cannot understand it at a glance, rename
  the variables and split long functions.
* Post a project for open code review — developer communities are happy to look
  at beginners' code.
* Explain your solution out loud as if to a colleague. The place where you
  stumble is what you have not understood yet.

## Common beginner mistakes

Watching video lessons for hours without writing code. Copying solutions just to
"close" a task. Starting a game or a social network in the first month.
Abandoning a project halfway. Being afraid of error messages instead of reading
them: the error text usually names the file, the line and the cause.

## Step-by-step plan

1. **Week 1 — language and setup** — Choose a language by your goal, install the interpreter, an editor and Git, run your first program.
2. **Weeks 2–6 — the basics** — Variables, conditions, loops, functions; 5–10 auto-checked tasks per topic.
3. **Weeks 7–10 — data structures and files** — Lists, dictionaries, reading and writing files, handling errors.
4. **Weeks 11–14 — two finished projects** — Programs of 100–300 lines with a README and tests in your own repository.
5. **Next — a direction** — Choose a specialisation — web, data, backend — and make a plan for the next three months.

## Check yourself

1. What does this Python code print: print(7 // 2)
   - 3
   - 3.5
   - 4
2. What is x after this Python code runs: x = 5, then x = x * 2 + 1?
3. What does this Python code print: print(len("hello"))
   - 4
   - 5
   - 6

## Sources

- [The Python Tutorial](https://docs.python.org/3/tutorial/) — The language basics from the authors of Python, free
- [Pro Git](https://git-scm.com/book/en/v2) — A free book on Git, from the first steps to branches
- [freeCodeCamp](https://www.freecodecamp.org/) — Free programming courses with exercises checked automatically
- [CS50x](https://cs50.harvard.edu/x/) — Harvard's free introduction to computer science

---

https://skillok.org/articles/en/learn-to-code-from-scratch
