Stupid iPhone SDK

Here's the deal. Aliesha's first-gen Mac Mini is an older machine, a 1.4 GHz PowerPC. We recently upgraded to 1GB of RAM, and a 250 GB hard drive. So, all is good, right? I should be able to start programing iPhone apps, right?

No.

The iPhone SDK requires OS X 10.5.5, at a minimum. The Mini only had 10.4. Another $120 later, and 10.5.6 is installed, and everything is just peachy.

Sort of.

I must say, 10.5 runs great on the Mini. Sure, it's slower than the newer x86-based Macs, but big deal. The fan starts winding up any time an app is opened, but that's not a problem, since OSHA isn't involved. The interface is responsive and beautiful, with all the fancy special effects necessary in today's operating environments.

I installed XCode, Apple's way-cool development environment. Hey, Microsoft! Why does your IDE suck so bad compared to XCode? It'd be nice to know. XCode is simple and slick. I hate the editor, but I hate pretty much any editor except Emacs and vi. Otherwise, it's really nice. As an added bonus, I get to program in Objective-C, my favorite all-around language, and the best of all the C-variant OO languages. Objective-C makes C++ look like it was designed by a bunch of advanced kindergarteners. It makes Java appear to be designed by a soulless corporation for the purpose of destroying coders' will to live.

So that's good.

When I went to create a new iPhone project, though, I didn't have that option. Bwah?

I hadn't paid much attention to the install process. I started up the XCode iPhone SDK installer, and lo and behold! The iPhone SDK portion was greyed-out. There was no chance to install it! "I bet Google can fix this for me," I thought. "Google can fix anything."

And so it was. I did a search, came up with a little patch to help me install the SDK on the PowerPC, and life was good.

At least, it was until last night. See, I'm writing an OpenGL game. It's a simple game, nothing big, but I really wanted to just write a game and be done with it. But the iPhone simulator is giving me fits. Oh, it runs all right. It's really quite spiffy. But: the OpenGL implementation has endian-ness problems! Yes, that's right. The call to glColor4f( red, green, blue, alpha ) screws up the colors because of platform endian-ness. Instead, you get glColor4f( green, red, alpha, blue ) which is not what I want at all. Not at all, I tell you!

So, the solution is to ignore the terrible colors on the iPhone emulator, and just program. But it sucks, because I can't see what it's going to look like. And next I'm going to implement textures. Will that have endian problems as well?

Grrrr. I really, really like the dev environment, and the emulator is damned near perfect. This one little glitch is very frustrating, though.

Lesson 1: Your first program

------------
Introduction
------------

In this lesson, you'll learn what a program is, the differences between compiled and interpreted programs, and what a compiler does. You'll also write your first (and second and third) program.

-------------------------
Programs and machine code
-------------------------

A "program" is a set of instructions that control a computer for a specific task. That's it. That's all a program is.

There are many ways to control a computer, but all of them ultimately come down to "machine code." Machine code is the stuff that controls the Central Processing Unit (CPU) of the computer. Every model of CPU has its own unique "instruction set."

The instruction set is just the definition of the machine code. So, the instruction to add two numbers might be "25 XX YY". XX and YY are the two numbers we want to add. So, the "machine code" to add 1 and 3 would look like this:

25 01 03

And the result will be "04".

This is a simplified view, but that's pretty much how all modern CPUs work.

Wikipedia has an excellent (though technical) write-up. This is a suggested reading, and not required, but this gives a much more thorough overview of instruction sets and machine code:

http://en.wikipedia.org/wiki/Instruction_set

---------------------------------------
Program types: compiled and interpreted
---------------------------------------

All programs *ultimately* come down to machine code. So, your program must eventually operate using machine code. The two simplest ways of doing this is "compiled" programs, and "interpreted" programs.

-----------------
Compiled programs
-----------------

For compiled programs, a "compiler" takes your source code and converts it into machine code. Compilers are simply programs that take text files as input (your source code) and do some magic to produce a single file of executable machine code (your program). The result runs on the CPU directly.

