Getting Started with Programming

By Shamus Posted Tuesday Jun 2, 2009

Filed under: Programming 84 comments

The procedural city project resulted in a lot of people emailing me who wanted to know how to get into programming. How to learn? What language? What books are most useful? How do you learn about graphics programming, specifically?

Those are all big questions. I guess the first thing I’d do is make sure you know what you’re getting into. Graphics programming is a very specific sub-discipline of general programming, and jumping right to the graphics stuff is a bit like trying to learn heart surgery before becoming a doctor. It can certainly be done if you really want to learn that way. (Unlike heart surgery, you don’t have to worry about being sued by bereaved next-of-kin for your newbie mistakes. You’ll just crash people’s computers. And Microsoft has proven you can’t go broke doing that.) But jumping into “graphics programming” before learning “programming” is probably not the smoothest route to knowledge. Learning programming isn’t quite the mental challenge medicine is (one assumes, judging by their relative salaries) but like any body of knowledge it does take time to acquire.

Aside from a few COBOL courses in school, I’m entirely self-taught. (The one language I was taught – twice – is the one language I don’t know. I couldn’t generate a single valid line of COBOL to this day.) I imagine the self-taught route is what you have in mind if you’re emailing me. If you were looking for formal education then you’d probably see your guidance counselor or shop for a college. Being an autodidact is fine for enriching your knowledge and understanding of the world, but slightly bad if you’re looking for a career. Even at 37, my earning potential is probably lower than someone with the same experience who can wave around a ~4 year degree. Whether or not that increased earning potential of a degree is worth the risk and expense of taking out loans to pay for one is a really complex question. I come down pretty firmly on the “no” side of the argument, but a lot of coders would argue with me. And the successful ones generally make a lot more than I do. QED.

Jumping in and learning a modern professional-grade language can be a bit much. In the 80’s, most kids were introduced to something much simpler, like BASIC, Logo, or (if they’re quite young) Turtle. I don’t know what kids are taught these days. The point of learning one of these simpler languages is to teach you the basic premise behind programming without getting too bogged down with technical details at the outset. Once you have your head around the idea that source code is a list of instructions that the computer will follow unerringly no matter how wrong they are or what you really intended, you have the basic tools to go learn something useful. It’s a bit like learning to play the piano before you learn another instrument. A piano provides an obvious and straightforward expression of the notes at your disposal, and you’ll usually have gotten a head full of music theory by the time you’ve learned to operate the thing. Then you’ll have a nice foundation to work with while you learn something less straightforward, like string instruments or anything powered by your lungs. In any case, this is a tradeoff: You’re reducing the steepness of the learning curve in exchange for making it longer.

So, assuming you want to learn some graphics programming, don’t mind investing time in generalized programming first, aren’t afraid of a steep learning curve, and aren’t looking to score a degree, then my advice may be of some use to you.

C++ is a good starting language, although there are enthusiastic adherents to many other languages. C# and Python are notable in that both of them can be used to write modern graphics programs. I still recommend going for C++, if for no other reason than the network effect will make it easier to find tutorials. Working in C++ also makes it easier to find unhelpful jerks who will offer snarky answers to earnest questions, which is a major improvement over the smaller languages where you won’t be able to find anyone at all.

I suggest starting with Teach Yourself C++ in 21 Days. Partly because it’s a great book (aside from some nitpicks with the way and the rate at which complex concepts are introduced) but mostly because it’s freely available online. You can also get a dead tree copy, which can be handy. Don’t be put off by the “21 days” stuff. You can blow through the first half-dozen lessons in an afternoon. Things will slow down after that, but the “21 days” stuff is by no means a hard figure and can vary a great deal on how much prior knowledge you have going in and how much time you put into it. I’ve purchased a few copies of the book and given them away to aspiring young programmers over the years.

Sadly, I’ve never found good books or tutorials that teach the concepts beyond language syntax. So, after your 21 days you’ll know how to write a program to balance your checkbook or play blackjack, but you’ll still have no idea how to structure your program by breaking it up into different modules. (That’s fancy programmer talk for putting the source code into different text files.) You’ll have learned nothing of the code formatting holy wars or the particulars of the 1,487 different ways to name variables, each of which has their own zealous adherents. You won’t know about LIB files, what they are, or how to use them. You won’t know about development environments, or MAKE files, or how to read a debug stack. You’ll probably have some idea of what a DLL file is (all windows users have those things floating around on their hard drives like so much driftwood) but you won’t know how to link to one. You won’t know how to really debug your program. (Although you’ll think you will.)

