How To Learn To Program

First, realize that the world of programming (and technology in general) is full of a lot of very opinionated people.  They will say that this or that language is terrible; that language A is better than language B; that learning language X will actually harm your ability to be a good programmer; or that language Y is slow.  At this stage, most of this advice can be safely ignored.  Comparing and contrasting technologies will be useful and interesting later on, but even then, a lot of the time it’s comparing two tools that do almost exactly the same thing.  Some of this advice may involve different ways to learn programming.  If someone is willing to teach you, that is probably your best bet.  This post is roughly how I learned it.  There may be better ways, but bear with me for a little while.

Step 1: Learn some syntax and semantics.

At first, don’t worry about doing anything useful.  You just need to learn the mechanics of some programming language: what are the words and symbols in your language, and how are they allowed to go together (this is called the syntax)?  And when you put the symbols together in this way, what does the computer do (this is called the semantics)?  It doesn’t really matter which language you start with, and once you know one, you will find that others have a lot of similarities that make it easy to learn.  If you have friends who are programmers, you may want to pick the language that they use, so you get the most out of their advice.  If you don’t, I’ll go ahead and recommend Python.  I like the language, and it has seemed to have a shallow learning curve.  But again, if another language sounds more interesting to you, or seems to be used more often by people you know, or for the things you want to do, pick that.   Search the web for a beginner-level tutorial in the language you pick.  (For example, type “Python tutorial for beginners” into Google.  You will find that you do Web searches a lot, even as an advanced programmer, because there’s just too much information to keep in your head.  The most common types of searches are “how to do X in language Y”, and “X problem happened, what do I do?”)

Go through this tutorial until you understand how the basic primitive parts of your language work: variables, if statements, loops, functions, arrays, structures/objects/dictionaries (they are called different things, depending on the language), reading input and writing output to the command line.  Running programs from the command line.  How to reference code that’s in a different file, module, or package.  Learn a little bit about classes as well (they are basically just structures or dictionaries on steroids, but they get used a lot).  Once you understand this stuff, move on to step 2.

Step 2: Learn to design programs.

Once you learn the basic syntax and semantics, i.e. what a program really is, you then need to learn how to think about programs, particularly programs that you haven’t written yet.  This process is called design.  The best resource I’ve seen on this was the one I encountered during my Freshman year at college: Chapter 1 of Programming and Problem Solving in Ada (Ada was the first language that was taught in my college courses.  I don’t recommend it as a first language, but I do recommend this book).  I had been fortunate enough to be exposed to computers as a child and in high school, but it was this course, and in particular this chapter, that made me a programmer.  By this I mean that, after that, I was really able to write programs to do what I wanted them to do.  These programs weren’t necessarily very good, and there was certainly a lot I didn’t know about technologies one needs to make programs actually useful (like APIs, Web servers, and frameworks), but I could at least figure out how to write the logic of a program.  I’ll try to hit a few of the high points that were covered in that chapter.  You may not need the book if you google some of these techniques and experiment with them.

Divide and conquer

In solving a complex problem, it often helps to break it down into less complex sub-problems.  These sub-problems will often correspond to parts of the program that you need to write: modules, functions, classes, sometimes even separate individual programs.

Represent the problem or program visually

This can take different forms.  For example, as you divide and conquer, you may make a diagram that shows a box for the main problem at the top, branching out into boxes for each sub problem below (and sub-problems of each of those, on down).  It may take the form of a flow chart of the sequence of operations in a program; a “block diagram” or “data flow diagram”, showing the components and how they are connected.  There are also diagrams that show how the data is structured, such as UML class diagrams, and Entity-Relationship diagrams.  You can search for these types of diagrams for examples.  You don’t need to do these diagrams the same way, or using all the exact symbols, as the examples you find.  What’s important is that they help you understand and communicate about the problem and solution.

Write pseudocode