Compiled programs take several steps to get from source code to running program. The steps are:

1) Write source code
2) Compile source code
3) Run executable

Writing compiled programs is generally more difficult than writing interpreted programs. But, since the resulting program runs on the CPU directly, compiled programs are generally much faster than interpreted programs.

--------------------
Interpreted programs
--------------------

Interpreted programs are different. Interpreters take the source code, which instructs the interpreter to perform certain tasks. The source code is never converted to machine code. Instead, the interpreter itself is machine code, and the source code controls the interpreter. So, your program runs on the interpreter. The interpreter is machine code, so it runs directly on the CPU.

Interpreters save a step in developing programs. There are only two steps:

1) Write source code
2) Run the interpreter with your source code

Interpreted programs are faster to write. However, as they run through the interpreter, they are generally much slower than compiled programs.

------------------
Your first program
------------------

The first program you are going to write is an interpreted program. We are going to use an interpreter called "bash." In fact, you are already familiar with this interpreter: you use it every time you run Terminal.

As per usual, there is a great Wikipedia article about bash:

http://en.wikipedia.org/wiki/Bash

When you run Terminal, bash becomes your "shell." A shell is just an interpreter that allows you to type in instructions directly, and will run programs for you. When I refer to a "shell," I'm referring to the Terminal window.

Before you write your first program, type this in a shell:

$ echo Hello, World.

