DEV Community

João Vítor Monteiro
João Vítor Monteiro

Posted on

Programming for Beginners: The Real 101

# Introduction

Hi there, how are you doing?
If you reading this, you have voided your warranty, please contact customer support.

Wait. Wrong article. Sorry, let me start again.

Hi there, how are you doing?
If you're reading this, you probably never wrote a computer program, or have wrote one computer program.
Or, as we usually say, programs == 0 || programs == 1.

In any case, now you want to write computer programs, or you just want to read an article about programming and have an intense need for nostalgia in your life. Whichever it is, let's get started!

# Background

At college, we had a teacher that was famous for mockingly asking if his students "knew how to program".
I'll be honest: I don't. There. Said it. But I've got something else: I understand how computers work and can talk to them. Sort of.

But there was a time when I didn't. I was around 14 when I wrote my first program. You can probably guess what it is: Hello World.

It was in Java. I copy-pasted it in a Notepad then ran the javac command in the CMD like they tell you to and then... it threw an error. I tried running it again: it still didn't work (dev rule #1: try running again).

I closed the CMD, told myself that I wasn't smart enough and that coding wasn't for me and went back to playing my guitar.

But now I'm here, sharing what I know. And now I know that programming is hard when you don't know what to know. Even when you know what to know, it's still hard. But it can be easy, it can be better.

Does the onboarding experience to programming really have to be "paste this in a file and run it. congratulations, you have learned how to program"?

I promise I'll try to keep it short.
Try.

# Why?

Ryan Reynolds asking "But Why?"
The approach to learning how to program is usually harsh. When you're just starting out, people will tell you:

"go learn Python/HTML/CSS/JavaScript/C, they're really easy to learn".

In my opinion, this is as useful as telling a newborn:

"JUST STAND UP AND MOVE YOUR LEGS!! IT'S, LIKE, BASIC!!" (no pun intended).

Sure, you can declare a variable, write a for loop, maybe classify species of Iris flowers. But what good does this do for you?

There are three questions you must always keep in mind when programming:

  • Why: you're gonna spend a lot of time doing it, so make sure you're motivated (a.k.a have a reason to). It can be for fun, to get a job, to brag to your friends, to mod your favorite game, to cure diseases, etc.

  • What: understand the context of what you're trying to achieve. If learning for fun, what fun things do you want to build? If to get a job, what language will you choose and how's the job market for it? If to brag, why do you even? If modding, how do other modders do it? If to cure diseases, how can a computer help?

  • How: what are the steps for solving the problem you choose. For example, if you want to make a mod that sends a tweet everytime a player character levels up, what would be the steps (algorithm) to do it? Spoiler: you'd need to get that information from the game, process it and send it to Twitter. That, in turn, would raise questions like: "how do I get that information" or "how do I send it to Twitter?". All of us devs have to do this process. That's what programming is about. Also, Googling basic stuff.


# What?

Dog saying "What?", even though dogs don't speak English


# The Context

Let's do some storytelling!

Your name is Alice (congratulations if your name is actually Alice). You're an assistant at a company that sells post-its. In this company, there are three departments:

  • Sales: they sell the post-its to customers. You don't like talking to them because they spit while talking. Gross.
  • Customer Support: they handle customer issues. It's almost impossible to talk to them as they're always busy on the phone with a yelling customer.
  • Production: they print and pack the post-its. They think they own the company (spoiler: they don't, they just work there, same as you).

# The Crisis

Everyday your boss, Bob, tells you:

Alice, I need to know three things:

  • how many post-its Sales sold yesterday;
  • how many complaints Customer Support received and solved yesterday;
  • and how many post-its Production put in stock.

And everyday, you silently cry for 5-10 minutes in the bathroom while smoking (average time to finish a cigarrete/questioning the value of your job/both at the same time 'cause you're efficient).

Afterwards, you spend 1 hour getting spit on in a meeting with Sales; 30 minutes waiting for someone in CS to notice you; and 45 minutes listening to Production's Lead blabber about how amazing he is (spoiler: he's a douche).

During these 5-10 minutes, you wonder how it would be if you didn't have to go through this. What if your boss asked them himself? Or maybe they could report it directly. What if you quit and got another job?


