learn to program?
June 29, 2010 11:02 AM

This question made me start thinking about learning computer programming. Two questions: do you think there's any value in doing so, and if so, how would I start? Details about me inside.

The linked question is about introducing kids to computer programming, and it made me start thinking about learning programming myself (I'm 25). It had never really occurred to me before that that was something I could do. I don't really know what the point would be - that's my first question. Would it be fun? I absolutely love logic games and puzzles. I was a math major, and I loved that. Would I be able to do cool stuff/ How much time would I have to put in before I got to the part where I could do cool stuff? Do you think learning programming is, in general, a worthwhile thing to do?

If you think it is worthwhile/fun, how do I start? Do I buy a book, is there a website I can just mess around with? The latter is my usual way of figuring out technology type things, and what I prefer to do, if possible. What language should I start with?

About me, in case it's helpful: I have never taken any computer science classes or taught myself anything about programming - I know that different languages exist, and that's about it. Math major, like I mentioned, and I tend to pick up things pretty quickly. Oh, and waaaay back in high school I did program little programs on my calculator to do things like the quadratic equation, or to ask me multiple choice questions - a choose your own adventure type game. I figured out how to do that just from looking at the code from other peoples' programs.

I did a search and saw some previous questions, but for the most part the responses went way over my head. I'm not interested in reading long books about theory, I'm interested in messing around with the actual languages and trying to make little programs.
posted by insectosaurus to Computers & Internet (13 answers total) 37 users marked this as a favorite
Your easiest path into making something visible happen on a screen is Javascript. You have a web browser, you just create a web page and open it locally, then start adding Javascript to the page. There's a million tutorials to get you going, tons of reference material, and with strong google-fu, it's almost inconceivable that someone won't have had the same problem you might have and have solved it already. There's lots to learn there, and Javascript is a real programming language with immediate applicability. From there, you can move on to PHP in a $10 shared hosting account and start doing more.

The benefit of this route is that you're always working on something that can be immediately visible and useful. Doing cool stuff is almost immediate, and as a math major, you'll likely be able to do interesting math stuff (graphing, math games, etc.) right away and with plenty of examples.
posted by fatbird at 11:09 AM on June 29, 2010


Here's a good AskMeFi question related to what you're asking.

http://ask.metafilter.com/55905/Best-programming-language-for-beginners

Python is always a good choice for beginners, in my opinion. It's very quick to start hacking around with "real" programs with it.
posted by speedgraphic at 11:11 AM on June 29, 2010


Learn the basics of python, then check out Project Euler, a bunch of math problems/puzzles for you to program.
posted by asphericalcow at 11:18 AM on June 29, 2010


I don't really know what the point would be - that's my first question.
It's a matter of creativity -- at least, eventually. As a beginner, you'll find it's almost too easy to get distracted by process to really feel 100% creative.
Would it be fun? I absolutely love logic games and puzzles.
It's as fun as you make it. If you like logic games and puzzles, you might find that therefore you enjoy programming, or you might find that you really just enjoy playing logic games.

For that reason, I suggest taking a look at sites like pygame.org. Find a logic puzzle game. Play it. If you like it, take a look at the source files. See how you can make the game better. Maybe you want to change the rules a bit, or change the graphics to match your favorite colors, or change the music.

I've taught a game programming overview course that was just this -- here's a game, play it, now see this problem with it? The tank is yellow, but it's shooting pink bullets. Can you make it shoot yellow bullets? Etc.
Do I buy a book, is there a website I can just mess around with? The latter is my usual way of figuring out technology type things, and what I prefer to do, if possible.
OK, then definitely start with what I said above. I learn that way too, and I have gazillions of unfinished programming texts on my shelf. They all got great reviews, too...but some of us just learn differently.

People recommend Python because it's "easy," but game programming will always present challenges. Python has the advantage of taking those challenges off the front end of the curve and moving them toward the back. You don't have to compile the software every time you want to run it, etc.
I figured out how to do that just from looking at the code from other peoples' programs.
Triple what I said above. Skip the tutorials, skip the books, just go straight for other peoples' code.

My guess is, if you try it this way, you'll start with 99% other peoples' code and 1% your own code, and eventually you'll probably reverse that, if you decide you want to keep it up.

The world is rich in programming environments and examples these days, so you've picked a great time to start. Happy hacking!
posted by circular at 11:22 AM on June 29, 2010


BTW, as another example of how things could go for you:

I'm primarily a graphics guy, so I started with a game that looked fun, made graphics changes to start with, and before I could get into changing the game logic too much, the original programmer invited me to collaborate.

It's turned out well so far -- I still do graphics work primarily, and while I enjoy programming, I'm fine with the other guy taking care of that as long as I can participate and still make things fun.

Game development used to be a bunch of solo-coders hoping to one day work on big teams. Now there are a lot of people who start on small teams and may not even aspire to change that.
posted by circular at 11:28 AM on June 29, 2010


It had never really occurred to me before that that was something I could do. I don't really know what the point would be - that's my first question.

This is harder now than it was back when I learned. When you had a computer with BASIC and a few other programs, writing code was one of the only interesting ways to make computers do neat stuff. These days you can download apps that already do tons of neat things and there are a lot of ways to create something yourself without writing actual code (like using pre-built blog software instead of writing your own code and HTML in the process of making a website). There is still room for writing your own code, though. Is there any relatively simple thing you would like your computer to do that it doesn't do, or something you would like to build that would involve writing some code to make it work?

Oh, and waaaay back in high school I did program little programs on my calculator to do things like the quadratic equation, or to ask me multiple choice questions - a choose your own adventure type game. I figured out how to do that just from looking at the code from other peoples' programs.

Was that fun? If so you can easily do pretty much the same thing with any other hobby programming project. Think of something cool that you want to do (make a website, build a little device that will read Twitter messages out loud, whatever), find online examples of people doing similar things online and fake your way through it. You can find example code and helpful libraries in almost any language on almost any topic. When pursuing programming seriously (such as in a career) it makes sense to really learn and understand everything, but if you're just doing it for fun you can go a long way by just jumping right in and learning it as you go along. Programming is mostly about having a problem to solve, figuring out how to solve it with the tools you have (which may just involve finding code or a library that already does most of what you want), and telling the computer how to solve it. I can't really give you advice about specific resources and languages unless I know more about what kinds of projects you want to do, though.
posted by burnmp3s at 11:56 AM on June 29, 2010


I don't know what kind of computer you're using, but if you're on a Windows machine, I found that AutoHotkey was a fantastic way to pick up a few essentials and get started right away. It's a (very simple) scripting language, so unlike most languages you'll find that with AutoHotkey you can start making your computer "do stuff" (from entering strings of text, to moving your mouse pointer for you, to building simple GUIs) very quickly. And AutoHotkey is a great place for a beginner to start because they have what is probably some of the most elegant and intuitive documentation I've ever seen.

If you want to move on to more powerful things, I think it's good to just use AutoHotkey as a stepping stone upward. However, I think it's the best way I know of to get started right away programming stuff that you're actually going to use.
posted by koeselitz at 12:36 PM on June 29, 2010


It is ABSOLUTELY worth doing. I say that, because programming teaches you to think in some way that very few other non-mechanical things can. I suspect that you can learn MANY of the same things via something like engineering or surgery, but it's really the only way to learn certain mental practices without getting your hands dirty.

You can learn some of these things from doing mathematics, but math doesn't give you instant feedback. There can be a mistake in your proof that take you forever to notice, but if your program doesn't work, it doesn't work.

Here are some things I do: direct plays, read difficult books, write books and articles, teach classes, draw... I enjoy a couple of those things more than programming, but hands down programming builds the most new structures in my brain. When I get to a new level as a programmer, it's like I can actually feel new neurons coming to life in my head. It's THRILLING.

Here's a great quote from a Stack Overflow (progammers forum) thread about how programming changes your brain:

I no longer equate thinking I'm right about something with actually being right about it.
It's now very easy for me to entertain the thought that I may be wrong even when I feel pretty strongly that I'm right. Even if I've been quite forceful about something I believe, I'm able to back down very quickly in the face of contradicting evidence. I have no embarrassment about admitting that I was wrong about something.

That all came from decades of working in a discipline that mercilessly proves you to be mistaken a dozen times a day, but that also requires you to believe you're right if you're going to make any progress at all.

... This discipline is much more native to the scientific method, of course: coming up with a solution is easy, it's not until there is solid evidence, demonstrating the solution in the face of attempts to disprove it, that it's of any value. I see this convergence as a sign that programming is finally becoming enough of a science that blind faith is beginning to be seen for the nonsensical position that it is.

... The practice of open-mindedness that I'm talking about is orthogonal to understanding the universe through controlled repetition. There are people to whom the experience of feeling wrong, and the action of openly admitting error, are unpleasant, even intolerable. Remaining open to that experience, even embracing it, is a practice that is more spiritual than scientific.
Sure, the best scientists have to cultivate this ability too in order to withstand the emotional process of investigation. But plenty of scientists don't (which is why we know who Thomas Kuhn was), and plenty of people who aren't scientists do.

And I vigorously reject the idea that we're somehow suddenly seeing that blind faith is nonsensical. Find me a software developer who's willing to stand up for blind faith. What we're not willing to say is that what we are doing is often engaging in faith, and that it this faith is sometimes blind.

posted by grumblebee at 2:02 PM on June 29, 2010


insectosaurus: "If you think it is worthwhile/fun, how do I start? Do I buy a book, is there a website I can just mess around with? The latter is my usual way of figuring out technology type things, and what I prefer to do, if possible. What language should I start with?"

Well, to my mind it's actually pretty criminal to give a math degree without any exposure to programming. But you're at least well grounded enough to do swimmingly. There's a chance you understand what a function is, and what a Directed Acyclic Graph is, which is great.

People have already mentioned making games, and that's great if you like them. Logic puzzles can be fun but it can be difficult to make sure the puzzles generated are solvable.

I might recommend a slightly different approach. I really like the OCaml approach to types -- it's very succinct. And as a self described math major you shouldn't have much trouble it's drawbacks (recursion featured prominently). So here's what might be an interesting project to work towards:
1. design a data structure that can represent mathematical expressions, including operators, constants, and variables.
2. Write a function/program that, when given a specific instance of above, types it out to the command line ("pretty printing").
3. Add a function to that program that can calculate the symbolic derivative of an expression. Nothing fancy, maybe just the power rule and addition rule.

That's really what computer programming is about: defining ways of organizing data and writing algorithms to manipulate it for useful results. You might have to write a bunch of smaller projects to get to where you can do the above project. So definitely do the hello world projects and the basic I/O and fibanocci sequences and binary search algorithms for training.
posted by pwnguin at 2:06 PM on June 29, 2010


Oh, since you like logic puzzles, try "The Little Schemer." It's a cross between a puzzle book and a programming book, and it's highly respected -- and FUN! It is written in this really cool, Socratic format that starts you from nothing and build you up to these really complex ideas.
posted by grumblebee at 2:11 PM on June 29, 2010


Programming, at some level, is absolutely as essential as any other form of literacy. Even if you just start with Auto-It (hell, even HTML/CSS or Excel spreadsheet macros).. The key to learning is to combine traditional exercises with doing something useful toward your own productive or creative impulses.
posted by Chuckles at 6:54 PM on June 29, 2010


Here's the interesting kind of adventure you have when you're programming: this morning I was making a slide show in Flash. When a new image displays, it slides in from the right, while the previous image slides off to the left. Or that's what is supposed to happen.

Inexplicably, the sliding would halt halfway through. It would halt so that the old slide was halfway off the screen rather than all-the-way gone. And the new slide was only halfway on the screen. To make things worse, this didn't happen all the time. It only happened some time.

Now the animation is handled by just two lines of code, one to animate off the old slide and another to animate on the new one. And it's not my code. I'm using a popular animation library called TweensyZero. My code looks something like this:

TweensyZero.animateOff(old slide, GoToOffScreenLeft)
TweensyZero.animateOn(new slide, ComeFromOffScreenRight)

(That's not really the correct syntax. It's just to give you the idea.)

So it seemed to me that the problem couldn't be mine. It must be a bug in TweensyZero, which I didn't write. So I starting googling things like "TweensyZero doesn't complete" and "TweensyZero bug." But I didn't find anything useful.

I went ahead and opened up the code for TweensyZero and started inserting traces. Traces make text (of my choice) appear in a special diagnostics window, alerting. I discovered that TweensyZero has a bit of code that's supposed to run when the animation is over. So I put a trace in the middle of that code that said "I'm over!"

I ran the program again and watched the diagnostics window. Every time the slides animated off/on correctly, I saw "I'm over! I'm over!" (Twice because both the on and off animations completed.) But when the animation would hang halfway through, I wouldn't see any text in the console. This told me that TweensyZero's internal completion code was never running.

Boy, this sure seemed like a TweesyZero bug. I mean, all way was doing was...

TweensyZero.animateOff(old slide, GoToOffScreenLeft)
TweensyZero.animateOn(new slide, ComeFromOffScreenRight)

There was really nothing I could do differently. It was just supposed to work.

But I found NOTHING online about a bug in TweensyZero. I've been the first person to find bugs before, but TweensyZero is used by hundreds of people, and that's a pretty big bug. Surely SOMEONE would have found it before me. So, despite my feelings about where the bug MUST be, I had a suspicion that I was wrong. That it was something in my code, not TweensyZero's code.

I thought, again, about how the bug only happened sometimes. I ran the program again, trying to see if there was anything special about the times it happened. Eventually, I noticed that it only seemed to happen when I moved my mouse over the screen.

Huh? Why would rolling my mouse over the app have anything to do with whether an animation completed or not?

Then I noticed that something else happened when I rolled my mouse over the app. A little control panel appeared. (Play button, pause button, etc.) If I rolled my mouse off the screen, the control panel vanished after a few seconds. None of this was a surprise. I had programed the control panel to do that several weeks ago. I programmed it, it worked, and so I forgot about it.

But it was using TweensyZero to do its fade-in, fade-out animation. Could there be some problem that was happening because I was using TweensyZero for two things at the same time? It was doing two things whenever I rolled my mouse over the screen -- making the control-panel fade in at the same time a slide was transitioning -- and it was then that the problem happened.

I thought back to when I programmed the control-panel animations. What I remembered was this: the normal course of events is that the control panel fades in (if you roll your mouse over the app) and then fades out five-seconds later. When I was testing that, I was often frustrated, because by the time I'd decided to click the pause button (or whatever), the five seconds was over and the control panel would fade out before I could press the button.

So I had amended the code to look something like this:

- WHEN THE USER ROLLS HIS MOUSE OVER THE APP, FADE IN THE PANEL.
- WAIT FIVE SECONDS.
- IF FIVE SECONDS ARE OVER, CHECK TO SEE IF THE MOUSE IS STILL OVER THE APP.
- IF IT'S NOT, FADE OUT THE PANEL. IF IT IS, STOP THE FADE-OUT ANIMATION.

So I was stopping an animation. How was I doing that? I looked at my old control-panel code and saw this:

TweensyZero.stopAll()

I checked TweensyZero's documentation and, sure enough, stopAll() stops ALL animations that TweensyZero is currently running. Bingo! The code that was stopping the control panel from disappearing was also stopping the slide transitions. I read a little more of the documentation and changed the code to this:

TweensyZero.stop( control panel );

And everything worked beautifully. ONLY the control-panel animation stopped while you rested your mouse on the screen. The slide-transition animation kept running.

This is the sort of problem-solving you do every day when you're programming. To me, it's thrilling. It can also be frustrating as hell, but in that good, logic-puzzle way. And, if you do this sort of thing every day, you get better and better at it. And you start being able to apply it to all sorts of things in life, not just debugging code.
posted by grumblebee at 2:00 PM on June 30, 2010


I've watched four episodes of this. Pretty darn good.
posted by grumblebee at 7:13 PM on June 30, 2010


« Older We'd rather reign in hell than serve in heaven!   |   Where can I find OEM Dodge parts online? Newer »
This thread is closed to new comments.