Jach's personal blog

(Largely containing a mind-dump to myselves: past, present, and future)
Current favorite quote: "Supposedly smart people are weirdly ignorant of Bayes' Rule." William B Vogt, 2010

OOP in C with Function Pointers and Structs

In the beginning PyGame book (google around for it) the author presents a text-based Tank Game in Chapter 2 where you select which tanks to shoot and stats accordingly change. It is used as an introduction to object oriented programming. My team at school has to use C to make a video game, but we really want to use OOP-like idioms, and classes really are just glorified structs. However, googling around for how to use function pointers, I never saw a clear way of doing what I wanted: classes in separate source files with static functions. So after a morning of hacking away at it, I figured it out. Here's the source code for the three files:

/* tank.h, the definition for the Tank class */
typedef struct Tank {
/* attributes */
char *name;
int alive;
int ammo;
int armor;

/* methods */
void (*stats)(const struct Tank *);
void (*fire_at)(struct Tank *, struct Tank *);
void (*hit)(struct Tank *);
void (*explode)(struct Tank *);

See Full Post and Comments

A small retraction

I have previously said "90% of philosophy is bullshit". I stand by that, but only because there is just so much bad philosophy!

The 10%, though, is pretty good, and it's not necessarily "easy" (as I generalized). Analytical philosophy, the kind that uses, you know, real propositional logic, is pretty decent. The professional philosophers, the good professors, they are formidable people on the intelligence scale (though I wish they'd do work on more important issues like FAI, but that's another issue).

My distaste for philosophy most certainly comes from my over-exposure to simply bad philosophy, with Rand at the head. I've discovered some interesting stuff, though, and I will try to remain faithful to the good brand if I delve more into the topic myself. (As you may notice I use the 'philosophy' tag kind of loosely; I think most people do.) Where I am likely to have issues with individuals is when they have embraced a philosophy as a religion (like I see with Objectivism: it's called a cult for a reason). Where I'm unlikely to have issues is with individuals who have read lots and lots of professional philosophy, understand the (admittedly simple) propositional logic syntax, and don't shrug me off as insignificant and may desire to enlighten me. I seek truth, but I don't pretend to be well-trained and I'm certain I've made many amateur mistakes.

See Full Post and Comments


I'll admit: I'm a utilitarian. But what does that mean, exactly, and why would I advocate others to follow along as well? Why have a morality anyway?

As I mentioned in my previous post, thanks to several areas of science it is painfully clear that we are not masters in our own homes: much of our decisions, much of our actions, function like clockwork. We've pinned down a number of chemicals in the brain that make you feel a certain way, or make you do certain things. We understand how these feelings got there, too, and it's not a flattering picture. All our "noble" feelings are, in the end, products of evolution: a process which only "wants" copies of genes in the next generation. The selfishness lies at the gene level, and looking around at the world we can see evolution doesn't care beyond that, in fact it doesn't even care about happiness or pain or cruelty. It's a "blind idiot god", whose indifference I would also call cruelty through negligence.

The Darwinian view has been around for some time, and it has been befriended by other forces that combine to "biological determinism" (though really, the word "biological" is unnecessary). It's increasingly difficult to actually blame and punish people for their actions, when it's clear why those actions were undertaken and why there wasn't any other choice for that person. It's like blaming a radio for playing bad music, and smashing it to bits when it plays especially bad music. Basically, it has become increasingly clear that humans are machines, and like machines can be controlled with certain forces.

See Full Post and Comments

Nosce te ipsum

Know thyself. I don't think any greater piece of wisdom was ever uttered. (And yes, I know the original is in Greek not Latin.)

In its naive form, it means to simply be more introspective and keep track of how you change as the years go by. Acknowledge when you are wrong and when you are right, know how you would react under various conditions, learn to predict yourself.

There is a more profound depth to this, though. Start writing all the things you know about yourself, and you'll sooner or later come upon the phrase "I am a human." Note the phrase is "Know thyself", not simply "Know stuff about thyself", and what better way to know yourself than to know how "you" think? How "you" function? And since you are human, you have other humans to study as well. Not just yourself.

See Full Post and Comments

Rooting is not the inverse of exponentiating!

I read someone spreading this lie again the other day, and it annoyed me. Consider addition whose inverse operation is subtraction. The additive inverse is typically expressed like so: a + (-a) = 0, and we make this shorthand to a - a = 0. All subtraction is, is inversed addition.

Consider multiplication, which can be thought of (but isn't necessarily) iterated addition. The multiplicative inverse is expressed like: a * 1/a = 1. In other words, division is multiplication's inverse. (Why is multiplication not necessarily iterated addition? Well, if the numbers are discrete, you're okay. But explain how you can take 2 * pi and add two with itself pi times. 2 * 1.5 is adding two with itself one and a half times (which already sounds strange), in other words take one two, then add it with half of a two. The iterated view isn't necessarily wrong, it's just not helpful after a point.)

Now consider exponentiation, which is often thought of (but isn't necessarily) iterated multiplication. 3^2 is 3 * 3 which is 9, 3^3 is 3 * 3 * 3 which is 27. What's the inverse you ask? Well, for 3^2, take the square root! For 3^3, take the cube root! For x^2 = y, take the square root of (known) y to find (unknown) x! (So long as x and y aren't negative, 'cause we're afraid of complex numbers.) This is all true so far. For 3^x = y, where x is known, the inverse operation to solve for y is indeed the "xth root", which will always be an actual known number. How about when y is known and x isn't? For 3^x = 27, take the... literal xth root... Wait...

See Full Post and Comments