That stuff is 90% of the job, and all of the books and tutorials are focused on that first 10% of learning language syntax and knowing what to type. There are books for refining existing skills in some of those areas, but they’re very much deep-end books that will lose a newcomer in a few pages. We have lots of articles for turning people into programmers, but very little for making them any good.

Thankfully, you can pick up most of that higher-level stuff as you go. I did. (Although I still can’t make use of a debug stack, even after all these years. And it’s not for lack of searching for someone who can explain it in English.)

Once you have some basic knowledge of C++ programming, you’re ready for the graphics stuff. At this point, there is no better place to go than NeHe productions. This is where I went to learn OpenGL. The tutorials on NeHe are some of the best programming tutorials you’ll read. It’s true that most tutorials suck, but the ones at NeHe (particularly the early ones) are simple, compact, straightforward, generously documented, and fun. You can simply download the code and make use of it, or you can read through it on the site along with the instructor’s commentary and explanations. (I highly recommend the latter.)

The site will let you learn by reading the commentary. Or you can learn by example through reading the code. Or you can learn by doing by playing around with (say) lesson 3 and seeing what happens when you plug different numbers in. NeHe isn’t just a collection of the best graphics tutorials around, it’s some of the best programming tutorials of any kind, period. It’s a site that focuses on teaching, rather then simply shoveling information in your direction.

Good luck.

 


 

Team Fortress 2: Poll Results

By Shamus Posted Monday Jun 1, 2009

Filed under: Video Games 68 comments

I was planning on letting the poll run for a few days, but there doesn’t seem to be any point in doing so. While the votes continue to roll in, the overall results haven’t changed in over 24 hours. There is an unmistakable trend here:

(not pictured)de_dust had a score of over +1 million, and it wasnt even on the poll.

Assuming that playing a map you hate is worse than not playing a map you love, I scored it so that each positive vote is worth +1 and each negative vote against a map is worth -1.5. I wanted seven maps, but it looks like there are only six that have an overall favorable rating. (And granary is pretty borderline.) It’s amazing how little the overall shape of this chart changed as the day wore on and more people voted.

Note that while 2fort had the lowest overall score, it was actually #4 in the “love” list. Granary is another controversial map, and the ratio of fans-to-haters remained very close to 3:2, which kept its score near zero. If we ignore the hate votes, then the top scorers are:

1) cp_gravelpit
2) cp_dustbowl
3) cp_badlands
4) ctf_2fort
5) cp_granary
6) cp_steel
7) cp_well

Yesterday I was trying to get on the server, but having no luck. It was at maximum capacity all day. After waiting in line for half an hour, I did the only reasonable thing I could: I used the remote console to boot someone signed up for a second server. There are now two servers: Twenty Sided: Lawful, and the new one: Twenty Sided: Chaotic.

I think Lawful should remain pure, vanilla, and with the broadest possible appeal. I’ll keep the payload maps (I might remove HooDoo, as someone reported it’s heavier than the other maps on slower computers) and use the five maps with large positive scores.

Chaotic can be our server for community maps and controversial stuff like 2fort. I don’t want to go crazy with the community maps, but one or two popular ones (I’m still liking the look and sound of payload “Swift”) would be nice.

Lawful is the priority. If the end of the month rolls around and there is enough money, I’ll renew both. If not, I’ll just renew Lawful and make up the difference myself. So, if you donate, keep in mind this priority. Hopefully the two servers will give us enough room so that we’re not all stuck waiting. Also keep in mind these things are only $30 a month each. You can see the balance here. It’s backwards, though, so negative values are better. Again, no pressure. I don’t want to do the public television thing and make you feel guilty if you don’t pony up. The thing is there to be played. Log on and do your part for the team.

Also, I have a few people in mind to be mods. I’ll be emailing those folks over the next couple of days.

 


 

Example Code

By Shamus Posted Monday Jun 1, 2009

Filed under: Programming 58 comments

Allow me a rant on technical documentation. This has been bugging me lately, and I thought I’d lessen the irritation by inflicting it on you.

The stereotype is that technical people are bad at writing documentation. Technical people are supposedly inept at organizing information, bad at translating technical concepts into plain English, and useless at intuiting what the audience needs to know. There is a reason for this stereotype. It’s completely true.

From manual pages to tutorials, most prose intended to teach the reader something technical is so poorly written that it might as well be in MD5-hashed Cantonese. People have been emailing me for advice on how to learn X or Y in the field of programming. It’s a bit frustrating, because often there is no decent place to send them for the knowledge they desire.

