Tag Archives

3 Articles

Programming Poetry

Connected


Once, atoms were sparsely connected
 then they connected.
Once, molecules were sparsely connected
 then they connected.
Once, proteins were sparsely connected
 then they connected.
Once, cells were sparsely connected
 then they connected.
Once, people were sparsely connected
 then they connected.
Once, societies and countries were sparsely connected
 then they connected.
Once, technologies were sparsely connected
 then they connected.
Once, people were sparsely connected

Learning Programming?

The poem above was written with a bit of python code. I’m sure you spotted the repetition. Can you isolate the changing vs non-changing portions of the poem?

My favorite way to learn programming is to puzzle through the code. Figure out what it’s doing. Change how it works. Mess it up. Make it better.

Here’s the code for this poem. Make sure you mess with it.  Click here to try this poem

 

# you can make functions with def in python
# this function is named makeVerseOne
# it has one parameter, named 'what'
# the function outpus a a verse with {0} replaced with the parameter 'what'
def makeVerseOne(what):
  return "Once, {0} were sparsely connected".format(what)
  
  
# this does the same thing but with a different verse
def makeVerseTwo(became):
  return " then they {0}.".format(became)
  
# this is a list of things my poem is about  
whatWas = [
  "atoms",
  "molecules",
  "proteins",
  "cells",
  "people",
  "societies and countries",
  "technologies",
  "people"
]


# this is an empty list. I want to STORE my verses here.
verses = []

# we commonly fill lists with values returned from functions
for what in whatWas :
  verses.append(makeVerseOne(what))
  verses.append(makeVerseTwo("connected"))
  
# remove last line, for edginess
verses.pop()
  
# lets combine all the verses with a newline after each verse
poem = "\n".join(verses)

# output the poem to the terminal
print(poem)

3 Basic Programming Concepts You Need to Know

Let’s start with the basics

Basic Programming Concepts

There are many concepts in programming and computer science which are very important and extremely useful. I encourage you to supplement my post with research, but hopefully you find the 3 basic programming concepts in this post are very clearly important to learning programming. Before we dive into the basics, first you need to make sure you know what programming is.

What is programming

Warning! Over simplifications ahead! ūüôā Programming is how humans talk to computers. Computers are machines that can only do exactly what we tell them to do. When we program, we are giving the computer instructions.

What does the computer do with the instructions?

The computer uses electricity to perform our instructions. All of our instructions end up telling the computer how it should handle the flow of electricity. Humans use these instructions to get the computer to manipulate information. Computers can only use the instructions they are built with. To learn more, research Machine Code.

How DO I TALK TO COMPUTERS??

People have built tools to help them talk to computers. Just like we have translators for speaking to people who don’t speak our language, we have translators for computers. When you program, you will be writing instructions that these translators understand. The translators will the convert your code into instructions the hardware can execute. We call these translators interpreters and compilers. ¬†Make sure you lookup the differences. We call the languages these translators understand¬†programming languages

Basic Programming Concepts

Now that you know you’re talking to the computer, you should be wondering what you’re talking to it about. Generally when we program we are describing information: how to store it, how to manipulate it,¬†¬†how it’s structured, how to present it,¬†etc.

Information is all around us! Information could be the names of all your friends. It could also be all of the dishes a local restaurant serves. Programming gives you the power to handle vast amounts of available information and do whatever you can imagine with it.

Mystery #1 – What concept is this?

Here’s a concept, written in the Javascript programming language.

var name = 'Micah';
var age = 2;

How about the same example in the Python programming language?

name = "Micah"
age = 2
What is all this nonsense?

 

You might be wondering, why var, why ‘Micah’, why ; WHAT IS HAPPENING!?! Don’t freak out. This is called “syntax”.

Programming languages have rules, the same way we have rules for how to write English sentences. The semi-colon indicates the end of a line. Some languages, like python, don’t need it. Just like English, programming languages change over time, gaining new ways of writing the same concepts.

BASIC PROGRAMMING CONCEPTs #1 – Storing Information

You may have deduced from the examples, that I was storing the word “Micah” and the number “2”. If not, no worries. This stuff is weird. Go look at it again… This concept of associating a value with a name is called assigning a variable.

We are assigning “Micah” to the variable name. As we should, because my name is Micah. Remember clear variable names make your code easy to read and reason about.

We are also assigning the value 2 to the variable called age. Unfortunately this is not my actual age. ¬†Let’s fix that.

Mystery #2 – What concept is this?

Here’s a new concept written in a language you’ve seen before.

var name = 'Micah';
var age = 2;
age = age + 21;

How about the same example in the Python programming language?

name = "Micah"
age = 2
age = age + 21
Okay, I’ve seen addition before…

Fantastic! Addition is a great thing to know! The concept is that we’re manipulating some information that we’ve previously stored. Age is changing from it’s previous value to it’s previous value increased by 21.

BASIC PROGRAMMING CONCEPTs #2 РManipulating INFORMATION

From the examples you probably saw that I was changing age from 2 to 23. After we store information into variables we often perform operations on them, like addition in the case of numbers. The symbol that indicates an operation is often called an operator. Different types of information handle these operations differently. Programmers can define their own operators, as well as their own types just like they can define variables.

