A small remark on programming conditionals. This is true for C and C++, but it might be true also for Java and other languages. I haven’t checked all of them.
It is about conditionals.
I’m seeing lots and lots of double OR and double AND in conditionals. In fact, I find it rare to see a single single operator these days. (Sorry, I couldn’t resist the pun). Almost without exception, every multiple conditional I see has the form:
if ((x>0) || (x<MAX_VAL))
Which is kind of silly, really. What one should do is use the simple single-operator
if ((x>0) | (x<MAX_VAL))
We had an issue at work. Our dev. team is managing a php server, which sends and receives binary KET files of constant size (say, 5kb) to production servers. I was rewriting some of the production servers and I notices that sometimes I’m getting TLE files in instead of KET files, and that they are 11 byte too big.
I checked it out. Apparently the dev. team was sending the KET files for compression (via php gzcompress). They were very much surprised to learn that the output files were larger than the original KETs. “Apparently”, they sighed, “gzip is not a very good compression. Let’s find another one”.
Which is the wrong conclusion. They have a meagre chance of finding a compression engine which wouldn’t expand the files. And this is a good excuse to explain this to the rest of the world.
An introduction to data compression
Pigeon hole principle → no general compression scheme possible.
Range limitation → Data redundancy → range-specific compression possible.
Prima facie, compression is an impossible task.
A few years back, a friend bought me Bernard Lewis’ “What went wrong” and asked me for a review. This is somewhat late – but you might find it interesting.
Lewis’ starting points seem obvious: is the 13th century, Islam was the future. The Islamic centers in Mesopotamia were the peak of civilization. 700 years later, Islamic Mesopotamia is poor and sordid.
He is searching for an answer in culture. That seemed weird to me. Culturally, the east – and especially the Islamic east – was not a lethargic culture.
And I think I have a better explanation now.
A nice keyboard
Ever so often I stumble across another annoying feature Microsoft is putting into their products. It never ceases to amaze me how creative the folks at Microsoft are at mis-designing products. Their products are always sleek, elegant, easy to use, and contain some hidden monstrosity under the folds.
At work, we have Microsoft Keyboards – just the most unbelievably hideous trap ever to be inflicted upon the unsuspecting world. The keyboard look nice enough, and is OK to use. Look at the picture. Notice those three little flat keys just between the ENTER and the numpad? Above the upper-arrow and below the “delete” key lurks a monster. Yes, it is a SHUTDOWN KEY! In the middle of the keyboard!
Need I tell you the details? You type a document, send out your little finger to press “up” or “del”, and all of a sudden the computer is shutting itself off.
And today I encountered another trap, at home. Here I am working at my computer (sometimes I still use MS windows, you see). And out of the blue pops a message. “Do you want to save?”. Well, why would I, in the middle of a messy revision? I press ESC, and the computer shuts down. Got me: It had an automatic update that was so much more important than my work…
So, shut down your automatic updates on Windows, double check MS products before you buy them, etc. All these advice work, but in my experience, they don’t work very well. remember: MS will always have the upper hand. There’s always another snark hidden beneath the table, ready to jump at you when you least expect it.
Below are several short tips which will help you survive C programming. I’ll be adding and amending this from time to time.
The most terrifying aspect of the C programming language is closely related to it’s core strength. Programming in C is all about using pointers – which are memory locations. Thus, in C, when you need a variable to work with to store numbers and manipulate them, you don’t have to deal with the variable directly – you use it’s address, instead. This is, of course, a really stupid thing to do when you just have to use a single variable to store a single number. But it is an enormously useful strategy when sending that variable off to a distant procedure, or when dealing with large arrays.
The usual strategy in this Blog is to wait until the recent, important event is old and all public interest is lost, before I comment on it.
This is not because I abhor of readership, but because I feel that in order to say an intelligent thing about a subject, I need time to contemplate. This time I did the contemplation before it happened. So I am about to do my thing while the wikileaks scandal is still raging. Here are my 2 cents. And I will start with the sound-byte:
19 year-old boys are not adults. Give these boys weapons (the ultimate in big-boom-generating toys), train them to kill, and send them on to a conflict-ridden zone. Now, guess: what they will do there?
If you even imagine that they will do anything other than killing, then you’re a damn fool.
The army is not the problem. It is simply not the solution. You can’t expect a bunch of kids with big guns to build a nation state. Nor should you send them on to do serious police work. It is not their job, it is not their expertise. You train them to fight a war, send them out to face an enemy, and they find themselves in the middle of civilian population. Anyone seriously suggesting that no atrocities will ensue is either a god-damn lier, or pathologically stupid.
Let me repeat myself, at the risk of being crude:
An army is not a peace-keeping force. It is a fighting force.