Sometimes people say things like, “Ah man. I tried to learn [programming or scripting language] but it was too hard. I’m just not smart enough to figure that stuff out.” But in many cases I think the problem is less with the student and more with the teacher.

At my day job, I have a primary duty and eleven hundred secondary ones. One of those duties is writing documentation. I do not claim to be a master, but There is a pattern that should be followed when presenting information to a reader. You need to give them an overview of what this document is about so that they don’t waste five minutes reading the thing before they realize they’re on the wrong page. There needs to be a raw presentation of the knowledge (syntax, usage, that sort of thing) and then the in-depth details on the thing, followed by a few working examples. Finally, there should be some links to other related documents in case this isn’t what they were looking for.

Some of my pet peeves:

1. Assumption that the reader will have prior knowledge of some area not directly related to the tutorial. Under no circumstances should you require the user to have a grip on concepts more complex than the one you’re trying to teach. If you’re explaining how to use gas stove, don’t write directions that include “Step 3: Cook dark chocolate soufflé with raspberry sauce.”

2. Writing production-quality code to serve as an example. This is probably the result of someone having “good coding practices” beaten into their heads in college. They learn heaps of dogma about what you “never” do when writing code, and apply that thinking to tutorials. If they were asked to provide a working example of an internal combustion engine, their docs would be the blueprints for a Ford F-150 pickup with fuel injection, anti-lock brakes, power steering, and all the other complexities of modern vehicles. It might be a working example of an internal combustion engine, but it’s not a useful one. It’s much too bloated and complex for the purposes of teaching. A tutorial should be cut down to contain only the concept being demonstrated and the bare minimum of code needed to support it.

Windows interface programs are really bad at this. I once saw one that was supposed to show you how to implement a simple slider control. The full example was a working sound player that let you browse your computer, open wav files, and start and stop sound playback. It had to interface with special libraries for loading and playing sounds, and had lots of little control buttons to access the various features. All of that, just so it could show you a slider control that was used to govern the volume. (Or panning. I can’t remember now.)

3. Over-organization of code. It’s really annoying for someone trying to learn to have to track activity over several source files. Perhaps the tutorial is there to demonstrate how to calculate the distance between two points in three-dimensional space. They start at core of the program in main.cpp, which then calls something in distance.cpp, which references vector.cpp, which at last leads them to math.cpp and the four lines of code they care about:


float delta_x = x1 - x2;
float delta_y = y1 - y2;
float delta_z = z1 - z2;
return sqrt (delta_x * delta_x + delta_y * delta_y + delta_z * delta_z);

Thanks a lot, pal. Why didn’t you just say so in the first place!?!?

I messed around with the DirectX API in the late 90’s, and those example programs suffered from this. Example code should be reduced to the bare number of files possible (one, ideally) and have the minimum level of call depth. You’re trying to teach someone else, not add a shipped title to your resume.

4. Over-use of jargon. Many, many programming tutorials suffer from this. Supposedly there to introduce newcomers to the discipline, they throw words like “rasterization” and “frustum” at the user without the slightest explanation. The reader will need to know these things, but just tossing out these words instead of paraphrasing in non-technical terms (or taking the time to teach them) simply introduces the question of who exactly is going to read this? Anyone sufficiently knowledgeable to parse the text is likely past the point where they need the tutorial.

Terrible: Terms are presented without explanation, leaving the user to try to decipher what is being said; turning the whole thing into an exercise in cryptography.

Acceptable: Terms are defined within the prose, making the text longer and less readable.

Good: Terms are defined at the start of the document, where they can be skipped or studied as needed.

Ideal: Terms are presented as hyperlinks to definitions.

5. Mixing high and low level concepts together. If you’re explaining malloc (), don’t spend three paragraphs talking about memory management and portability issues before you get to the point. If you’re explaining the finer points of memory management, don’t inflict the nitty-gritty details of how to use malloc () on the reader.

What are the worst docs or tutorials you’ve ever been obliged to read?

 


 

Twenty Sided Server: Map Rotation

By Shamus Posted Sunday May 31, 2009

Filed under: Video Games 60 comments

There are varying opinions on what maps should be in the rotation on our Team Fortress 2 server. Strong opinions in some cases. There are maps some people hate. Maps some people love. Maps to which which some people are ambivalent or indifferent. The problem: How to arrange the map list so that the maximum number of people get the maximum number of maps that they love while (more importantly) minimizing the number of people who end up playing a map they hate. Oh, and the map list must meet some minimum level of complexity and variety, rather than just taking one popular map and repeating it endlessly.

