Monday, October 29, 2007

So, to continue from the previous post. Really want to thank God for the course today. :D The trainer's a Canadian, running his own consultancy... he saw my Bible on my desk as I was settling down, and he came over and shook my hand. Gosh. I was stunned - I had just sat down, and suddenly, this big burly Canadian comes over and shakes my hand in front of everyone... But found out that he's a Christian too! :D For a long, long time... in a church as well - in fact, he does the acoustic guitar in his own free time, and has already cut his own album. He gave me a free copy of his own album... w00t! Thank God! So shall listen to it - it's a LOT of songs he's written...

Then got to know more people... very interesting... we were all very quiet... I'm starting to think - seems like most software engineers and IT professionals tend to be very quiet. I wonder why... :P

Anyway, what I learnt in the course... very interesting... concepts of testing... methods, terminology, etc etc.

At the same time I was thinking about what Peter suggested to me the other day about modelling a programming language to be bug-free... "Why not implement something in programming like the electronic logic gates that I worked with last time? So that don't have to spend so much time debugging."

That got me thinking. Why in the world is a car so much more reliable than Windows? If a car were designed like Windows, it would crash at least 2 times a day, run 10 km to the litre, and need to be restarted at least 5 times a day.

So started thinking about the nature of logic gates. Then it struck me: The reason that electronic circuits are so much more predictable and testable than software programs is because electronic circuits are essentially functional in nature. That means, whatever you output will not affect the input. In other words, the circuit is linear. The number of possible states grows linearly.

But the moment you implement state in the electronic circuit (e.g. a flip-flop memory gate using NANDs), your circuit is already teetering on the brink of non-linearity. The possible number of states grow astronomically.

Then I asked myself, "Why don't I simply implement everything using 'virtual' logic gates then? Logically speaking, if you simply hard-code all desired states into your code and ignore all the unwanted states, then your program is essentially 100% verifiable."

Extrapolating the question further, why don't we simply grab our soldering irons and do everything in hardware? After all there are WWII computers that actually work as fast as modern supercomputers, because the WWII computers are hard-wired!

But I realised then that there's a tradeoff: flexibility versus predictability. If you hard-code (or wire), you lose all flexibility and programmability totally. But! If you make it extremely flexible, you make it extremely unpredictable.

One reason the Turing machine (the conceptual framework of modern digital computers) is so powerful as a computing machine is that by simple manipulation of a few states, you are able to compute ANYTHING that can be computed (given sufficient time). But that flexibility comes with a price.

Thus, it struck me that functional programming, which I've been looking into, by itself is not sufficient to eliminate bugs. In fact, it seems to be an inbuilt inevitability that you can't have the best of both worlds: flexibility and predictability. You need to balance.

So what can be done in the world of software engineering? Think it's one thing: Balance. If an application calls for absolute predictability, then hardcode it and eliminate all variables - you can't go wrong with a program that has only one possible outcome. But conversely, if it calls for a lot of flexibility, doing whatever the user wants to do, then you have to factor in for complexity.

Thing is, some programs do not need to be written with memory, just a series of conditional statements. Others need to be. It's a matter of applying the right programming paradigm for the right kind of application.

Perhaps there's a way to determine whether a program is linear or non-linear. Think I gotta read up about chaos theory again. If it's non-linear, then you have to resort to statistical testing - that's the best you can do.

Gee. Just geeky ramblings. :P But hope it helps some poor programmer out there one day... :P

4 comments:

Anonymous said...

Actually I wrote a somewhat long reply, but decided to clear it cos I'm not sure how to reply after all.

I'm not sure if your zealousness for statelessness is lending some bias to your views on computing!

When you are excited about something, be careful to stay balanced in your perception and views.



For example and by the way, it's not fair to compare Windows and cars. Cars are relatively simple machines compared to operating systems. Trottle, brake, clutch, gear shift, steering wheel, parking brake - the driving module takes only 6 parameters.

Cars crash too, if the driver is lousy. It depends on the operator. Windows doesn't crash if you use it right. Mine doesn't crash. For performance and efficiency, there is defrag, msconfig, ccleaner and tweakui. Hey, cars need tuning, optimising and servicing too.

Windows does a million and one things more than a car, and most of the time, it does it well.

Anonymous said...

I'm not sure if your zealousness for statelessness is lending some bias to your views on computing!

When you are excited about something, be careful to stay balanced in your perception and views.


*scratches head* Err... that was totally not what I meant! In fact my post was entirely about investigating into the possibility of whether it is actually possible or not to totally eliminate certain classes of bugs, be it in theory or in practice.

And functional programming, as i had discussed previously, was ONE possible way of eliminating side-effects.

Yes, i'm excited... but can you see where exactly i'm coming from? i'm not espousing statelessness per se - i'm investigating into the possibility that there may actually be a way to totally eliminate certain classes of bugs in programming. In short, I smell A Very Good Idea that may actually transform the entire discipline of software engineering.

Maybe it's a pipe dream... but while i'm working as a software engineer, i'll dream my best for God - and i'll not stop here - 'cos i feel His pleasure when i imagine. :)

But i just need someone more grounded in reality (i.e. you) to help me evaluate and assess these ideas... not shoot them down at once!

Haha... i can see sparks flying now... (as we've done before) "As iron sharpens iron, so one man sharpens another." Sparks'll fly... but let them be bright sparks!

anyway, read my post again... i think it's not that clear, but try again...

Anonymous said...

haha, ya... *smells cordite*

no lah, it was late and I was tired, so maybe I was somewhat terse.. Sorry :)

But I do mean what I said (minus the terseness).

Like what you said, maybe I can pull you down when you're floating away into the ionosphere..

I'm an imaginative person too, and it's great that you are always dreaming big. But must be balanced. Because if your pipe dream is a balanced one, it can lead to realisation.

I can't really place exactly where I got irked. The bottom half of your post is quite balanced. I think it's the overall sense that you get carried away sometimes.

My comment on bias is because while you are excited about the new possibilities you are exploring, you seem to be focusing a lot on the possible plus points, while focusing a lot on the minus points of other paradigms/ways of doing things. Sometimes without thinking fully.



So I pointed out the Windows vs Cars example. In this example, you seem to be saying that because of the functional linear design of cars, they crash less, are more efficient, and do not have to be restarted often. But it seems to me to be an exaggeration of Windows's problems, and the merits of car engineering. I pointed out that this was an unfair comparison, as the complexity of the two are worlds apart. And as a side point, the competency of the operator is a factor that has to be considered too.

Anonymous said...

Hey... Maybe you'll invent a ground-breaking new programming language/paradigm/framework!