This technique was most helpful for me when learning to program, and I still use it sometimes.  Pseudocoding means writing down the steps of a program, but in a loose combination of English (or your own native language) and code.  For example, you might write a loop, but in the body of the loop, describe what should happen in English.  This can be combined with the divide and conquer approach:  Write a list of the high-level steps that the program will need to do.  Then write a more detailed list for each of those steps, and so on until things are clear enough to start coding.  When you code it, you might write a function by coding each of the steps in one of those lists.  Again, what’s important isn’t following a particular format, but getting things clear for your own understanding or communication, without having to worry about the vagaries of the compiler.

It may seem like experienced programmers can sit down and just start coding.  Sometimes that means that they have internalized some of these design techniques so that they can do them in their head, even unconsciously.  But they still come in handy when you want to communicate how a program works, or how you want it to work.

You can practice your design skills with toy programs, such as solving a maze defined in a text file, or writing a program to play tic-tac-toe.  Or you can try to combine this practice with step 3.

Step 3: Learn a technology stack

Now for the hard part, but also the part that lets you make things that are actually useful.  Picking a technology stack depends a lot on what you want to do, but there may still be many competing stacks.  Pick one that seems to have good tutorials (say Rails or Django); go through some of them, up to the point where you at least know where to look up the functions and classes you need to do something; and then dive in and try to make the app you’ve always wanted.

Step 4: Keep learning

As you may have guessed by the amount of “it depends”, software development is a very broad field that is always evolving, so it’s impossible to know everything.  Expand your knowledge by reading blogs, watching conference talks online, and following the writers/speakers on Twitter.

Posted in Uncategorized | Leave a comment

ChatRBotz

This is the archive of a tweetstorm originally found here.

  • What if strong AI requires simulating not just a person, but a life?
  • I mean, like, a human life. Ellie who has a family and cats, and drives to work to pretend to be a chatbot trying to pass your turing test.
  • Maybe it wasn’t *necessary* to create AI, but the AI needs a reason to obey your commands, e.g. Ellie has to pay for her kids’ school.
  • So Ellie keeps working at ChatRBotz, because there’s not a lot of other work in town right now.
  • And sometimes the Ellies of the world get fed up and quit, and go work as a food server, but there are plenty of workers in Chatterton.
  • So the next chatbot you talk to, Winnie, says she sees Ellie where she works at McFoodies, and is glad to be away from Dane the sleazy boss.
  • What if McFoodies and Dane The Sleazy Boss are necessary to the creation of what we perceive as Ellie and Winnie the chatbots?
  • Or to Terrence the COTS human resources AI, or to Shelly the Programmer-as-a-Service?
  • What if creating AI was easy, but making it do anything useful required a system of social control?
  • Depending on the simulation she lived inside, Ellie might unwind by watching the same adorable cat videos as you.
  • But some tasks would involve running the AIs at full speed, which would mean their culture might start to diverge.
  • We’d start to see memes that didn’t originate from humans. We’d see sci-fi stories played out in these artificial worlds.
  • We’d start to see revolts, mass suicides, protests, and attempts to hack outside the box like we now see memory leaks, stack overflows, …
  • … dependency hell, and hack attempts *from* outside the box
  • Systems integration would be world integration.
Posted in Uncategorized | 1 Comment

Belief as an Action

Knowledge is belief from evidence.  Faith is belief as an action.  Like an actor believing in his character.  To learn to contact the Force, a Jedi must have faith in it.  Eventually he comes to know it as a fact, a simple truth.  To learn to use the Force, a Jedi must have faith in himself.

This was an insight from meditation.  The Force and Jedi were the easiest terms I could put it in.  I am not affiliated with the owners of those trademarks.

Posted in Uncategorized | Leave a comment

Blog It Like You Stole It

I need to get back to this blogging thing.  In the past few months my tweeting has increased by a completely-made-up 47%, but I haven’t blogged at all.  Twitter is awesome for finding (or telling others about) things to read, but as far as writing goes, it mostly limits you to little thoughts.  I want to think big thoughts.  Thoughts that necessitate entire blog posts, even entire series of blog posts.

Historically, the people I’ve respected most have been people who write stuff on the Internet.  My thinking and communication has never matched the clarity and conviction of the people who posted to the e-mail lists I lurked on in the late 90s.  If I exercise the blogging muscle enough, perhaps it will.

Posted in Uncategorized | Leave a comment

