Never trust server’s time for your own sake!

I’ve just had another very useful lesson on what to not do. In one of my school project I have one table in database that represents orders and another that keeps events associated with orders. The latter one simply has an foreign key to order table. Each event has timestamp and a number that references order state after the event. State is stored as a number and it references third table which keeps all numbers with their respective states. To find out which is the current state of an order you simply run a query that selects all events associated with that order and finds out which one is the newest.
Turns out, that’s exactly how not to design a database! While we were showing off our work to our lecturer the strangest thing happened, after he confirmed an order it stayed in the same state as before! Very bad considering that every time an order is confirmed the number of products in warehouse is increased by the amount in the order by application. Confirming the same order more than once is something that should not be possible! And our application did have a check whether the order in a state that allows the next state to be “confirmed”.
My first suspect was the type of event that is inserted would be wrong. We had one such case with the same project earlier. Stupid, but yes, that’s exactly why you need to test everything. That was not the case, quick look on tables showed that this part was correct.
Next was the probability that the database view that displayed each order’s state was incorrect. That was a rather complicated query compared to simple select clause and I didn’t really feel like debugging it. Instead I took another look at the events table. This time I paid attention to the timestamp attribute as well. Imagine my surprise when I saw that the timestamp for the last event was 40 minutes earlier than the event that I know had happened earlier! Apparently while the lecturer was clicking around, confirming orders and such, our lovely server decided to go back in time by 40 minutes!
I wouldn’t have come to that conclusion unless the time wouldn’t be incorrect at the moment.
Simple script echoing time showed 18:05:59 and three seconds later 18:05:02! It was actually about 18:50.
My lesson from this: if you want to keep events like that then keep current state number in the orders’ table as well for each order. Every time when you insert new event update it. This way you get strange result when you print out all events of a certain order but you never find yourself in the position that current state is wrong.

What is boredom?

I haven’t experienced it for couple of weeks at all. And.. I probably won’t until mid-January :D. University keeps me busy with all those things except linear algebra which I did last spring.

Then there’s Spikker for those interested in crosswords, both making and solving. I finished it up to a point and now it just waits for further entries or additional php code.

Programming

I tried out the exercise of Monday’s C exam. It took me nearly three hours without any hurrying. On Friday I’ll have up to four to do the same with new file and requirements. Getting a 5 should be possible. Of course if it were the real world I would have to use dynamic arrays and memory allocation but for now static does the job. By the way if they say that road repair is from 10th to 20th then is it over on 20th or on 21st?
After that some more math and a lot of schemes and facts about computers and physics exam. And then it will finally feel like summer, without all those school responsibilities.
I’ve got several ideas of what I’d like to learn while I have more free time, so I need to figure out where to start from. For those of you who freaked out because I plan to study in summer: it is huge difference when you can pick yourself what, how much and when you learn. And if something more interesting gets in the way you can continue later without worrying about all the deadlines.
But in the end I still have to start from one of them, C and C++, Java or PHP, which I have wanted to learn for more than a year I believe but never got to do it.
And then there’s English. I need to find a way not to forget what I already know. Recently I haven’t used it as much as I used to and it will have consequences. So either English book or tv-programme or some job, which I haven’t found yet.

It’s all mathematicians fault

Another math practice lesson. Topic: Fourier’ series. Someone asked the teacher, where’s the point of this rather theoretical excercise.

We (me and my deskmate) had a short theory about that. At first when mathematicians come up with a new idea, it is rather boring for students to learn, because you can’t apply it yet. They’re not satisfied. Then physisists come up with something new and discover that this seemingly pointless theory mathematicians have is useful. They come up with a great gadget and it is used most often by military in a war. Only after people have survived that they can actually use the gadget to make their life easier, better, etc. Now there are new students learning the same thing and… no one explains what is the theory useful for or that most probably some gadget they use wouldn’t exist or work without mathematicians’ work.
And so everyone blames mathematicians.

Besides, was that bee just crazy? I don’t like to play tag with something size of my thumb and a sting. Is the fragrance of mimosa the same to bees as cat thyme to cats? Fortunately it couldn’t go through two doors as fast as I.