Thursday, July 9, 2009
Do I need an object for that?
Friday, July 11, 2008
The coder test
int a = 10
int b = 20
a = b
What are the values of a and b after execution of the code above?
If you have programming experience, that's a dumb question. It's designed for beginners. I found it at Coding Horror, in the archives. It's a good test. It determines, with impressive accuracy, whether or not an untrained coder will succeed or fail to pass an introductory programming course (and, by extension, eliminates people who are ill-suited to programming jobs).
What's going on here? Someone new, faced with knowing the 'equals' sign as a comparison operator, sees an implied question mark or a period at the end of each line. Arithmetically, 3 + 4 = 5. Algebraically, 4 + x = 5, x = ?, right? Equals signs are for absolute truth. Yes if the things on each side are the same. No if they are not. Mathematical, logical, rigorous, and familiar.
But this is not a traditional arithmetic problem, or an algebra problem. We begin with "a = 10," and assume that it's true. The parser in your brain says "when I see a, that really means 10." Most of us are comfortable with letters in place of numbers from high school math classes. "b = 20" proceeds the same way. The problem comes when we see the line "a = b." We've just been told that a and b have different values. How, then, can they have the same value?
There are a number of ways to approach this. One way is to refuse to accept a new meaning for the "equals" sign, ignore the last line, and say that a is 10 and b is 20. That's fine, but it's not a programmer's answer.
Another way is to guess. This is not a programmer's answer, either. Neither is shutting down and refusing to answer.
Consciously or unconsciously, a (future) programmer will realize that the familiar "=" glyph no longer has the same meaning. We still say "equals," of course, but it's doing something different: assignment. You could even say that the a, b, 10, and 20 glyphs have taken on new meaning; that's immaterial. What matters is that since all three lines of code are valid, "=" is now doing something different, and you have to figure out what that is. Future McProgrammer figures out a consistent explanation for what the "=" glyph does in this world: the value of the thing on the left takes on the value of the thing on the right. So, after the first line, a stores the value 10. At the end of the program, its value has changed. The ambiguity is resolved, and everything's 20.
This isn't a hard exercise, for someone who can grok basic coding stuff. It's not even an IQ test. It's an "are you a coder type" test. There are 11 more questions to the exam, which I didn't see in the source post or the article it links to. I imagine they test for understanding of recursion, but I don't know.
If they'd give this test to beginners, and discourage people who fail them from careers in computer science, I think the state of CS education could be improved. Intro CS courses could be harder, because instructors wouldn't have to spend time beating the square pegs of non-programmers into programmer-shaped holes. This means less revenue for the University, the the short term; in the long term, though, it probably means more grad students.
(As my coworker Chase Maier pointed out, the problem gets easier if we replace "=" with ":="; the ":=" glyph doesn't exist in anyone's head yet. I think that invalidates the point of the test. It does, however, raise and interesting question: if we teach everyone Pascal, then tell everyone "Java's like Pascal, but
Sunday, July 6, 2008
Landing an interview
On his resume, presumably, you look for five years experience with the language your shop works in, previous jobs, and a bachelor's degree. You do this because it is what everyone else does and it seems to be the best way to hire developers. You choose the best-looking resumes, call the corresponding job candidates, and invite them to interview.
At that interview, what are you looking for? The traditional answer is that you want someone who knows the problem domain and who interacts well with the other people in your office. Joel Spolsky refines this to smart, and get things done. Steve Yegge agrees but reverses the order: done, and get things smart. This is why we have interviews, right? Because you can look at that resume all you want, and you won't know anything about the candidate, except that he can spell.
The best interviewee becomes the new hire. If you're smart, the new hire is technically a short-term contractor, and his first few months on the job function as an extended interview. That way, you can find out if those years of "experience" were actually years "playing minesweeper on the computer at my dad's company and billing out at 40 grand." He passed the contractor phase, and you offer him a permanent position? Congratulations, new hire, you now have a job as a software developer.
End that scenario, in your head. Now pretend that you are the new hire, back before the interview. You want to have something intelligent to put on that resume. The problem is that in order to have those five years of experience when a job comes open, you have to start planning five years before that job exists. You can do "smart," and we'll assume you have the work ethic to fit "get things done." Let's be generous and assume you interview well. If you get the interview, let's say, you get the contract position, in which case you'll be offered the job in six months. So the only problem is to get the interview. How do you do that?
Monday, June 16, 2008
The Tyranny of the idea of the Tyranny of Fun
Allow me to begin by saying that I completely understand, sympathize with, and support a certain degree of masochism. Even needless masochism. I like hard video games and terrible science fiction and the feeling of being exhausted. That's the point of existence. I'm all for esoteric rules that few people can understand. From time to time, I'm even in favor of elitism, at least when "elitism" translates as "It is possible for a thing to be objectively and absolutely better than some other thing." I'll even say that 2nd edition Dungeons and Dragons was just plain more fun than 3e, and 4e looks to be even less enjoyable.
But I don't agree completely with everything James says. There are certainly facts there which are not to be disputed (nestled alongside a chestnut about China that I hope was a joke), but the rest of his post is subjective, needlessly angry elitism. Those damn kids will get off his lawn, I'm sure, because it's eloquent writing. They might even go try a game where losing is likely, and be better off for it. But Wizards of the Coast isn't going to listen, isn't going to give the old-timers who don't like needing miniatures our game back. The Lovecraftian horror of the older RPGs is being replaced by High Fantasy and heroic pipe dreams. Quite frankly, no matter how good it is for young people to learn to lose, it isn't enjoyable. Eventually, everyone wants to win; if they can do so in dramatic fashion, by looking to a table full of little squares and plastic men instead of into their own imaginations, even better. I don't agree with it: if I've won, why keep playing? But it's happened, and it's happened because that is what people want.
What I disagree with the most strongly is the idea that somehow we old-school masochists own the game, even though the designers and people who pay for it now don't. It's an abstraction, an idea, a framework for other ideas. It isn't something to be owned, except in the broadest copyright sense. I can't make something and call it Dungeons and Dragons, but I could sure make a game where females can't have 18/100 strength and dwarf is a class, and nobody would sue me. Ideas that other people came up with don't belong to you by any reasonable stretch of imagination, no matter how much you like them.
The other problem with this elitism and complaint about the dumbing down of the genre is the idea that other people enjoying a different game keeps the rest of us from playing the old way. The words on the pages of the first and second edition games are still there, right? Wizards and Hasbro didn't erase them when they developed fourth edition. Just because I don't like something and don't think that I would enjoy it doesn't mean that it's wrong for other people to enjoy that thing. Heck, if I don't dwell on the sins of these heathens, it's even less likely to bother me.
While I may continue to gripe about the state of games today, about how even kids can finish the blockbuster Xbox 360 shooter on their first try or my beloved D&D has become a wannabe wargame, I have no right to tell anyone else what to enjoy. Yes, they will outnumber people like me, and the publishers will cater more strongly to them. But there are still difficult games with lots of text and no graphics out there. Nobody is going to stop us from playing them. Why not just sit over there and enjoy your first edition while I sit here and enjoy second edition and those guys over there play 3rd and 4th and 7,632nd edition? Why isn't there room?
(As a side note, post-conclusion: why are role-playing games, especially D&D, so susceptible to this sort of generational flamewar? Nobody argues against Super Mario Galaxy because it's 3d and robs you of the joy of 8-bit gaming, or calls the people who own Wiis nasty names for using more hardware. What gives?)
What am I doing?
I wrote a game that was really cool. Scriptable! I mean, high school kids were teaching themselves to program so they could write areas and monsters and spells and quests for this game that I wrote, which was written in Java and scriptable in Jython.
And of course this gets me thinking. This is why I'm learning to program (other people say they can program. My job, as defined by me, is to keep learning. I'll be learning to program until the industry goes away). Wyvern. A game, a kids' game, with poor balance and inexplicable magic. I found it looking for an online version of Dungeons and Dragons, because I was tired of playing D&D with just my little brother (who, by the way, can play a mean 2nd edition fighter). And... wow programming. I knew that it was possible, naturally. Programs do not just happen, someone writes them, and someone had explained this to me.
So Wyvern cost me my high school career and delayed finding girls, which is right and good and happens to all future billionaire coders, right? And it sparked an interest in programming. Made my first year of college easier, because I could do "hello world!" and infinite loops already. Taught me what not to do with game balance and made me feel special because I got to write some guides and a user's manual for the map editor. I started coding because I wanted my own spells in Wyvern. Never did write one.
So Steve Yegge posts this, better than six years after I found his game. It's always been there, kind of in the back of my head, and my characters still exist, including my admin character. But I no longer care about it. The ideas I had for online games are still here in my head, of course, and some of them are pretty good, but I don't want to make video games any more.
What changed? I always knew making games was more like doing math homework than like playing games. (Just for fun, some time, find a kid who thinks he wants to make video games for a living. Show him "hello world," or Tetris if you've written it. He won't want to make games anymore.) I didn't think it would make me rich. Did it seem cool, was that it? Was it the idea of seeing my ideas come to life? I don't know.
Lately, it looks more and more like I'm going to be a web developer, and hack PHP together. That's alright. Maybe it'll be Java for a big, evil corporation. Maybe it'll be freelance work or (fingers crossed) a successful startup. It will not be games, not even for an already-established company. I might have a couple of applets on a personal site to draw hits, if I ever establish a personal site. But it will not be my primary source of income.
Is that a little sad? I don't really think so. Classical games are toys to occupy kids so they don't kill themselves by accident while the grownups are out in the fields producing food, or diversions to give the adults something to do while they talk so they don't run out of things to say. Video games fill the same purposes, but more so; they turn kids into zombies and crush adult conversation entirely, transforming talk about the French Revolution or the last book we read into "Head Shot!" and "Oh, you little bastard!" They're drugs without chemicals.
This isn't to say they're all bad. Even some drugs are good; aspirin, taken during a heart attack, makes you not die sometimes. That's nice. Starcraft teaches resource management and tells a good story, the type you can discuss over Scrabble and coffee. Wesnoth taught me formation tactics and a proper Blitzkrieg. Done properly, in moderation, games can make you smarter and better.
Improperly is too easy, though. Warcraft 3 ate my life; World of Warcraft, Battlefield 2, and Starcraft have done the same things to people I love. You can even play too much Space Invaders, I'm sure.
So, admitting I'm not going to make video games makes me uncool, but I can live with that. Not selling Cocaine would do the same thing, in some circles. I don't think vices ought to be crimes, but I do not like the idea of contributing to anyone's vice, anyway. Goals and dreams and ambitions change over time, it would seem, and that's one of the big ones for me. But it's okay.
There's always database frontends in PHP.
Saturday, June 14, 2008
Feelings of progress
People like to get positive feedback for what we do. It's a recurring theme; schoolchildren are motivated in part by grades, bureaucrats by awards, and young martial artists by achieving that next belt. That's what those things are there for; that "Employee of the Month" award makes you feel good about the work you've done and motivates you to do similarly good work in the future, the green belt motivates you to work toward the brown belt, and that 4.0 GPA makes you stress over continuing to get straight As in the future. It's safe to say that most people are more likely to keep doing a thing if they get positive feedback when they do that thing.
Of course, if the positive feedback is rare, you might forget about it before any more comes along. You might feel like you're grinding endlessly instead of making progress and give up because of it, even if you're making good progress. This is what motivated the belt system in martial arts and the "Employee of the Month" concept in the first place. By rewarding people incrementally with abstract feel-goods that have no direct real-world application, you let them know you've noticed their hard work. You give them a concrete and real award to point to. You give yourself a good worker or student.
At least, that's how it is supposed to work. These systems are broken for me (and for other people, I'm sure). I couldn't make myself care about the next belt in Judo as a kid, and getting good grades is meaningless even now. This doesn't mean that the system is completely broken or useless. There are plenty of effective scholars, people who learn a lot and do good research, who thrive in a graded and regimented system. We've all seen the sitcom character who is perennially employee of the month; both Hank Hill and Spongebob Squarepants thrive on such certificates. The fake awards work much of the time. If they didn't, we would have stopped using them long ago.
I think that's where Sean is coming from in his blog. You're always the right level to fight the monsters around you; why bother with levels at all? Why not just nerf the monsters' hit points and damage to a level commensurate with the player's, and call it good? If you want the player to unlock shiny new powers, you can do that on an area-by-area basis. Single-digit attack damage will be the order of the day from the first area to the final boss, and nobody will spend any time grinding. It's great.
The problem with this is that it removes that constant incremental positive feedback and disconnects the player from his influence over the character's life. Instead of "I have to kill this one more goblin, then I'll level!" the player gets to feel a cold, practical "I have to kill this goblin because he's between me and $story_element." There's no direct reward; even though the player is now closer to finishing your content, he doesn't get the little gold star, the pat on the back that is leveling up.
In an MMO, especially, this would be dangerous. If the player feels unrewarded and uninvolved (Sean talks about just letting the computer pick his character's new attributes at each level in Icewind Dale and games of its ilk; that's a lack of involvement on the player's part), he might as well be watching a movie or reading a book. For people who like books and movies and other passive entertainment, that's great. A lot of games have deep and involved story lines, and sometimes these get missed or glossed over in favor of getting that "OMG MY SWORD IS ON FIRE" spell at the next level. ("Okay, Melchior, yadda yadda Masamune, stop talking so I can see my guy cast Luminaire!")
Overall, I'd say that the experience system is a necessary evil for a lot of games. Many players wouldn't finish games without it. This isn't to say that there's no place for xp-free gaming; I'd love a game where grinding was unnecessary, but I'd also miss the chance to customize my character's abilities. There's even a place for xp-free pencil and paper RPGs. But experience points are not universally a bad idea.
To quote Phil Foglio, "I just made second level!"
Wednesday, June 11, 2008
Victory over inanimate objects
It's even fun when the people aren't hitting each other. More fun, even, because the analysis is easier: watching the instant replay, if not the strike itself, will tell you why that man broke six boards with his fist and that man only broke three. Watching these non-combat events can even teach the viewer about effective use of force, avoiding wasting motion, or more abstract lessons.
Witness yesterday's lunch. I bike home, because this is where the food is, and turn on the television (which still sits in its temporary place on the kitchen counter) on a lark. The channel was Altitude, and the athletes were fighters. "FIGHT SPORTS!" announced the introductory sequence. As it turned out, the fighters were fighting stacks of bricks instead of other human beings; mildly disappointed, I sat to watch a few minutes.
The first fighter, a balding, pudgy and middle aged man who would defeat me handily in any fight, approached the judges. He drew himself up to his full height, which was not much, and stood at rigid attention. He announced his name and his style, both of which I forget, and asked permission to begin.
I assume that this permission was granted. He approached the stack of bricks, which sat upon two cinder blocks and stood as high as the little fellow's armpit. These were not the bricks you build a chimney out of, you understand; these were two inch slabs weakened with sand. They were stacked with gaps between them to allow the competitor to break them one at a time instead of all at once (which would be impossible). There were fifteen of them. The man had chosen this number, hoping that a score of fifteen bricks would be unbeatable and knowing that he couldn't break sixteen.
As it turned out, he couldn't break fifteen, either. He pantomimed an elbow drop a few times, then struck the top of the stack with great theatrical flare and a loud shout. Five bricks broke. Visibly disappointed, he walked away.
The next man was bigger and stronger looking. He approached the judges and gave his name and style in a voice suited to badly dubbed kung-fu films of the old school. He, too, tried to break fifteen bricks. Being taller, he seemed to have an advantage. His pantomimed strikes were played to the audience; his leap was higher, his shout louder. He broke four bricks. He spun too much during his jump, you see, and so did not strike the bricks cleanly. Four bricks out of fifteen.
The TV announcers had a great deal of fun with the next fellow. He wasn't pudgy, he was portly. He had a bear's face and bears hands and sleepy eyes. The commentator mentioned that he's been late to the competition as his children had woken him up after he missed his alarm. He approached the judges and gave his name. They said he could start.
He moseyed sleepily (I swear you would use the same words if you had seen this) to the platform by the bricks. There were eight of them. This man probably had six inches on the first, and a hundred pounds on the second. Both of these are advantages. He used a raised platform to give him more height on the bricks. Again, there were eight. He jumped without a shout, without fanfare, and broke all eight bricks cleanly through the middle: so cleanly, in fact, that they remained standing even though they were plainly broken. He bowed and walked off the stage.
There were more competitors, of course; a great tall fellow who tried ten bricks, a rambo wannabe who tried twelve, a great tall scarecrow who should have been an actor and broke six of seventeen. None of them broke all their bricks, and none of them broke more than eight.
The winner of this competition was a sleepy-eyed fellow who was not afraid to use a platform, who knew the limits of his abilities and didn't overreach himself. He didn't do it dramatically, but he did it well. He can't brag that he did it the hard way, but he can brag that he won. That, my friends, is humility: to know exactly what your abilities are, and to win without showing off.
Sleepy man, I salute you, and thank you for the lesson.