# The Hope

"But... what if... IF... HYPOTETICALLY SPEAKING ABOUT A HYPOTETICAL HYPOTESIS... What if this wasn't necessary? What if this process was... automated? What if there was an automata, or a robot, that could do this work for me EVERYDAY?"

Dream job, am I right? Well dear Alice, turns out there is! It's called a computer, you're using one right now to read this!

"But can it, like, do this? Like, ACTUALLY do this?"

Of course, as long as you tell it to. Which is the whole point in programming: how the f*** do I tell the computer to do this?


# How

William Dafoe desperately saying "Tell me How", you should help him quickly as he's quite disturbed

"OK Jo-"

I'm Charlie, forgot to tell you. My name's Charlie now.

"OK Charlie, then how the f*** do I tell the computer to do this? Can't you do it for me?"

First: write a program. Second: I can, but I don't work for free.


# What even are computers?

"Write a what?"

A P-R-O-G-R-A-M. You can think of computers as persons that only understand 2 things: 1's and 0's. A program is a sequence of 1's and 0's.

"I know that, I've watched Matrix, it's those floating green things on the background, right?
But if there are only 2 things it understands, how do they turn into other things like this website?"

Well, some people found a way to turn those 2 things into a set of instructions. They group the bits together and each group corresponds to an instruction, or as I like to call them, words.

Then they create central processing units that read and interpret these words. And like a dog that sits when it's told to sit, when the computer reads these words, it'll do ONE SPECIFIC THING and ONLY THAT THING.

This is what we call an Architecture. There are many ways to organize and process these words, you have 32-bit CPU, 64-bit CP-

"That's too much."

Sorry.

"But I don't see people writing words of 1's and 0's all the time. In those hacker movies, people are writing, like, ACTUAL words, you know?"

Well, some other people found a way to translate computer words into more human words. We call these programming languages, because they're, well, languages used to program computers.

So they write a bunch of words of a programming language in a sequence, sometimes indented (looking at you, Python), save it (always remember to save) and call it a program.

"Even HTML?"

Let's not do this, ok?
Anyway, these languages have grammars like any other languages such as English.
You learn the syntax (or just copy-paste from Google), write it in a document with the correct file extension, run the compiler/interpreter and then-

"DO WHAT NOW??"

When you want to communicate with someone, you say words, right? If you wanted to say hello to me, you'd say "Hello, Charlie". My brain would, in a split of a second, think: "this is English, what words do I know for English?"

Then it would think about the meaning of the sentence:

  • I know 'hello', it is a greeting.
  • I know that 'hello' can be followed by another word: a name.
  • 'Charlie' follows 'hello', therefore it is a name.
  • Charlie is my name.
  • Therefore, Alice is greeting me.

If you had told me "Gkgdfkgd, otrpr", I surely wouldn't get it, because I don't know what language that is, but maybe someone in (or out) of this planet does.

This is what a computer does, but instead of English, it's Python, for example. This is known as compilation, which is actually much more complex and can be used to transform any kind of text into another.

"But there's like a trillion programming languages..."

Yes. For that, people write compilers specific to a language. They compile that program's language to another, like machine (computer) language or Assembly or C or LISP.

"What?? Anyway, can I just write an English compiler that compiles to machine language?"

No one's stopping you, honey... But ask yourself why programming languages exist.


# And programs are...?

"That was rude. But then how do I automate my work?"

Well, you can pick up a language and watch some tutorials on YouTube, then write a program.

"Still rude. Also, you said that's not good."

I didn't say it. I'm Charlie. I agree with you, though. A good start is describing what you want to build by writing an algorithm.

"Oh I know this one!!! It's one of those Google Interview things I read about, right!?"

Well, yeah, you're not wrong. An algorithm is a high-level step-by-step description of a process that achieves something by the end. In your case, it would be:

  1. Talk to Sales.
  2. Talk to CS.
  3. Talk to Production.
  4. Talk to Bob, your boss.

"You mean people at Google just sit there and write algorithms like psychopaths? And get paid for it? Well, WHAT AM I DOING HERE?"

