Programming Things 101: Hello Queer World!

queer-your-tech-header_FINAL_640web

Hi Queermos! I’m Intern Chloe, I’m a software engineer at a large tech company, and I want to teach you things about programming computers! Programming is one of my top three favorite activities, after eating pasta and responding to Autostraddle tech support requests. Hopefully you might want to program computers too, because there’s a ton of job growth in I.T., and while there are some pretty kick ass queer women programmers, tech is still overwhelmingly dominated by men. Also lots of girls seem to think my ability to program computers is a good reason to send me OKCupid messages, so.

I have no idea what I'm doing (via catsoncomputers.tumblr.com)

I have no idea what I’m doing (via catsoncomputers.tumblr.com)

Let’s talk about python. I picked python for our gentle programming introduction because when you squint really hard it allllllmost looks like regular English. There are dozens of programming languages that have different strengths and weaknesses, but once you know how to program in one it’s way easier to learn more. Python is easy to learn, but also super practical and is mostly what I use in my job.

There’s a tradition among programmers every time you learn a new language to have your first program be “Hello World,” which just prints out “Hello World.” That seems a little straight for us, so we’re gonna do “Hello Queer World” instead.

First, we need a text editor to write computer code in. I’m going to be using Sublime Text 2, which you can download for free and works on Mac, Windows and Linux. Once you’ve downloaded and installed, follow these steps:

  1. Open a new window
  2. In the menu, go to “View” > “Syntax” and select “Python.” This makes the code pretty colors, basically.
  3. Also in the menu, go to “Tools” > “Build System” and select “Python.” This tells the computer to read what we write as Python code.
  4. Then, in your window, type: print “Hello Queer World!”

It should look something like this:

screenshot1

The last thing you have to do in order to run your program is save it. On a Mac you can type command+”s”, or you can click “File > Save.” We’re finally ready to roll. Next, go to “Tools > Build” (or command+”b”) to actually run your code!

Does it print out something like this?

Hello Queer World! [Finished in 0.0s]

Hellooooooo queer world (via catsoncomputers.tumblr.com)

Hellooooooo queer world (via catsoncomputers.tumblr.com)

Let’s break this down a little bit. print is a special statement in python that allows us to write out information from the computer program when we run it. “Hello Queer World!” is a string. In programming, data can have many different types; a string is anything between quotation marks. Now, try to change your program to print out “Hello <your name>” instead.

Not that kind of string (via caterville.tumblr.com)

Not that kind of string (via caterville.tumblr.com)

 

Another common data type is an int, short for integer, which is pretty much what you might expect it to be, and we can do all sorts of normal math-type things with ints too. For example, all of these statements are valid:

  1. print 4
  2. print 4 + 5
  3. print -10 / 2

What happens if you instead type print “4 + 5?” Python just reads “4 + 5″ as a string because it is in quotation marks, and so it doesn’t try to do math on it. Your window probably looks something like this:

Sublime also makes different types different colors: the ints are purple and strings are yellow.

Sublime also makes different types different colors: the ints are purple and strings are yellow.

Next we are going to talk about variables. Variables are a way of storing information that we want to use later on. For example, we could have a variable called my_name that stores a string for us. Then we can write something that looks like this:

my_name = “Chloe”

print “Hello” + my_name

And if you build this, it should print Hello <your name>. Variables can store any type of information; for example, maybe I also wanted to print out my age:

oh noooooooo

oh noooooooo

Disaster! This is our very first error message, which is telling us that we can’t add strings and ints together because they are different types. Error messages are really useful when you mess up — they try to give you information to fix the problem.

Did someone say concatenate? (via meowmeowmeeeeow.tumblr.com)

Did someone say concatenate? (via meowmeowmeeeeow.tumblr.com)

We can fix this by casting my_age to be a string instead — that is, changing it’s type for the purpose of printing it out:

Fact

Fact

Great job so far! You are learning so many things! Try making the above print statement more complicated and adding more facts about yourself using variables.


 

Ok ready for the last new big thing? The next major concept is called a function, which is a piece of code that you can reuse over and over again. For example, say I wanted to print out the name and age of anyone, not just myself. I could individually write out each print statement:

hello5

This is going to get really cumbersome because what if more Ellens come out? What then, will we just keep copy pasting code?! We need a function to end the madness.

def print_info(name, age):

Functions always start with a special keyword, def, which means that we are defining a function. Then comes the name of the function, print_info, and then the information that the function takes in — name and age. Below the function definition, we write the code that will be called every time the function is called.

def print_info(name, age):

print name + “is” str(age)

There are three important things to note about every function:

  1. The name: print_info
  2. The arguments: name (a string), age (an int)
  3. What it does when you call it: prints out name and age

hello6

A couple of things to notice about this code: mainly, you can think of print_info as a shortcut for the code inside the definition. Instead of having to type out the messy print statement over and over, you can just type print_info with the information you want it to contain. Also, notice how name and age look all orange and strange in the function definition. They are still variables, but a special kind of variable called function parameters that you send into the function when you call it, and then the function can use them like regular variables. Lastly, the line under the function definition is indented several spaces. Python actually cares about proper indentation, which means every time you end a line with a “:” you indent the next line 2 spaces. Sublime is awesome and will take care of this for you magically, but it is still worth knowing.

It’s super ok if this is confusing! Functions are scary and strange at we’re gonna do another example and then you can practice on your own.

Now, try on your own to write a function that takes in two ints as inputs and prints out the sum of them (I know it’s silly; bear with me). Ready go! Scroll below the next cat to find the answer:

Programming is exhausting

Programming is exhausting

Ok did you do it? Here’s my solution:

hello7

Cool! Great job! You know so many things about programming now! Though this is possibly the only “learn to program” guide on the internet using cat interstitials, you might want to learn more after this (I hope you do!). I highly recommend code.org for an excellent introduction. If you want to keep going, Coursera has a great selection of free online courses. What do you think? Was it confusing? Do you want to learn more? Were there enough cats? Tell me all your feelings about programming!


 

This has been the eighty-fourth installment of  Queer Your Tech with Fun, Autostraddle’s nerdy tech column. Not everything we cover is queer per se, but we talk about customizing this awesome technology you’ve got. Having it our way, expressing our appy selves just like we do with our identities. Here we can talk about anything from app recommendations to choosing a wireless printer to web sites you have to favorite to any other fun shit we can do with technology.

Feature image via Shutterstock.

Header by Rory Midhani

Profile photo of Chloe

Chloe lives and works in the Bay Area programming computers to do things. Primary interests include gender issues in tech and her growing collection of onesies. She can be reached at chloe [at] autostraddle [dot] com.

Chloe has written 1 articles for us.

37 Comments

  1. Thumb up 4

    Please log in to vote

    I had to install Python though. Anyway, great amount of cats and thank you for actually clearing my doubts between programming and design. I am actually going to start programming for a living. I made the account (although I read Autostraddle every day) just to comment on your post. Thank you!

  2. Thumb up 2

    Please log in to vote

    This article is great. And it’s such good timing as well, because I’ve literally just started trying to learn how to programme (do programming?)

    So, thank you for sharing, this is very helpful :)!

  3. Thumb up 1

    Please log in to vote

    This is a wonderful little guide and would have been way better than how I was taught when I first started programming in high school. Somehow, despite that awful Java class sophomore year, I still wanted to do compsci in college. Of course, I didn’t graduate with that degree but alas, I still have a fondness for programming. Just not pointers. Never ever ever pointers.

    Also there totes can never be enough cats but any amount of cats is superior to no cats.

  4. Thumb up 0

    Please log in to vote

    Dang, I would know SO MUCH about programming if kittens were a regular part of the curriculum.

    Do you have advice on how to learn assembly? I have to learn it for my internship this Summer…and I didn’t even know it existed a month ago. I’ve tried to find tutorials online but I guess there is not a lot of demand?

  5. Thumb up 2

    Please log in to vote

    This is super cute and is inspiring me to learn Python! Delightfully straightforward-looking.

    I also want to give a shoutout to Codecademy – that’s the site I’ve been using to gradually improve my skills; I’ve gone from zero to HTML+CSS+Javascript. It’s really good at reinforcing what you’ve already learned and combining concepts!

  6. Thumb up 1

    Please log in to vote

    This was a wonderful little introduction to Python! Yay for queer programming! And I also second the idea of CodeAcademy; as some in the comments have pointed out, it’s a lovely little site that can help bare bones beginners or refresh long time programmers.

  7. Thumb up 2

    Please log in to vote

    “This is going to get really cumbersome because what if more Ellens come out? What then, will we just keep copy pasting code?!”

    Chloe you are perfect and I love you. Also I wanted to comment on the quality of cats in this post. I feel like this many cats in one post COULD have gotten overwhelming. But they were really good cats, so I approve. ALSO I actually understood what you were trying to say w/r/t coding and it made me strangely nostalgic for that one coding class I took in high school.

  8. Thumb up 0

    Please log in to vote

    Really great intro to Python! It is on my increasingly growing list of languages to learn – sitting somewhere between ruby and swift I think. Completely forgot how easy it is to understand though!

    Pretty sure if there were more tutorials with kittens I would have picked it up sooner…

  9. Thumb up 0

    Please log in to vote

    I don’t understand how going through all of those extra steps is better than just typing “Ellen Degeneres is 56″. If you wanted to make a whole list you would still have to type all of the data plus the commands. I feel like I am missing something!

    • Thumb up 1

      Please log in to vote

      It’s just because it’s a small example that it doesn’t save typing. The advantage comes when your data (the names and ages) comes out of e.g. a spreadsheet, and then you could use the print_info function for each person to print them all out in a list.

      In fact, you would make a loop, and tell python (effectively) “do print_info for everyone on the spreadsheet” instead of “do print_info for the first person, then do print_info for the second person, then…”

    • Thumb up 1

      Please log in to vote

      You’re not missing anything! It’s true it doesn’t save you any typing at all in this case–it was just an example to try to demonstrate what a function does. The other reply has it exactly right-it starts to save you time when you have way more people or a more complicated function. I plan on elaborating on this in a future post-thanks for the feedback!

  10. Thumb up 0

    Please log in to vote

    Great intro! I also highly recommend GitHub’s text editor, Atom. Though sublime is free, if you don’t get a registered version they always prompt you to buy it… Atom is completely free and super customizable. It has all of the basics (syntax highlighting, autocomplete) and tons of other packages.

  11. Thumb up 0

    Please log in to vote

    Thanks so much!!! I work with GIS and I’ve been plodding through various python tutorials so I can make GIS work better and faster. This was very concise and way more fun than using examples of imaginary tables of imaginary things I don’t really care about. (For GIS users, ESRI has a very kind, free tutorial: http://training.esri.com/gateway/index.cfm?fa=catalog.webcoursedetail&courseid=2520“>a very kind, free tutorial.

Contribute to the conversation...

You must be logged in to post a comment.