Clearly this is an NP-Complete problem. Luckily, we’re only dealing with a list of 13 potential maps. Unluckily, we’re dealing with hundreds and hundreds of people with varying tastes. I’m not sure if I should optimize for maximum happiness or maximum fairness. (Always a problem in any social system.) To wit: Do I throw in maps to satisfy a small minority of users with very unpopular tastes, or do I simply “sacrifice” those few in order to improve the overall happiness of the player base? Hmm.

Coding the proper algorithm is going to take weeks of research and testing. I’ll need to put all of the users into a database along with their preferences, and sort through different map lists and calculate how much each map is loved and hated. Then I’ll need to sort through millions of possible map lists and find the permutation that has the maximum number of satisfied players.

Or maybe I should just take an inaccurate and highly unscientific poll and then eyeball the results? You know what? That sounds pretty good:

[poll id=”4″]

[poll id=”5″]

What about arena maps?

Fie on arena. It has its place and its fans, but the whole idea of arena runs counter to my vision of a fun and newbie-friendly server.

What about payload maps?

Payload maps are a given. All of the payload maps are in rotation. Every other alternating map is payload. The others are capture point or capture the flag.

There are three standard payload maps (Badwater, Goldrush, and HooDoo) plus that crazy dual-payload cart going in both directions. (Pipeline.) I think a good map list will look something like this:

1. Payload Badwater
2. (Map #1)
3. Payload Goldrush
4. (Map #2)
5. Payload HooDoo
6. (Map #3)
7. Payload Badwater
8. (Map #4)
9. Payload Goldrush
10. (Map #5)
11. Payload HooDoo
12. (Map #6)
13. Payload Pipeline
14. (Map #7)

Maps #1 through #7 will be filled in using whatever knowledge I can glean from the polls above. This gives us a list of 11 unique maps, which should give us a nice variety without completely overwhelming newcomers.

 


 

Damien Walters Showreel

By Shamus Posted Saturday May 30, 2009

Filed under: Movies 45 comments


Link (YouTube)

My thoughts:

That one trick at the 55 second mark? Pfft. Big deal. I took off my pants as recently as yesterday, and I did it without the trampoline thing.

More seriously: I always laughed at those wall-run moves in Prince of Persia, but they aren’t all that different from what this guy is doing. And he doesn’t have time-traveling cutlery to bail him out if he messes up.

Jackie Chan is fifty-five years old. As much as I love his work, he’s getting to the point where he probably shouldn’t be back-flipping out of an exploding helicopter into a burning car crusher owned by angry Shaolin monks. I have always wondered who could possibly take his place as the world’s foremost comic kung-fu stunt actor. After seeing this, I nominate Damien Walters. Someone hurry up and get that man into a helicopter made of dynamite and filled with ninjas.

Putting this guy on wires would be insane. The stuff he’s doing on the street already looks fake. (For example, watch this one at the 45 second mark.)

Also: He’s good with kids.

It really is disgusting how much talent some people have. The nerve.

 


 

Twenty Sided Server: Novelty rounds

By Shamus Posted Friday May 29, 2009

Filed under: Video Games 74 comments

On Wednesday night I jumped onto the server and found everyone running around bare-handed, killing each other with taunts. (I did not know this. Apparently certain taunts are instant kills if you can walk up to an enemy and get them to hold still long enough to pull it off. The downside being you have to be close, you’re rooted in place while taunting, and the animation takes a few seconds.) Seeing twenty four people all agree to set aside the established gameplay and run around operating under an impromptu rule set was pretty impressive. The results were hilarious, and I’m confident that such a thing would be impossible on a vast majority of existing servers.

They also did a round where everyone chose the heavy weapons guy class, and did the round using nothing but fists. Citizenparker was good enough to get some screengrabs of the event:

http://www.flickr.com/photos/22871999@N02/sets/72157618889278414/

Thanks to everyone for being so much fun to play with. Thanks also to everyone who donated. (Next month is 2/3 paid for already. Like I said, no sweat if you don’t give, just make sure you log in and say hi. And let me set you on fire.)

Open thread. Perhaps tell us about your most epic moment on the server.

 


 

Stolen Pixels #94: Crysis Demo, Part 3

By Shamus Posted Friday May 29, 2009

Filed under: Column 23 comments

The ending of the Crysis Demo was quite a surprise.

Punchline spoiler: People refuse to believe, but yes. See for yourself.