Nice meme but no, not really. Programmers write algorithms in a programming language.

Like I said, the point of programming is how to tell the computer how to do something. But as computers only understand machine language, and therefore, programming languages, the hard work is translating your algorithm to programming languages.

That's literally all you have to do. There's no magic behind it (spoiler: there's A TON of magic and Googling behind it).


# Always focus on the basics.

"OK, I have my algorithm written down! How do I start programming?"

There are a few fundamental concepts of programming that you must understand before creating a new startup.

"Awwwww..."

Yes. They are variables, control flow, loops and input and output.

  • Variables are where you store your data. Like in basic math, you can assign a value to X. Later, you can use it for doing other calculations (processing), like, say, calculating the distance between X and Y. For example, your bank account has a variable amount with value 0, because you're here talking to me instead of working.

  • Control Flow is how the program runs. For example, if you go to CS and they're not giving you attention, you don't wanna stay there all day waiting. Maybe go get a coffee and come back later. In this case, the control of your algorithm would flow elsewhere (to the coffee machine).

  • Loops are repetitions of a set of instructions. In this case, your boss telling you to talk to these departments is a loop that repeats everyday.

  • Input and output are respectively the data that a program receives and the data it gives you back after processing it. For you, it means that after receiving an order from Bob you're going to process it and return the reports he asked for. These are very common nicknames for input and output you'll see around: receive and return.


# Building stuff

"Whew. That's a lot. Still, I don't understand how I would write my algorithm using a programming language."

There are some common patterns in computing for solving general problems. Suppose you want to write letters to a friend, but it takes too much time for both of you to receive the letter and send an answer back. What would you do to solve this problem?"

"That's an e-mail right? You mean e-mails are programs!?"

Yes, dear Alice, e-mails are programs.

"Wait, is Instagram a program!?"

Yep.

"Then is this website a program too!?"

Bingo.

"So you're saying this is all 1's and 0's?"

That's right! And each one of them solves a different problem.

  • E-mails solve the mailing problem.
  • Instagram solves social networking problems.
  • Websites solve content distribution problems.

And when these solutions become problems, we create new solutions. For instance, WhatsApp solves e-mail problems (sort of).

"Then, what is my problem?"

Well, you already know. Your problem is:

  • My boss wants to know some info from the departments. I have to ask people questions, but sometimes they take too long to answer and I hate interacting with these people. That's an information problem.

"And how do I solve it?"

The simple way would be writing a program that receives a question like "how many post-its were sold yesterday?" and returns the number of pots-its sold yesterday.

Then everytime your boss wants to know something, he'd run that program instead of asking you. The departments can store their data on a text file everyday so your program can read it when you boss runs it.

But you must remember: your boss' computer must be able to understand the language of your program, which means it'll need an compiler or interpreter or an executable file to actually work.

Actually, this could be a website. Or a chatbot. Or you can just e-mail spreadsheets around. It's up to you, really.

"Seems simple, yet complicated."

That's programming.


# Conclusion

"So how do I build my robot? Or automata. Or program. I don't know what to call it anymore."

You write a program.

"And how do I write a program?"

Use a programming language. Write its words in a sequence* respecting the *syntax and following your **algorithm.

"Which language should I learn?"

I don't know, they say Python is good for beginners.

"YOU SAID THAT'S NOT GOOD."

Honey, I didn't say anything. I'm Charlie, remember?

"WELL THEN HOW AM I SUPPOSED TO WRITE A PYTHON PROGRAM THEN?"

Learn it's syntax (grammar).

"AND HOW DO I LEARN IT?"

Watch tutorials on YouTube, read tutorials in this website or read the language's documentation, and always Google your questions. The last one helps a lot more than the others.

And remember: programming/coding is just communicating to a computer how to do something using a language it can understand.

"Are you avoiding my question? It doesn't seem to me like you know how to program..."

Yeah, I began the text saying that. I don't know how to program, I just talk to computers using programming languages.

"Wait, aren't you Charlie?"

Well, dear, aren't we all Charlie? We all know how to program and, at the same time, we don't. Welcome to the club.

Top comments (0)