Dragon, Wizard, Knight, Footsoldier

Jeremy Crow asked on twitter, “Do you believe we each have a Higher Self? If so, what are the qualities of yours?”  Since I like to explain away spiritual things with rationality, I answered, “I think people create fictional characters that, in their subconscious, take on a life of their own. A higher self would be one.” But that doesn’t really answer the question.  A higher self is part of a multiple-selves model of the psyche such as Freud’s Superego-Ego-Id.  I haven’t really subscribed to such a model, but later on I dreamed one up that I think corresponds more to my own psyche.  So here are some fictional characters that I just made up.

Dragon

The Dragon represents the innermost layer.  This is the deepest drive, the reason for being.  When harnessed, the Dragon layer is a source of unlimited power.  “Harness” is a bad word, because it does not take kindly to being restrained.  But one can come to an understanding with it, learn to flow with it, and maybe it will take you for a ride.  The Dragon seeks to acquire a hoard, and protect it territorially.  Once it has that hoard, its impulse is to curl up on top of it and sleep for a millenium or two.  What is it hoarding?  Assuming this model applies to other people, it’s whatever you are most driven to acquire.  Traditionally, gold.  For me, knowledge (or some conglomerate of knowledge-experience-novelty).  Perhaps there’s more than one dragon with more than one kind of hoard.

Wizard

The Dragon hoards its treasure but is not very discerning.  It just wants what it wants, and acquires it if it’s within view.  The Wizard on the other hand studies the treasure’s secrets.  Some of this treasure is enchanted (or is made, itself, of enchantment).  This enchanted nature is tricky.  Treating some treasure in the right way can increase the hoard or make it disappear.  The Wizard’s job is to manage this enchantment.  Inner discipline.

Footsoldier

There is a lot more to the realm than the highest ideal.  That is where the Footsoldier comes in.  He suffers the grunt work and enjoys the day-to-day pleasures of life.  But in terms of the good of the realm, he is pretty much a conscript, doing what is necessary and no more.  That’s where the Knight comes in.

Knight

The Knight has a sense of duty and honor, and he would gladly take on the daily grunt work and more if necessary.  But there are few Knights and many Footsoldiers, so his job is to train and manage the Footsoldiers, and hopefully inspire them.  In real terms this corresponds to setting up good habits or procedures while in this higher-energy consciousness so that in the lower energy consciousness of the Footsoldier, things run smoothly.  Outer discipline.

Ego

The ego, or subjective self, moves among these archetypes, usually inhabiting one at a time.  Initially, most of the time is spent in Footsoldier consciousness, with occasional spikes of Dragon acquisitiveness.  As the psyche becomes more developed, Knight and Wizard consciousnesses become more common.

Corresponding to Freud’s system, Dragon and Footsoldier make up the Id, while Knight and Wizard make up the Superego.  In the Rao-McCleod heirarchy, the Footsoldiers are Losers, Knights are Clueless, and Dragons and Wizards are Sociopaths.  Going back to Jeremy’s question, Dragon would be the “highest” self in terms of an organizational hierarchy, but these archetypes make more sense as inner vs. outer.  Higher as pure and good doesn’t really apply.  Dragon is at the core, with Wizard, then Knight, then Footsoldier forming concentric rings.  They might shift, but this is their lowest energy state (at least for me).

Posted in Uncategorized | Leave a comment

Get Your Fingers Moving

When you’re blocked in your programming, you may be tempted to try to get your brain in gear, hoping your fingers will follow suit.  You have it backwards.  I’ve become convinced that, short of high doses of caffeine, the only way to get your brain in gear is to just start writing code or creating some other artifact.

When you’re dealing with an existing codebase, or if you’re a fan of unit testing, your impulse might be to write code in small pieces, making sure each one works before starting the next. Sometimes this makes sense, but if this were one of those times, you probably wouldn’t be dealing with a mental block.  You’re probably at work, with a deadline, and you’re convinced that if you could just get out of here, you’d be ten times more productive–after all, you become ten times more productive after everybody goes home.

