CodeNewbie Community 🌱

Cover image for Chill & Learn: How To Begin Thinking Like A Programmer
Ayu Adiati
Ayu Adiati

Posted on • Originally published at adiati.com

Chill & Learn: How To Begin Thinking Like A Programmer

Hello Fellow Codenewbies 👋,

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


Title: How to Begin Thinking Like a Programmer
Speaker: Andy Harris
Duration: 1 hour
Ayu's comment:
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!
The speaker, Andy, is very funny and energetic. As this was a talk for IndyPy, 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.

    How long would it take you to set up the environment before you start to write your code?

  • The people can be scary.

    You have to be able to speak jargon and show what you learn.

  • Most beginners failed a lot.

    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, you don't have to code until the end.
  • The best way to start is to pick a problem you want to solve.

    What if the problem that you want to solve is world peace?

  • You'll stay motivated if you work on a real-world problem.

    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.

    No one remembers all syntax.

  • Most programming isn't about math.

    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.

    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.

    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.

    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!

    👉 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.

name = initVal
Enter fullscreen mode Exit fullscreen mode

2. Output

  • message: text to write to the user.

🧠 Output algorithm

Output the text message.

print('message')
Enter fullscreen mode Exit fullscreen mode

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.

variable = input('message')
Enter fullscreen mode Exit fullscreen mode

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

Practicing algorithm & code

Create algorithm as comments

# 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
Enter fullscreen mode Exit fullscreen mode

Flesh out the comments

# 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)
Enter fullscreen mode Exit fullscreen mode

Test it!

X: 3
Y: 5
Answer is 
35
Enter fullscreen mode Exit fullscreen mode

why 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.

    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.

    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.

    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.

intVariable = int(oldVariable)
Enter fullscreen mode Exit fullscreen mode

Hold your breath!

# 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)
Enter fullscreen mode Exit fullscreen mode

Test it (again)!

X: 3
Y: 5
Answer is 
8
Enter fullscreen mode Exit fullscreen mode

victory 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!
Last but not least, you can find me on Twitter. Let's connect! 😊

Top comments (0)