When programmers define their own operations, they tend to be grouped into something called functions. A function is a reusable mapping of some input to some output. For instance, say you have a function called addTwice. It takes in two numbers and outputs the numbers added to each other twice.

function addTwice(firstNum, secondNum) {
 return firstNum + secondNum + firstNum + secondNum;
}
addTwice(5,2);

If this looks crazy to you

  • the word function is a keyword, which tells a programming language, hey, I’m about to tell you something. Var is also a keyword ūüėČ
  • addTwice is the name of the function
  • (firstNum, secondNum) This is how we define the inputs a function can have.
  • Once an input is defined, you can use it inside of the {} block. This will become more clear
  • return is how you output something from a function.
  • addTwice(5,2); This is how you use the function.

PS – If you’re wondering why age isn’t equal to “age + 21”, the words, then congrats. You just realized why we need to use a signifier like quotes around words that aren’t variables.

When would I need to make a function?

If you have some code that you’re copy and pasting, or if you have something that’s a bunch of steps that can be described in a higher level than the steps, try making a function for it. Imagine you have some code that is transferring money between you and a friend, and you want to let others use this code. You could create a function called transferMoney. It would take in 3 parameters, amount, fromPerson, toPerson. After making this function you can now facilitate payments between any two people, without ever changing your code. Re-usability is very important in programming.

MYSTERY #3 – WHAT CONCEPT IS THIS?

Here’s a new concept written in¬†TypeScript. Javascript with types.

class Person {
 name: string;
 age: number;
}

How about the same example in the Python programming language?

class Person: 
 name = ""
 age = 0
Classes? What I’m trying to learn, now I gotta take a class?

Don’t get caught up on that word. What’s in the class? How would you know that? In Javascript things inside the {} are called blocks. Generally things in blocks are related to the code preceding the block. In python blocks are determined by indention, following a colon. So everything that’s indented after the colon is considered a block. Go research blocks. Hint: They’re used for grouping instructions.

Basic Programming Concepts #3 РStructuring INFORMATION

Imagine you had 100 people, and you wanted to store their names and ages. In our first set of examples, you would have tried to make a variable for each person for age and name.

var name1 = 'Micah';
var age1 = 2;
var name2 = 'Matt';
var age2 = 100;
...
var name99 = 'Fonzy';
var age99 = 800;

Now that you’ve seen the example, you might guess that “classes” allow us to describe information with multiple properties. Instead of a ¬†variable holding one piece of information, ‘Micah’, it can hold a name and an age.

var writer = new Person();
writer.name = 'Micah';
writer.age = 2;

Take a moment to pat yourself on the back. You’ve just consumed quite a large amount of information. If you’ve managed to make it this far, and you feel completely lost, don’t freak out. There’s hope. You aren’t going to learn this stuff in one day. You’ll need to mess around with it. I’ll work on getting some interactive code up for everyone.

tldr;

Just make sure you learn :

  1. In programming we store information
    1. variables store information
  2. In programming we manipulate information
    1. functions are blocks of code that take in input and produce output
  3. In programming we structure information
    1. blocks are used to group instructions
    2. classes are used to create structured data.
  4. Google everything. Research. This should be a good starting point.
  5. Dont give up. It’s okay to be confused. It’s okay if it doesn’t work. Keep trying.
  6. Tweet me if too confused, or if you have questions I’ll try to help you. @micahriggan

Thanks for reading!

Thanks!

Thanks!

Want to learn programming? Start here

Programming is fun

Programming is fun

So you want to learn to program?

Write some code? Build an app? Make a website? Awesome! Maybe I can help. I taught myself programming and I think that anyone can learn it. If you invest the time and actually play with it, you will learn. Interested?

Start here!

Programming – High Level Overview

I’m going to do a series of posts with the goal of teaching you to code. I’ll start out super simple, generic, and vague. Then I’ll explain programming concepts¬†rather than any language specific topics. Next I’ll start with a high level view of the concepts, so you know where we’re going. Then I’ll cover the basic concepts, which will be combined to show more complicated concepts. Eventually the picture will be filled in, and you’ll understand¬†the concepts. With mastery of the concepts all languages become trivial to learn.

Puzzle out the examples

After I give the overview of the concepts, I’ll start with examples.¬†I learned to program from reading code and trying to puzzle out what it was doing. Hopefully you get some benefit from this as well. Make sure you mess with the examples. Change them around. This will help more than anything.

Video summary

With each post, I’ll include a video explanation, that way those who learn better from videos than reading can benefit. If you have comments or requests or maybe you’ve got a better way of explaining something, let me know in the comments or on twitter. By no means am I the authority on programming. I am just trying¬†to share my knowledge. Hopefully this helps others to learn and progress.

tldr;

  • I’m doing a blog series where my goal is to help you to learn to program
  • I’m going to start with the basic concepts.
  • I’ll show examples with the concepts
  • I want you to try and figure out what the examples are doing
  • I want you to modify the examples
  • I’ll include a video with each post.
  • Hopefully I can help you.

Lets get to it!

Start here!

 

Learning Resources