Skip to content

NSB Programming Courses (in ALPHA)

magnesium2400 edited this page Jun 22, 2023 · 7 revisions

Introduction to Programming

Reproduced from https://automatetheboringstuff.com/2e/chapter0/

Why learn programming?

“You’ve just done in two hours what it takes the three of us two days to do.” My college roommate was working at a retail electronics store in the early 2000s. Occasionally, the store would receive a spreadsheet of thousands of product prices from other stores. A team of three employees would print the spreadsheet onto a thick stack of paper and split it among themselves. For each product price, they would look up their store’s price and note all the products that their competitors sold for less. It usually took a couple of days.

“You know, I could write a program to do that if you have the original file for the printouts,” my roommate told them, when he saw them sitting on the floor with papers scattered and stacked all around.

After a couple of hours, he had a short program that read a competitor’s price from a file, found the product in the store’s database, and noted whether the competitor was cheaper. He was still new to programming, so he spent most of his time looking up documentation in a programming book. The actual program took only a few seconds to run. My roommate and his co-workers took an extra-long lunch that day.

This is the power of computer programming. A computer is like a Swiss Army knife that you can configure for countless tasks. Many people spend hours clicking and typing to perform repetitive tasks, unaware that the machine they’re using could do their job in seconds if they gave it the right instructions.

You get out what you put in

Programmers Don’t Need to Know Much Maths

The most common anxiety I hear about learning to program is the notion that it requires a lot of math. Actually, most programming doesn’t require maths beyond basic arithmetic. In fact,** being good at programming isn’t that different from being good at solving Sudoku puzzles**. Just because Sudoku involves numbers doesn’t mean you have to be good at maths to figure out the solution. The same is true of programming. Like solving a Sudoku puzzle, writing programs involves breaking down a problem into individual, detailed steps. Similarly, when debugging programs (that is, finding and fixing errors), you’ll patiently observe what the program is doing and find the cause of the bugs. And like all skills, the more you program, the better you’ll become.

You Are Not Too Old to Learn Programming

The second most common anxiety I hear about learning to program is that people think they’re too old to learn it. I read many internet comments from folks who think it’s too late for them because they are already (gasp!) 23 years old. This is clearly not “too old” to learn to program: many people learn much later in life. It’s important to have a “growth mindset” about programming—in other words, understand that people develop programming skills through practice. They aren’t just born as programmers, and being unskilled at programming now is not an indication that you can never become an expert.

Programming Is a Creative Activity

Programming is a creative task, like painting, writing, knitting, or constructing LEGO castles. Like painting a blank canvas, making software has many constraints but endless possibilities. The difference between programming and other creative activities is that when programming, you have all the raw materials you need in your computer… A decade-old computer is more than powerful enough to write programs. Once your program is written, it can be copied perfectly an infinite number of times. A knit sweater can only be worn by one person at a time, but a useful program can easily be shared online with the entire world.la

Using this document

  1. This document is supposed to be beginner friendly, but also self contained. Please let us know if things are not being explained well enough in this document! Or if you have any questions, or there is content you would like to see added.
  2. The document is in a few sections.
    1. This first section (here) contains a few introductory notes.
    2. The following pages have large tables of lists for the common tools that we use. These tables are introduction/dot points of the full breadth of information. It seems like a lot, but you will pick it up quickly with practice. The information presented is a combination of (i) clear and efficient tutorials on the web; and (ii) tutorials developed within the lab. They are listed approximately in order of what to learn: first, interacting with MASSIVE; then, choosing a particular language; then, furthering your analytic techniques.
    3. The end of the document contains separate sections that expound on the content covered in the tables. Generally, these sections will be content written by and for the lab.

Programming primers

We recommend starting with the excellent Computer Science course developed by folks over at Crash Course. Episode #12 starts with a basic introduction to introductory programming ideas, including variables, statements, and loops. [We also recommend the rest of the course for learning the fundamentals of computer science more broadly].

Debugging code

What happens when your code goes wrong? There are various ways to fix code. You could…

  • Talk to a senior: science is collaborative. Do not be afraid to ask for help.
  • Rubber Duck Debugging: “the name is a reference to a story in the book _The Pragmatic Programmer _in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line by line, to the duck.” This is a very useful technique - and may be helpful in the process of annotating your code for future code checkers.
  • Google and StackOverflow: godsends to programmers of all ages around the world.
  • (NEW) Use ChatGPT to help: but users beware - ChatGPT will sometimes give code alternatives that will not work. At the end of the day, it’s best to know what the code is doing: if things go wrong, you can more effectively debug scripts, reproduce results and justify your analyses.
    • Sometimes you can tell it that it’s first answer is wrong, and it will spontaneously correct itself 🙃