Day by Day Daily Cartoon by Chris Muir

The Mad Scientist... Mwahahahahahahahaha

Wednesday, January 14, 2009

Programming Languages and Salvation

Ooh, I'm on a roll here.

How do these two compare? But first, some digression to set up the topic.

Here is a 1 year old comparison of the top 5 most popular programming languages in use (source is TIOBE, go ahead and quibble with their stats if you want, but I just want to make a point here).

19.022% Java
15.931% C
10.116% C++
9.161% Visual Basic
8.882% PHP

What do these languages have in common? You won't think they did, really, but here's what - they're not as 'correct' as Ada. Let's take them one at a time.

Java is really popular because it supposedly allows you to write code that's easy to port - move to a different system altogether. It is not strongly typed, though, and it is quite easy to write very buggy code.

C is the quintessential old-school programming language, and has been called the portable assembler, not without reason. Usually, you would use C to write really low level stuff such as device drivers, operating systems, and code for embedded systems. And it is super easy to write WTF code.

C++ is an object-oriented superset of C, which simply means you can write WTF code in even more ways. What fun.

Visual Basic is a Microsoft offering, and it should come as no surprise to everyone that a lot of Windows software is written using VB. And because it looks easy to use, WTFs wander everywhere amongst the VB community. A lot of programmers look down on VB programmers, to be honest.

PHP is really a web-centric scripting language; but even using it in its proper environment WTFs are also everywhere.

Now, let's look at the more 'safe' languages - where it's harder to write code because the language (and the compiler which enforces the language) forces you to write proper code which is more correct and more bug-free - and what are the numbers associated with them? Well...

Pascal (an Algol-variant, and hence kin to Ada) comes in at ~0.67%, and Delphi (another Algol variant) weigs in at 3.3%. C#, a stonger-typed language with Java-like (and hence C-like) syntax, comes in at 5.6%. Ada isn't even in the list.

We now know, therefore, that despite the various weaknesses of the top 5 programming languages, they are in use by over half of the programmers around. But why? All general-purpose programming languages are Turing-complete; that is to say, whatever you want to compute in one, you can theoretically compute in all the others. So why use an unsafe language, when there are plenty of safer ones around? Well, the answer is that programmers don't like safe languages. Let the runtime or the garbage collector take care of potential memory leaks, why should I have to write code that manages this? Why do I have to explicitly typecast? Let the language do the conversion for me. Now I must note here that not all programmers are like this; many just grew up with C, for instance, or its descendants, and Ada is very verbose.

Never mind that. In the early era of Windows, it was a cooperative multitasking environment. Windows 3.x as I mentioned earlier had no notion of security whatsoever. Microsoft assumed that if you screwed stuff up, it was because you didn't mean to (why would anyone deliberately stuff up, after all) , and so its safety precautions were based on that.

Strange, because the first PC virus came on the scene 1986 as a joke. And now, of course, we know that given the right way and the wrong way of doing things, people will inevitably choose the wrong way if it seems easier than the right way. Raymond Chen's blog is replete with examples of such behaviour.

Software engineers and developers, especially those who write operating system code, now know that they can no longer assume the 'user' or programmer to be benign. In fact, their default position is now to consider all the many millions of ways someone can try to break their system, and toughen it up even more. This is why system administrators lock down corporate and public computers, after all.

And now you begin to see how this ties in with salvation. You will not find a single IT guy out there worth his salt, who believes that people are by nature well-behaved on computer systems, they just need the proper knowledge and tools. Not one. To a man they will affirm that most if not all users are either incurably stupid, incorrigibly pig-ignorant, or far more convinced of their skills than they actually are skilled. To make things worse, they themselves slip up too.

Which is what Christians including myself have been saying all this time, really. People are not good by nature. We're lazy. We prefer the easy way, even if it's the wrong way. We're plain bad.

And we need someone who's like us, and yet not like us, to break the cycle.

Tuesday, January 13, 2009

Windows Vista and Jesus Christ

Hah! Betcha you didn't think I could write something coherent about the two subjects, right? Well, I can and I will. But first, some background.

One of the things that people get seriously flustered (and frustrated) about the Christian view (or doctrine) towards Jesus is our insistence that He is dual-natured; both fully God and fully Man (at the same time, but that goes without saying). Some claim He is merely a man (Muslims, you know), others that He is 'only' God (Arians come to mind). Still others say He's half/half. Hmm. Sorta biracial, you might say. Homo sapiens and Theos omnipoten, so to speak. We'll get back to that.