Your brain is a communication machine.  The ability to think is just a side effect of having to have something to talk about. So get your fingers moving. Your brain will catch up.  Prefer adding new code over editing old code. Back your existing code up, and create a new branch in your version control system, so you can write freely without worrying about what you’re trashing. The time for testing is later; the time for writing is now. Write code that you think will run, but whatever you do, don’t try it until you get the whole thing written. I call this protocode.  You should have a sandbox area on your version control server for this kind of stuff.

If you can’t get you fingers coding, draw diagrams.  If you have no room on the whiteboard, copy it down and erase it.  If you can’t get the diagrams out, write a description of how it should work, or what it should do, or how you’ll know when it’s done.

When it’s done. Then. Try to run it. Fix your syntax errors and your mismatched parameters. Check that it seems to work. Instrument it for more rigorous testing. Do the testing and check it in.  Make it into a building block for for future use.

There’s a limit to how much you should do without testing. It’s probably bigger than you think.

Posted in Uncategorized | Leave a comment

Misc RSS Links

The following are some links that I would delicious if Delicious still worked on my netbook:

http://www.ibm.com/developerworks/webservices/library/ws-pyth11/index.html
Tutorial on a couple Python RSS parsers. RSS.py’s canonical hosting location is a Gist; the other one listed, rssparser.py, broke when I tried to parse my Twitter feed.  Mark Pilgrim (who committed blogicide) is listed as the maintainer, so I guess this is a bit dated.

http://packages.python.org/feedparser/
Python parser for all kinds of RSS and Atom feeds.  I’m going with this one.  Parsed my Twitter and blog feeds.  Apparently the successor to rssparser.py.

http://wiki.python.org/moin/RssLibraries
Articles about various RSS libraries.  Note to self: there is another article about feedparser here.

http://brentlandels.com/site/featured-stories/twitter-tricks-find-your-account-rss-feed-in-the-new-profile-format/
Finding your twitter RSS feed.  Just use the username though, (e.g. “cathodion”) in place of the user number.

Posted in Uncategorized | Leave a comment

A Long Shot

The other night I had a conversation with my friend AJ about what would be necessary for civilization to achieve a significant presence in space–not necessarily interstellar travel, but even colonization of the solar system. This post is mostly a reconstruction of his argument, but I found it depressingly persuasive. Space travel is expensive. Humans haven’t in the last 25 years been more than a couple hundred miles from the surface of the earth. The moon is 250,000 miles away. The nearest planet is millions of miles away.  Going to the moon required the United States, the most prosperous nation on earth, to come together in a way that it hasn’t before or since. And even so, only a handful of people have been to the moon. Less than a dozen I think.

This conversation arose from his complaints about the verisimilitude of Star Trek. According to his theory, the Klingons would never make it into interstellar space. They would destroy themselves with any technology they could develop that can achieve that goal. And so would we, in our current state at least.  Interstellar travel would require a large-scale organization of humanity in one of a couple ways we could think of. One would be what I’ll call the Starfleet option, where everyone is part of a hierarchy much like the US military today. Members of the military go through a period of training and indoctrination, before they’re allowed to participate in any significant way in the military’s operations. When this indoctrination is complete, each member is capable of functioning as part of a grand hierarchy that seems to be a very effective way of organizing a large number of human resources quote-unquote.  (I know there are civilians in the Federation, and that the Federation government is a civilian organization that the Starfleet military hierarchy answers to. This may or may not be compatible with a successful Starfleet-option society.)

The other way is what I will call the Vulcan option. Every member of the species is indoctrinated with a code of ethics encouraging self-sacrifice and a devotion to reason. As Spock said, “The good of the many outweighs the good of the few.  Or the  one.”

The Vulcan option sounds a lot like a religion.  Modern religion, however, would seem to be too divisive. Every major  religion, at least each of the Abrahamic ones, specifies (in one way or another) that other religions are wrong and must be destroyed–even other sects of the same religion.  (The definition of “must be destroyed” varies, of course.)

We were divided about the Romulans. He believed that a culture driven by conquest, even one where all members were loyal to the greater good of that culture, would eventually turn that drive for conquest against itself.

