# Chill & Learn: How To Begin Thinking Like A Programmer

Hello Fellow Codenewbies 👋,

I want to write something different.
<br>
Once in a while, I will post my notes and/or summaries about various talks that I find interesting to share with you. 
<br>
I am calling this series of articles "Chill & Learn", where I learn something new while chilling on my couch 😄. 
<br>
I want to have some fun writing this series. So the format would be in my favorite way in taking notes: *Bullet points*! 🤩
<br>
I hope you enjoy it 😊.

---

**Title**: [How to Begin Thinking Like a Programmer](https://www.youtube.com/watch?v=azcrPFhaY9k)
<br>
**Speaker**: [Andy Harris](https://www.youtube.com/channel/UCIhnHoRkoJmkWwLz2jBpgNQ)
<br>
**Duration**: 1 hour
<br>
**Ayu's comment**:
<br>
This is a 1-hour talk that doesn't feel long. I really enjoy listening to this talk and I wish I found it in my early stage of programming learning! 
<br>
The speaker, Andy, is very funny and energetic. As this was a talk for [IndyPy](https://indypy.org/), he used Python as examples for his codes. But it doesn't matter because this talk is explaining programming in general. If you have time, I recommend you to watch the video. If you don't, you can read my notes below 😊.

---

## Opening

- Programmers are getting *greater*, not *smarter*.
- Programming is hard, but teaching is harder!

## Learning to program is hard

Doesn't matter what their level is, people still think that programming is hard. Why?
  - Programming feels different than other skills.
  - The language is scary.
  - The environments (IDE's) are scary.
<br>
      How long would it take you to set up the environment before you start to write your code?
  - The people can be scary.
<br>
      You have to be able to speak jargon and show what you learn.
  - Most beginners failed a lot.
<br>
      When they are stuck and feel not good, they tend to not go back. 
  - Good programmers aren't always good teachers.

## Bad beginner advice

- Just start with a simple game (like Tetris!)
- Start with C++ because that's what they use in the industry.
- If you use [Visual Basic](https://docs.microsoft.com/en-us/dotnet/visual-basic/), you don't have to code until the end.
- The best way to start is to pick a problem you want to solve.
  <br>
  What if the problem that you want to solve is world peace?
- You'll stay motivated if you work on a real-world problem.
  <br>
  Hard fact: real-world is messy.

## What Andy wishes he'd been taught as a beginner

- Programming isn't about languages because it ultimately doesn't matter much. 
- There's not a lot of memorizing.
  <br>
  No one remembers all syntax.
- Most programming isn't about math.
<br>
  The kind of thinking you're doing in programming is the kind of thinking math to teach you in the first place.
- Programming languages are simpler than human ones.
<br>
  There are about 100 vocabularies in programming, while humans have much more. And programming vocabularies are designed to be sensible, not flexible.
- Programming is really about solving problems.

## Code isn't about language

- Coding is about concepts.
- They work in almost the same way in every language.
- Learn how to use these concepts in human language because the secret is not code, but algorithms.
- Write out the concepts first, then convert to code later.
<br>
  If you are lost in coding, perhaps you shouldn't write the codes yet.
- Most beginners think they don't understand what code to write.
<br>
  The real problem is they don't really understand the problem. They're trying to solve and jump straight to code.
- Comments explain code to other programmers... WRONG! 
<br>
  👉 Code explains the comments to the computer.

## First 3 main concepts (out of 7 or 8) in programming

### 1. Variable
- **Name**: what do we call this thing?
- **Type**: what type of data does it contain?
- **initVal**: what is its starting value?

#### 🧠 Variable algorithm

Create a variable called **name** of type **type** that starts with the value **initVal**.

```python
name = initVal
```

### 2. Output
- **message**: text to write to the user.

#### 🧠 Output algorithm

Output the text **message**.

```python
print('message')
```

### 3. Input
- **variable**: where answer from the user will be stored?
- **message**: the question being asked of the user.

#### 🧠 Input algorithm
Ask the user **message**  and store the answer in a **variable**.

```python
variable = input('message')
```

**Notes**:
<br>
Input should *never be the first one in your algorithm* because it has prerequisites.
<br>
You cannot just ask for answers like, "Tell me the answer."
<br>
You should also give questions like, "Is the temperature cold? Or hot? Tell me the answer. "

## Practicing algorithm & code

### Create algorithm as comments

```python
# create an integer variable for x
# create an integer variable for y
# create an integer variable for sum
# ask the user "X: " and put answer in x
# ask the user "Y: " and put answer in y
# put x + y in sum
# tell user "answer is " sum
```

### Flesh out the comments

```python
# create an integer variable for x
x = 0
# create an integer variable for y
y = 0
# create an integer variable for sum
sum = 0

# ask the user "X: " and put answer in x
x = input("X: ")
# ask the user "Y: " and put answer in y
y = input("Y: ")

# put x + y in sum
sum = x + y

# tell user "answer is " sum
print("Answer is ")
print(sum)
```

### Test it!
```text
X: 3
Y: 5
Answer is 
35
```
![why gif](https://media.giphy.com/media/l2JhtKtDWYNKdRpoA/giphy.gif)

### Failure is WONDERFUL!
It's the opportunity for you to grow and let's have a good attitude about that.

- A normal part of programming.
- Begin debugging now:
  - Did you tell the program what to do incorrectly? 
  - Or did you tell the program to do the wrong thing?

Most beginners assume the code is wrong or there is an implementation problem. But usually, it's an algorithm/understanding problem.

### How to debug
- The best way is to not have bugs 😆.
- Bad implementation can be googled.
- Bad algorithms usually cannot be googled.
- What are you not understanding?
- What tools can you use to test?
- DON'T start with a solution because you will mess up.
<br>
  Assumptions usually are a big part of the reason we don't understand things.
- Start by truly understanding the problem.

### What happened in that code?
- It's easy to assume the "+" sign is broken.
<br>
  But that's not really the problem.
- Try `print("python" + "meetup")`. 
- So, we can add text/string.
- I wonder if it thinks "2" and "3" are text/string?
- Lookup for a tool to find out.
<br>
  We can use the type function to test!

### Let's try again!

#### Convert to integer
- **oldVariable**: in a non-integer format.
- **intVariable**: integer to hold results.

#### 🧠 Convert to integer algorithm

convert **oldVariable** to integer and store in **intVariable**.

```python
intVariable = int(oldVariable)
```

### Hold your breath!

```python
# create an integer variable for x
x = 0
# create an integer variable for y
y = 0
# create an integer variable for sum
sum = 0

# ask the user "X: " and put answer in x
x = input("X: ")
# ask the user "Y: " and put answer in y
y = input("Y: ")

# convert x to integer
x = int(x)
# convert y to integer
y = int(y)

# put x + y in sum
sum = x + y

#tell user "answer is " sum
print("Answer is ")
print(sum)
```

### Test it (again)!
```text
X: 3
Y: 5
Answer is 
8
```
![victory gif](https://media.giphy.com/media/lnlAifQdenMxW/giphy.gif)

## Key Takeaway
- The secret about programming is not code, but algorithm/understanding.
- Write algorithms in comments to understand and solve a problem. Then translate them into code. 
- When you encounter new problems, you develop a new algorithm tool to get there. And you're growing!

See you with another talk and topic in "Chill & Learn" next time! 👋

---

Thank you for reading!
<br>
Last but not least, you can find me on [Twitter](https://twitter.com/AdiatiAyu). Let's connect! 😊