Moving now to the security models adopted by operating systems (and you may see why these security models are needed and how they came to be). in Unix and Unix-based (POSIX) systems, there are two kinds of users; root (superuser) and user. Remember that Unix came about on mainframes and dumb terminals; the root was the administrator and basically did all the systems work, and the users were the ones who ran programs and did their work on the computer. In Unix, it was an all-or-nothing scenario; either you were an ordinary user, or you were root.

The Microsoft approach in MS-DOS, Windows 3.x, and on through the 9x series to Windows ME was different. Because these operating systems ran on Personal Computers (PCs), the concept of root and user had absolutely no meaning, and no distinction was made. In fact, in MS-DOS, you had absolute freedom to do just about anything and everything you wanted.

Windows NT and its successors (Win2K, WinXP, Vista, Win2k3, etc etc etc) supported a more flexible security model. There are several different kinds of actions supported by every 'thing' (or object), and the combination of whether you were allowed to perform certain specific actions determined your security level. This allowed for a more granular control over which user can do what, although in the home, usually it amounted to the Unix model of having 'root' (called Administrator) and 'user' (called Limited User). In the corporate environment, it is possible to be much more fine-grained.

Now, you can probably tell what the shortcomings of the first two approaches were, and why I prefer the NT security model. Unfortunately, because a large number of people moved to Windows 2000 from Windows 9x, which made no security decisions and pretty much amounted to the 'Administrator' security level, a large number of applications made underlying assumptions that only held true if they maintained themselves at that level. Hence, even in Windows XP, if you switched to being a Limited User, oh so many programs got screwed.

In Windows Vista, Microsoft tried to change the way in which Windows worked, so that it was practical to run as Limited User and programs did not break. A lot of very interesting (and to me at least, clever) tricks were pulled off to make this happen, but I am only interested in one scenario; where you ran as a member of the Administrators group.

Strangely enough, in the usual way of things, you were a Limited User. You were given all the protections (and limitations) of the Limited User group... until you needed to do something only Administrators can do. At this point, Windows sort of stops everything and asks you whether you were sure you wanted to do something Administrator-ish. Once you said yes, Windows went ahead and did it, and then bang! you're went back to being still mostly protected as a Limited User. The difference between this and running explicitly as a Limited User is that as a Limited User, you needed to call upon a member of the Administrator group (or know the password, which is the same thing) - in this case, you're using your own authority. Doing something Administrator-ish is called elevating your rights, and when Windows asked you to confirm it, it was prompting for elevation.