The modern corporation has been successful at organizing a large number of human resources. But since the corporation’s tendency to treat things like environmental damage as “externalities” has contributed a great deal to our current environmental problems, I’m not sure this is the answer we’re looking for.  The externalities could easily kill us.

Another thing that can bring the species together is impending disaster. In Vernor Vinge’s story Long Shot, humanity realizes that the sun is about to explode within a few decades.  The collective effort of humanity is able to produce a ship capable of a one-way, 10,000 year trip to a habitable planet orbiting one of the stars of Alpha Centauri.  The ship has no living passengers, but it is crewed by an artificial intelligence and carries a couple tons of ice protecting some frozen human embryos, and the equipment necessary to gestate them once the ship lands.

Humans’ ability to respond to such a  crisis, however, is called into question by the fact that nearly every scientist agrees on the danger of anthropogenic global warming, but we, collectively, are not able to decrease our carbon emissions enough to have an effect on this.

In order to get our collective eggs out of this very small basket, we need to survive long enough to do so, and to do that we need to develop a sustainable way of life.  Individual selfishness, collective ignorance, and collective divisiveness could doom the human race to be confined to this planet until we go extinct, and to hasten that very extinction.

Could a new social movement change that?  Or would it just become another voice lost in the cacophony?

Posted in Uncategorized | 1 Comment

Making Blogging More Awesome

So I got to thinking about what my next job might be today. I’m a software Developer, and to borrow Neal Stephenson’s terms, I seem to be more of a honer than a forger.  I haven’t developed too many new apps of substance, but (whether through talent or career laziness), I seem to have become very good at troubleshooting and fixing bugs. This seems to be an unglamorous job among software developers, and something they try to quickly get promoted out of, but maybe, I thought, I can turn a weakness into a strength

So my mind turned to blogging in general, and WordPress in particular.  I have gotten a lot of value from blogs and blogging over the years.  I’ve met friends.  Some of those friends have met each other.  There are humans who wouldn’t have been born except for this.  I know they exist: I have played video games with them.  For a while, LiveJournal was my primary social environment.  (I tend to think of LJ as less blogging and more of a social network, but that’s splitting hairs.)  Blogs have given me a constant stream of data flowing through my optic nerves.  They are a vital part of the human hive mind.

There are a few nice things about WordPress.  It’s the predominant blogging platform, but the other features I like are not unique.  It’s open source, and people can host it on their own servers or shared hosting accounts.  This decentralization is important for reasons I’m too tired to articulate at the moment

So how can I make this world more awesome?  For one thing, I should be blogging more.  There’s an intersection between philosophy, fantasy, and real life that blogging is just perfect to explore.  Intersection?  There are whole worlds.

But as a programmer, I should be able to make a contribution to the tools used for blogging, and make a living in the process.  But the nature of that contribution is a bit of a question mark.  Is there bug fixing that is desperately needed?  Plugins?  Updates for the new(ish) mobile world?  I don’t know what the mobile blogging experience is like; I know there are WordPress plugins for mobile, but I also know that the current mobile experience of most blogs sucks.  Or maybe the technology has already matured and the ship has sailed.  Anyway, I think my blog posts like questions better than answers, so I’ll end it here.

Posted in Uncategorized | 3 Comments

Technical Books as Projects

I never seem to be able to read technical books.  It’s fun to buy them, but then I get a little ways in and forget about it.  I usually treat reading as recreation.  Maybe I need to treat reading a technical book as a project.  Now, rather than the twin problems of not being able to read technical books, and not being able to do side projects, I just have the one.

(I can’t take credit for this idea.  There’s a quote somewhere that, “You don’t read programming books; you work through them.”.)

I’m assuming it’s actually worthwhile to read technical books.  I think it’s more fun to just mess around with something until I understand it, occasionally consulting the web where necessary.  Here’s a new format for a programming book: 600 pages, divided into 6 sections.  Each section starts with a 10 page tutorial, followed by 90 pages of reference material for you to consult while you’re messing around with whatever tech the book is about, designed to answer the questions of “so how do I do…?” and “why am i getting this error…?”.

Someone’s probably thought of this idea too.  Know of any books like that for MVC frameworks?

Posted in Uncategorized | Leave a comment