(Don't type the '$'. I use that to indicate you are typing something at a shell prompt.)

What happened?

Now you are ready to write your first program. Fire up Emacs. Open a new file by using the command "c-x c-f". (When using Emacs key bindings, 'c-x' means the ctrl-x: hold down the ctrl key and press the x key.) You don't have to let up on the ctrl key between the 'x' and the 'f'.

Type in the name of the file. Let's call it "hello-world.sh". The ".sh" is a standard ending for shell programs (also called shell scripts). It isn't necessary to add .sh; it's just convenient.

In the window, enter this text:

---[ BEGIN ]-------------------------

echo "Hello, World."

---[ END ]---------------------------

(NOTE: don't add the lines that contain BEGIN and END. I just use those to set out the text you need to put in the file. So with this line, just put in the line that begins "echo".)

Type "c-x c-s" to save the file.

Now, from a shell, execute your program:

$ bash hello-world.sh

(Again, don't type the '$'.)

This command causes your shell (bash) to launch *another* bash with your program. This second bash interpreter runs each line of your program (here, just the one line), and then exits.

So, that's your first program. Congratulations!

Okay, it's a simple program. The "Hello, World" program is a traditional first program. In your programming career, you will likely write that program for every new language you learn. It helps as a gentle introduction to the nuances of each language.

----------------
Making it better
----------------

Wouldn't it be nice if you didn't have to type "bash hello-world.sh" on the command line? There's an easy way to make it so that you can run "hello-world.sh" directly. It requires adding a line to your program, and then telling the shell that the file is executable by setting the right permissions.

First, let's edit the program and make it so it knows which interpreter to use. Open up the hello-world.sh file in Emacs (hint: "c-x c-f"). Make it look like this:

---[ BEGIN ]-------------------------
#!/bin/bash

echo "Hello, World."

---[ END ]---------------------------

The '#!/bin/bash' line should be the very first line -- no spaces or blank lines in front of it. The "#!" characters tell the shell that you are running a program that needs an interpreter. The '/bin/bash' part tells the shell which interpreter to use, using the full path name of the interpreter program.

Save the file. ('c-x c-s')

In your shell, make the program executable. Use the "chmod" (change file modes) command, like this:

$ chmod a+x hello-world.sh

This command gives the execute mode ('x') to all people ('a') for the file 'hello-world.sh'. This will make it so anyone can run this program.

Now, run your program:

$ hello-world.sh

What happened? Is it what you expected?

-------------------------------
Compiled program: hello-world.c
-------------------------------

Now it's time to write your first compiled program. We'll be using the 'C' programming language. This language is the most common language in use today, and is the foundation for many other languages, such as C++, Java, and Objective-C.

In emacs, open a new file called "hello-world.c". This file should contain these lines:

---[ BEGIN ]-------------------------
#include
#include

int
main( int argc, char **argv )
{
printf( "Hello, world!\n" );

exit( 0 );
}
---[ END ]---------------------------

Save this file.

This is a very rudimentary C "program." It's called a program, even though it's not really machine code yet. When compiled, though, it will produce a program that *will* run on the CPU.

The '#include <...>' statements tell the compiler to load up additional files. This is a very important step, one which you'll be exploring for parts of several lessons. Here, we're including some standard "header files." We'll cover header files in the next lesson. At the moment, it's enough to understand that header files define external functions (functions that are not defined in our source code).

After the includes, we have the main program. Every C program has a "main" function. It is always defined like this.

Functions are just bits of programs. They are defined just like "main" is defined above:

int <---- This is the "return type." The procedure will return an integer. There are other types, including "character" types, "float" types, and so on. We'll cover types in the next lesson.

main <---- This is the function name.

( int argc, char **argv ) <---- These are the "arguments" to the function. These are "passed in" to the function when the function is called.

This is how a function is defined. How do you call a function? That's pretty easy, really, and we have two examples in the program. The first is printf.

printf( "Hello, world!\n" );

"printf" if a function that is already defined. It prints something to the terminal. Here, we pass in a "character string." A character is a single letter, such as 'H' or 'e' or so on. A "character string" is a bunch of characters strung together. So, we are passing in a "character string" to the printf function. The '\n' character is a special character: it means "newline," which causes "hello, world" to be printed on its own line.

The other function is "exit." We pass in an integer (in this case, 0).

Don't worry about "types" yet, like integer or character or character string (often called just a "string"). We'll cover types thoroughly in the next lesson. Just be aware that functions take arguments, and can return types.

---------------------------------
Compiling and running the program
---------------------------------

Before we can execute this program, we must first compile it. OS X uses the GNU compiler, gcc. To compile this program, simply issue the following command:

$ gcc hello-world.c

If the compile is successful, it will not print anything at all. If it prints something, there is an error.

Use ls to give a directory listing. What do you see?

There should be a file called 'a.out' in the directory. This is your program. gcc creates the file named 'a.out' by default. You can execute this program directly:

$ a.out

What happens?

Let's tell gcc to create a file with a better name:

$ gcc -o hello-world hello-world.c

The '-o' option is for "output filename." Now you should have a file called "hello-world" in your directory. Run this program.

What's the difference between the a.out file and the hello-world file?

--------
Homework
--------

The questions marked with an asterisk (*) are advanced questions, and may require some extra research.

For problem 1, use the source file "hello-world.c".

1a) Remove the '#include ' line and recompile.

Q1: What happens when you compile the program?

1b) Put the '#include ' line back, and remove the '#include ' line.

Q2: What happens when you compile the program?

*Q3: What do you think the files "stdio.h" and "stdlib.h" do?

2) Write a C program that prints out three lines. Line one is your name, line two is your age, and line three is your favorite food. Compile that program. Use a name other than "hello-world" for both the source code and the compiled program.

Q4: What is a compiled program?

Q5: What is an interpreted program?

Q6: What is your favorite part of this lesson?

Bonus question: What does the command "chmod a-x hello-world.sh" do?

Obama's shout-out to atheists

During President Obama's (I like saying that) inauguration, he mentioned non-believers on equal footing with Christians and Jews And Muslims. Evidently, this stuck in some people's craw (those with craws, anyway).

Let me say something once and for all: this is not a Christian nation, and never was!

That's right. Jefferson, the primary architect of our nation's principles (including liberty and whatnot), was a deist. He was not a Christian. In fact, he penned his own version of the Bible, in which he removed all the mythic nonsense about God, and Jesus being the son of God, and whatnot, leaving "the good bits," the bits about being a kind and generous person, the bits about performing good works, and so on.

George Washington was also a deist, rather than a practising Christian.