Now how Windows Vista does this is not the issue here (in fact, it created two security tokens, IDs if you like, and if you could get away with using the limited one, that's what it did, otherwise it would prompt for elevation). So you could ask the question, "Am I an Administrator, or a Limited User?" The actual answer is, both. And at the same time. Go ahead and check; if you have Office 2007 installed, try to run Excel twice. You should get two windows of Excel, one with Book1, and the other with Book2. But, if you run Excel once, and then again using Run as administrator, both windows of Excel with report as Book1. That is to say, Excel is running both under you as Administrator, and you as Limited User.

Which goes back to the original issue of Jesus' nature; is He God, Man, both, or half of each? The answer is the same; He is both fully God, and fully Man, and at the same time - just as you are fully Administrator, and fully Limited User, at the same time. Now, no analogy is perfect, and the Trinity as well as the dual-nature of Jesus Christ, are and will likely remain mysteries. However, this one comes pretty close.

Are you fully Administrator (otherwise known as God-mode)? Yes; you can pretty much run everything as Administrator. One of the interesting things is that the Administrator token (or ID) is passed on, so if you initially ran Explorer in Administrator mode, everything is thereafter run using the Administrator token.

Are you fully Limited User? Yes; if you answer every elevation prompt (otherwise known as that pesky thing UAC) negatively, your privileges remain that of a Limited User for everything.

Are you both at the same time? Yes; you can mix and match all you like. As you've seen, you can run any program as Administrator and Limited User at once. In fact, that is how you are recognised by Windows, because of your two security tokens - Windows recognises you as both simultaneously, and will treat you in however you want it to.

Here's one more thing. If you were in the system as a normal Limited User, then if you needed to do something in God-mode, you needed the password of the Administrator. This is because you are actually using the authority of the Administrator to do it. In the scenario I created, you don't have to - because that authority is your own, and in your own right. Hmm, sort of like how Jesus could teach with authority, and the others could not, isn't it?


And that is how the topics of Windows Vista and Jesus Christ can be tied together.

Sunday, January 11, 2009

Are those tests useful for anything?

You may notice that I have a few of these personality test results on my blog. Do they mean anything?

Well... yes and no. I'm not trying to brag that I'm a dorky nerd or a geek... not exactly something mainstream guys are likely to admit to, right? Nevertheless, they do provide you some insight into my personality. Although, not the best method around, but it's close.

Strangely enough, I don't like being pigeonholed by others. I can pigeonhole myself, sure, but no one else had better do so. To make it slightly more difficult, I deliberately go out of my way to do stuff I otherwise won't do.

Hence, while my base personality outline is Male, Heterosexual, Christian, Nerd/Geek, there are elements foreign to the stereotypes (or what I perceive the stereotypes to be, any way - you're welcome to correct me).

For example, take a look at the theme I've got running on this blog. It's PINK, ain't it? Not something you'd expect from a guy, but there you are. And I read (present tense) romance novels (and series, like the Sweet Valley High stuff) and older classics like the Anne of Green Gable series. Also, not exactly something you'd expect from a straight guy, no?

Of course, F&SF genres don't usually mix with Christians - at least, some more fundie type Christians. Strange, because I consider myself as one of those fundies - YEC, plain reading of Bible, infallibility of original authographs as dictated by God's Holy Spirit, etc etc etc. But there you are - I'm a huge (A)D&D fan, not to mention Eddings, Feist, Goodkind, and so on.

And, of course, lasciviousness *is* something you'd associate with nerd-types, but hey! I'm not exactly unsociable...

Now, if you were trying to fit me in a category, like the abovementioned 'tests', then overwhelmingly by base type comes out. But some degree of 'skinning' and customisation has occurred, you know?

Friday, January 09, 2009

GeekBlogger Interlude 2

Reading Raymond Chen's blog (The Old New Thing) is an eye opener. Now, to be fair, I do not consider myself a programmer. I can program, true enough. But I'm a WTF programmer. Good enough to know that the code I read is pretty bad code, good enough to see how it can be made better, but crappy enough to know that a fair amount of my code will look like WTFs all by themselves. Nevertheless, I can criticise with the best of them, and providing I lurk long enough, can masquerade as a 'native'.

One of the things that come up in his blog (All The Time) is compatibility. Has anyone ever wondered if you can run 16-bit Windows 3.x code in Windows Vista? You can. You can run 16 bit DOS code in Windows Vista as well, should you really, really want to. And when you consider the sheer differences between the design of DOS (which is not really an OS by modern standards - well, a crappy, minimalistic one at any rate) and the design of Windows 16-bit and Windows 32-bit, this can boggle the mind. Some of the stuff Microsoft programmers manage to pull off will both awe and appall you. It's truly miraculous how Windows manages to run, and run reasonably well (as of writing, my uptime in Vista with two browsers (and ~10 tabs in total), 2 P2P programs, various TSRs - well, the Win32 equivalents thereof - an antivirus, a dual-pane file manager and various sundry programs executed and exited is 318 hours or 13 days 6 hours).

In 64bit Vista/XP, however, you can't. That's because the V86 mode (Virtual 8086) which Windows relies on to do 16-bit code cannot be switched to when you run in 64-bit mode. This is slightly beside the point - even moving between Win9x and WinNT code bases, and heading into WinXP, Raymond Chen and the rest of the Windows core teams had lots of fun (read: blood, toil, tears and sweat, not to mention swear words) ensuring that every buggy piece of Windows software managed to run in the next version of Windows - even when these buggy Windows software did stuff they shouldn't.

That's what compatibility means in the computer world. When we say that Jack and Jill are compatible, we usually mean that they were made for each other. But when some IT geek says Jill is Gina-compatible, he's not talking about lesbian soulmates; oh no, what's he's saying is something to the effect that JILL (e.g. Java Identity Login Layer) can masquerade or take the place of GINA (Graphical Identification aNd Authentication). BTW, I don't think JILL actually exists, okay? I just made it up on the spot. So when Jack goes out with Jill, he's actually thinking he's having a date with Gina. And when he's makin' sweet, sweet love to Jill, he's actually crying out "Gina! Gina! Gina!"

Let's face facts: this situation sucks. Because Jack expects Gina-like behaviour, Jill can't act like herself - even if Jill's way, way smarter, and far prettier, and much better in the sack. It would utterly crash Jack to find out that he's not gettin' jiggy with Gina.

A proposed solution from some people is virtualisation. This is where instead of ensuring Jill behaved and acted like Gina, it was like having a copy of Gina's personality (call her schizo-Jill) instead. That way, Jill remains Jill, and Gina's still Gina.

Now, normally people think of virtualisation as actually installing a virtualisation software like Virtual PC or VMWare or something, but wouldn't it be better if instead of virtualising the whole machine, you only virtualised the high-level stuff? After all, Jill's a Woman, and so is Gina. You don't have to fake the hardware bits much, really, just the parts that matter. Strangely enough, Windows could accommodate that sort of behaviour. And why not? The original Windows NT was designed to be as modular as possible. You had the low-level micro-kernel, the HAL (Hardware Abstraction Layer, which provides a single view of hardware regardless of what it was underneath), and then you had the subsystems which rode on top of the low-level OS. Windows NT and its successors (Win2K, WinXP, WinVista, and soon enough, Win7) supported almost every subsystem there ever was. OS/2 (which was the original default subsystem, believe it or not), DOS, Windows 16-bit (otherwise known as Win16), Windows 32-bit (Win32), Windows 64-bit (presumably Win64), and Unix (via the Interix subsystem). In fact, the only major desktop OS subsystem Windows has never implemented (or have implemented by someone else) on the NT platform is the MacOS - and the Mac's running BSD (a Unix) on Intel processors now. So the idea's not as stupid as it sounds.

One problem. When you speak of a subsystem in NT, what you're actually talking about is the API, or Application Programming Interface. This is a contract - if you're programming on Win32 APIs, it pretty much says that "As long as you promise to do ONLY what is documented functionality in these APIs, we guarantee that as long as we implement Win32 APIs, your program will work flawlessly". In theory, of course. In practice, there are a largish number of programs that don't do this. Instead, they peek and poke into internal structures and directly do stuff assuming these structures will never change. In effect, instead of calling Undress(Girlfriend), they look at what the Undress() procedure did, as well as which structures it was manipulating, and proceeded to call Unfasten(Blouse.Buttons); Unzip(Skirt.Zip); Unhook(Bra.MetalClasp); and so on. And then the next version of Undress() did something different like Unzip(Dress.Zip); Eat(EdibleBra) and the program blew up because it didn't expect that. And yet, both procedures are Undress(). And it is the same Win32 API you're talking about.

Is there a proper solution? I don't know. But it's surely interesting trying to find out :)

Wednesday, January 07, 2009

New Year Stuff

Okay, so the new year has rolled around - Merry Christmas and Happy New Year!

Still on my GeekBlogger Interlude, until the end of Jan, more or less (Chinese New Year falls on Jan 26th, which coincidentally is the very date for Australia Day). So, let's continue to roll, shall we?

When I consider all the possible programming languages in the world (at least those that vaguely look like English), I come back to my first ever programming language learned (aside from scripts/batch files); Ada. What do I like about Ada? Well, pretty much everything, really. It's clean, it's elegant, it's named after the first ever programmer (woman programmer, at that!), it's fully documented, but the biggest thing I love about Ada is that it's really, really hard to write WTF code with it. The IOCCC gives you an idea how easy it is to bugger up C source; doing the same with Ada requires two hundred times the amount of creativity and ingenuity (or sheer bad luck).

C is, as many people have put it, a portable assembler. We're not exactly at the MOV AX, CX level when we use C, but you can certainly emit some seriously bollixed source code in C. There are programming languages out there that will compile whatever you write (the compilers for these languages pretty much modify your code until it does something, just not necessarily what you want or thought it would do); Ada compilers pretty much sit on your code until you fix everything.

Considering that Ada is a real-time, concurrent, multi-threading, object-oriented language used by the military all over the world, it's really no wonder it's mighty hard to bring down. But see, here's the thing. If you learn to code in Ada, switching to any other language is going to suck balls, and suck hard. In Ada, there's a lot of stuff that the compiler enforces on you that other languages call 'good coding practices'. If you write code in Ada, it's practically impossible to get buffer overruns - simply because the language prevents it. Move over to another language, much less strongly typed and where your input is not sanitised... say, VB, or even C++, and bye bye! to your compiler checks.

Of course, you could always emit Ada-like code in such languages, but you also have to write your own buffer-overflow detection and prevention code. And that's stupid - the compiler should do that for you.

So, yeah, anyways, I like Ada a lot.