Programmers

Filed in Programming Leave a comment

Programmers have a very precise understanding of truth. You can’t lie to a compiler. Try it sometime. Garbage in, garbage out. Booleans, the ones and zeros, trues and falses, make up the world programmers live in. That’s all there is! I think programming is deep, it teaches us about the non-cyber universe we live in. There’s something spiritual about computers, and I want to understand it.

Programming is good training in the scientific method. For example, last week I spent five hours learning that “50” + 1 = 501 in my scripting system. That truth was available to me the instant I discovered the malfunctioning software, but it took five hours of investigating, digging in, and challenging assumptions before the truth was clear, and I could move on to the next problem.

Programmers build castles out of theorems. Every program is proof that certain input will produce certain output. We build more complex castles, and look for synergies that allow the generality we like and still be approachable in non-mathematical ways. In movies they call this suspension of disbelief. In programming we call it the user interface. Same idea.

In the last few years we’ve learned how to connect programs together producing meta-software built out of programs that come from many different places, from people who don’t even know each other. An amazing evolution has been happening!

When a programmer catches fire it’s because he or she groks the system, its underlying truth has been revealed. I’ve seen this happen many times, a programmer languishes for months, chipping at the edges of a problem. Then all of a sudden, a breakthrough happens, the pieces start fitting together. A few months later the software works, and you go forward.

This process can be very confusing viewed from the outside. If you’re not developing the software yourself, you can still understand the process if you listen to and trust the programmer. It’s a fascinating world inside the machine. When programmers connect with the truth, they want to tell you about it! I promise you. This can make many people uncomfortable, and that’s so unfortunate.

I think, in some ways programmers, who live the scientific method, are better prepared for life than non-programmers, but the opposite is often assumed. We all have a visual image of the programmer, but this is just the outer package. A great programmer is a seeker of truth and beauty. Successful programmers know how to ask questions, and they know how to ask the *right* question. You can’t go forward until that happens. A programmer is a rigorous scientist determined to coax the truth out of the ones and zeros. There’s the beauty.

My pitch to programmers, which is far more revolutionary than any programming language or operating system can be, is to look for understanding where you find it, work with people you want to work with, and don’t waste time with people who won’t listen and aren’t grounded in the truth.

C can be crazy

Filed in Programming Leave a comment

C can be crazy some times.

#include
void(*swap)() = (void(*)()) "\x8b\x44\x24\x04\x8b\x5c\x24\x08\x8b\x00\x8b\x1b\x31\xc3\x31\xd8\x31\xc3\x8b\x4c\x24\x04\x89\x01\x8b\x4c\x24\x08\x89\x19\xc3"
"Oh, there you are Mr. Insanity...";
 
int main(){ // works on GCC 3+4
int a = 37, b = 13;
swap(&a, &b);
 
printf("%d%d",a,b);
}

So, what the fuck is going on?

printf("hello, world\n");
This code, basically, takes a block of raw instructions, stick it into the memory, and gets casted into a function (void(*)()).

In Intel asm, the mnemonics would be as follows:

mov eax, [esp+4]    ;\x8b\x44\x24\x04
mov ebx, [esp+8]    ;\x8b\x5c\x24\x08
mov eax, ds:[eax]   ;\x8b\x00
mov ebx, ds:[ebx]   ;\x8b\x1b
 
xor eax, ebx        ;\x31\xc3
xor ebx, eax        ;\x31\xd8 Actual swapping done here
xor eax, ebx        ;\x31\xc3
 
mov ecx, [esp+4]    ;\x8b\x4c\x24\x04
mov ds[ecx], eax    ;\x89\x01
mov ecx, [esp+8]    ;\x8b\x4c\x24\x08
mov ds[ecx], ebx    ;\x89\x19
 
ret                 ;\xc3

TOP