So, for all of you who think this nation was founded on Christianity: you're wrong. This is not a Christian nation. It is a nation containing a lot of Christians, but that doesn't make it a Christian nation. No: The United States of America is a secular nation, which means it's not a Christian, Jewish, Muslim, or atheist nation; it is a nation that has no religion at all, and allows its citizens to pursue the belief of their choice.

This is important: if you believe in liberty, you must believe that the US is a secular nation, and that all people are allowed to pursue their own belief (or even lack of belief). If you believe the US is not a secular nation, then you forgo any claims to support of liberty!

(Also: you can't claim victimisation for Christianity when Christians make up 65% (or more) of the nation. Just so you know.)

Anyway, back to President Obama's mention of non-believers: as a non-believer, I am extremely grateful that the President gave me a nod, recognising that I too am part of this nation. Whether you like it or not: I am a part of this nation!

And you know what? Non-believers make better citizens. Yeah, you heard me right. Non-believers are better people. How do I know? Well, you know those "family values" Christian ideologues are always whinging on about? Atheists have fewer divorces than Christians. Let me say that again: atheists tend to have more stable families. Also, although atheists make up anywhere from 15% to 20% of the nation, they only make up about 3% of the prison population. Yes, it's true: atheists are less likely to commit crimes (or get caught, at least).

So stop your whining about how amoral all us atheists are. The facts refute this argument. Atheists are at least as moral as Christians, and probably more so.

Also, as atheism is merely the lack of belief in God, we are less likely to try to push our political agenda. Yes, I've heard the conspiracy theories about how all us atheists with our science are trying to disprove God by teaching evil evolution. That doesn't hold water: science is the process of testing our ideas against reality, so if science supports evolution, it's only because reality supports evolution. And if you don't believe that reality supports evolution, how about you stop taking just about any drug more recent than aspirin. Pretty much all modern medicine is based on the concept that evolution is true. And considering that prayer doesn't heal, good luck. (Prayer doesn't heal. Sorry. Don't believe me? Check out the girl who recently died because her parents prayed for her recovery, rather than taking her to a hospital.)

If I sound angry here, it's because I am. I'm angry at the people who believe that they have the only True Belief, and therefore should be the ones forcing their True Belief on others. I'm angry at those who believe that this nation belongs to only them and their select few Christian friends (all 65% of you). I'm angry that Christianity interferes with proper understanding of reality, pushing creationist bullshit under the guise of "academic freedom." (How about I start teaching every single fucking thought that races through my brain as the gospel truth? How's that for academic freedom? Academic Freedom entails academic responsibility to teach that which best fits our current scientific ontology, because that's our best understanding of the world as it is. Teach your fantasies in Sunday school. Or better yet, don't.)

Listen: I am part of this nation. Atheists (and this includes a lot of folks who call themselves "agnostic;" if you're not sure whether or not god exists, but think he doesn't, you're an atheist) make up 15% to 20% of the population. That number is growing. Get used to it. We are a strong and vital part of this nation, so stop getting your panties in a twist every time we're mentioned in public.

You want us to treat you with respect? Then start treating us with respect. Complaining that we are mentioned in a Presidential speech is not respect. In fact, it's disrespect. I'm generally a turn-the-other-cheek kind of person, but when you are intentionally being disrespectful, I'm more an eye-for-an-eye kind of person. If you want my respect, show me that you respect me as well.

Oh, and if I am disrespectful of particular bits of your belief (such as intelligent design), it's because you are holding that belief contrary to observable reality. I respect reality more than I respect others' beliefs. It's part of what makes me an atheist, I guess.

The philosophic problems of God

I would like to address why an infinite, omniscient, omnipotent God is a philosophically bankrupt concept.

It's simple, really, and can be summed up in a single sentence: This God presents an unworkable epistemology.

First, let me state that I think philosophy has served its purpose, by creating (or discovering) the single effective epistemology: science. Science obsoleted all other epistemologies, as it is the only one that demonstrably and provably produces correct results. There is no other known epistemology that is effective at all, let alone as effective as science.

Now, this isn't to say that science is perfect. Science doesn't really prove things, per se. It's very good at disproving things, though. Once an hypothesis or theory has been disproven, that concept is no longer valid nor accepted. This is important when many ideas compete to explain a set of data. If you can disprove all but one, you have a good candidate for the correct idea.

It's also good at increasing confidence in hypotheses and theories that appear to be correct. Even though our confidence in a concept may never quite reach 100%, we can converge on absolute certainty to within acceptable bounds, to where our confidence and absolute certainty are indistinguishable. (Take, for example, the theory of evolution through natural selection.) The ontology derived from application of the scientific method has many theories that are so close to certain that they are indistinguishable from certain; there are many more theories that are accepted, but not necessarily unassailable; and there are quite a few that are still heavily debated (I'm looking at you, string theory). Further, there are huge areas of ignorance or near-ignorance, such as we have with the origins of the universe.

The demonstrable success of science as an epistemology gives me hope that we will be able to illuminate these dark swaths of ignorance. As I try to base my beliefs on evidence, I point to the historical success of science to not only fill in our ignorance, but to point to hitherto unknown areas of ignorance.

The metaphysics derived from the scientific method is naturalism, a universe which is comprised solely of matter, energy, and the relationships between them. As this metaphysics is derived from the epistemology of science, it is the only metaphysics with a solid foundation.

Now that you know my bias, I will present the exact opposite epistemology:

God.

The problem with an infinite, omniscient, omnipotent God as creator of the universe is simple. Once you assume the universe was created by an omnipotent, omniscient God, you can no longer assume anything about reality. And by that, I mean anything. You can't even assume that reality itself exists.

Reality could be nothing more than a figment of God's imagination. Or, perhaps God created the universe ten seconds ago, with the appearance of antiquity (fossil light from distant galaxies lensed by gravity, for instance). Or perhaps God hasn't created the universe yet, but intends to Any Time Now, and all this that you think is happening at the moment is really just a memory of the "you" created in an hour, simply because God wanted you to have a history.

All of these options are equally valid. The metaphysics based on the epistemology of God is completely undefined, as all potential options of an infinite, omniscient, omnipotent God are limitless.

One might say that science works, and what we observe about the universe is true, including its great antiquity; but that God merely set things in motion. From an epistemological standpoint, that option is no more valid an any other potential option. Choosing any option is completely arbitrary.

If you choose to believe that God created this universe at the Big Bang, and that naturalism has essentially prevailed (with only minor meddling), you do so by corrupting the essence of the one epistemology which is known to work. You introduce the ultimate wild card: "God did it."

And by introducing "God did it," you throw out any claim to a known reality. The epistemology of God doesn't support a knowable, coherent metaphysics.

Why libertarians are wrong

I'm going to beat up on libertarians by creating a straw-man version of them. But, I plan to have fun, and perhaps this little exercise will be cathartic.

Here's the straw-man: Libertarians believe that individuals should choose whether or not to participate in social good. That is, taxes are a form of theft, of the government stealing from you to support their power habits, and to give to the poor, who don't deserve it because they are fat and lazy and probably on drugs, and definitely on welfare.

This version of libertarianism isn't too far from the truth. They rant about this often enough.

Here's my problem with this:

You are part of society. You are gaining by participating in a cooperative society. Therefore, you have obligations to help keep that society as strong as possible. If you don't wish to participate in society, get the hell out. Go someplace where society supports ultimate liberty -- say, Rowanda, or Columbia, where you can do pretty much as you please, as long as you have the money. Granted, others might do unto you that which will benefit them most, but that's what liberty is about, isn't it?

Otherwise, if you are gaining by being a part of society, cowboy up. Stop bitching about how the government is stealing from you. Bullshit. The government is necessary, as are many of the functions the government oversees. These functions are not necessarily ones with which you agree, but I doubt society would be as good without most of them.

"But Tony!" you whine. "Why should I pay taxes to support someone who isn't contributing to society? Why should I help those who are unwilling to help themselves?"

Because, Mister, they don't necessarily have the freedoms you have.

Here's the deal: "freedom" is not equal for all. "Freedom" is another word for "allowed range of action or motion." Now, we wish to maximize freedom as much as possible (which is where the more-appropriate word "liberty" comes into play). However, some people are born with more potential choices in their lives. Some people have more freedom simply by their birthright. In America, this is worsened by simple things, like the terrible way in which we fund our schools (in which the poor neighborhoods have inferior education to the richer neighborhoods). This in turn decreases the range of options open to many, many people in the US.

Don't believe me? Do you think you are able to do all the things that Warren Buffett can do? Well, unless you're Warren Buffett. In which case, welcome to my blog. Oh, and would you like to fund a little independent movie?

So get off your high-horse, Jack. Society gave you the opportunities which you exploited to get where you are today. Society continues to support you. You didn't get your position by being better, or a harder worker, or anything else. You got to where you are because of society, and the freedoms to which you were born.

Now, none of this has to do with liberty. Liberty is the right to perform actions. While freedom can be restricted by a particular situation (such as being poor, or lacking limbs, or so on), liberty cannot. It is an intrinsic right. That doesn't matter, though, as everyone is restricted in some ways, and will not be able to exercise their liberty to the fullest extent.

So that's why libertarians are wrong. Providing the basic minimum comfortable quality of life for those with less opportunity is essential for the preservation of society. And since this is the same society that provides a much greater quality of life for those with greater opportunities, it is our responsibility to contribute.

On the issue of social programs, at least, libertarians, from what I've seen, wish to garner the benefits of our society, while shirking the responsibility of helping to preserve our society.

New XBox 360 interface sucks

So, I updated my XBox 360 the other day to install the new interface. First thing after the reboot, I had to create my "avatar," a stupid-looking model with a limited range of variability that looks suspiciously like a Mii. Even the music played while creating the "avatar" (MS-Mii) was very much like the light-pop-jazz-muzak that is predominant on the Wii.

C'mon, Microsoft, can't you do anything original?

The MS-Mii is used in the new menu system. There's no bloody reason for it whatsoever. He jumps around like he has a happy-crab in his shorts. That's about it. I spent five seconds of my life using the default MS-Mii just for this? That's five seconds of my life I'll never get back!

Then there's the new menu system itself. It fuckin' sucks wormy dog poop through a straw. It's a bit more like a vertical, messy version of the XMB from the PS3. The only advantage it has over the old blade-style menu is that it doesn't have all the fucking ads on every single fucking screen. Other than that, it uses the ubiquitous floor reflections that everyone is using since Apple first used them on their website. Everything is big and ugly, which just makes the whole screen even more of a jumble than the old blade system.

Then, in another "homage" to Nintendo, everything is divided up into channels. Just like the Wii. Oh, happy joy! Now I have even more shit on my screen to suck completely!

All-in-all, it was a completely worthless update. Sure, the XBox 360 seems to have more eye-candy now. But the interface is no more usable than the old blade system, doesn't have the clean simplicity of the XMB, and doesn't make use of the MS-Mii like the Wii did with their Miis.

Really, it seems they are simply trying to steal the thunder of Playstation Home. And to that I say, "Why bother?" Home fucking sucks too.

Please allow myself to introduce myself

Hi, God here. I'm just trying out this new internutz thing lol. I prolly won't write a whole bunch more as you suxorz don't listen to a Me-damned thing I say, but here I am anyway. And I gotta get going soon anyway, since Jonah invited me over for sushi in a little bit.

Class act

For the record:

McCain's concession speech was exceptionally classy. He earned back a tiny bit of the respect he's lost from me. If he could've been that classy during the campaign, he very well might've won.

Passed his bedtime

So, it must be passed McCain's bedtime. He fuckin' caved, and the score's only 338 to 156.

The pussy.

The most important vote

The all-important dog-vote goes to Obama.

As Roscoe says, "McCain can't even raise his arms far enough to throw a fuckin' tennis ball."

Syndicate content