[1+1=2]
OneAndOneIs2

Tue, May 13, 2008

[Link][Icon]Little details

I set my alarm for 3am and went to sleep. Because I tend to sleep lightly when expecting an alarm, I woke at 2:45 and got up. I packed the last few things in to the van, and set off for France. My train was booked for 5:50 and I reckoned on it taking around an hour and three quarters. Plenty of time to get there with the half-hour to spare that they want.

I arrived at 5:00 dead. Plenty of time. Got into the terminal, mooched around a bit.. and then something struck me. Something I hadn't packed. A few bits of dull metal.

The keys to the house!!!

I leave keys in a compartment in my car. That way I always know where they are, and have them with me. It's a great system.

Except, I wasn't IN my car. I was in a hired van. And I hadn't transferred the keys.

*sob*

So at 5:50 when my train left, I was just leaving the terminal to drive to my parents to pick up their keys. THREE HOURS and 140 miles later, I got back to the terminal. I'm now on the 9:50 train, a mere four hours late, having made an already long journey even longer and without even the advantage of having a lie-in before catching the later train.

I hope the trip improves from this start...

2 comments • Categories: Omni, My Life

Mon, May 12, 2008

[Link][Icon]Moving out

A mere seven months after I moved in to it, I'm moving out of this flat.

I packed stuff during the weekend, and loaded it onto the van today. I've been up and down stairs literally all day, and have only recently finished. I'm knackered.

I still have a couple bits that I literally can't cram into the van, so they'll have to wait 'til I come back to do the official bits of paper things with the landlord. But mostly, I'm packed and moved out.

It has been a really miserable day. Gorgeous and sunny, but miserable. And I'm not quite sure why.

I was thoroughly miserable the last time I moved, but that was understandable. I'd lived there happily for years. This place? My reasons for coming here were unhappy ones, I was on a very difficult course that ultimately destroyed my enthusiasm for doing the job it was meant to be training for, I can barely even remember what a social life is... the last seven months have actually been about the unhappiest of my life. It was perfectly common for me to wake up and start crying.

The few happy memories I have of the place are, to put it mildly, bittersweet: The really good friends I made on the course were the best part of the whole thing. But I left the course. And so on.

Why is it so depressing to move out of a place you didn't even like?

Tomorrow, at around 3am, I will rise from my bed and start driving. My train leaves at 6am, I want to be there in plenty of time, and it'll take 1-2 hours to get there. Then it's eight hours or so driving across France to get to my destination.

On Wednesday, I'll unpack. Thursday, I'll just relax and recover from all the exercise. Thursday evening or Friday morning, depending on mood, I'll head back. Depending on when I get back into the area, I may go and visit one of the PGCE people I mentioned above, as it's her birthday. And then I'll be moving briefly back in with my parents for a couple weeks, before setting out for good on a backpacking trip to God knows where.

This time last year, I'd have told you that at this point I'd be on the last few weeks of my school placement, looking forward to the long summer holiday and trying to decide what school I wanted to work at next year.

The best laid plans...

1 comment • Categories: Omni, My Life

Fri, May 09, 2008

[Link][Icon]K&R 4.6

Add the ability to use variables to your calculator.

In a stroke of genius, I initially created a way to assign variables, but forgot to also install a way of calling them. Sigh.

The C answer book redeemed itself a little. After using strcmp in the previous example, when we're still 30-odd pages away from learning its existence, I was not impressed with it. But I thought I was going to have to replace the switch statement with if-else's to be able to do case 'A': case 'B': case 'C':... etc, but it made me realize that putting an 'if' into the 'default:' would solve this one far more easily.

I was also going to create 26 separate variables in the code for the 26 variables in the code, because I hadn't thought enough about it. Creating one array of 26 was of course a much better solution.

Not sure I'll bother with any more of the coding exercises before moving onto the next section.. none leap out at me as particularly interesting. We shall see...

Read more! »

6 comments • Categories: Omni, Programming

Thu, May 08, 2008

[Link][Icon]Pain is your body's way of telling you that something is wrong

I've been told that, in smug tones of voice, by various people, and seen it written down in a number of places.

So. To the people who think it's useful advice:

My body has been telling me the same thing for half a decade. It can safely assume that I have heard the message. Message received and understood. Really.

What the body really needs is a "Reply" button. Something along the lines of "Yes, I know something is wrong. So howsabout you stop telling me about the problem and get on with FIXING it for a change??"

I think maybe it's the hot weather. Misalignment apparently causes inflammation, which is worsened by heat.

So I'm going to go and get the frozen peas out of the freezer. Again.

And if it doesn't help, I'm going to sulk.

2 comments • Categories: Omni, Rant, My Life

[Link][Icon]The perils of packing away

This weekend, I have to get everything I own packed up into boxes. On Monday, I pack all the boxes onto a van, and on Tuesday, I go to France, where all my worldly goods will be stored whilst I go wandering the world.

Trouble is.. it's always fatal, this sort of thing. You keep coming across stuff you'd packed away. In this case, I've started coming across my scuba gear.

I haven't used it in a while. Rotten weather; seasickness; and a club that insisted on doing its dives in the morning so you had to stagger out of bed at 5am on a Saturday if you wanted to go... all sapped my enthusiasm. And then I got into that year or so of trying to save money to cover me for when I left my job, and that really put a stop to it. One thing scuba diving ISN'T is cheap.

So I put the whole hobby on hold, and packed my gear away in the bottom of a wardrobe. My diving website hasn't been updated in years (still gets several hundred hits a month tho...)

But I came to go through my wardrobe to have a clear-out, and there was all my dive gear... as described here if you want to see it.. Ahh, the nostalgia! If not for the fact that the cylinders are out of test and can't be filled, and solo diving is generally banned at most diving sites, I'd probably have gone for a splash-around in all this hot weather.

Ah well. Maybe in a year or two's time, when I'm back from backpacking and have a job and everything.

Trouble is.. when you start thinking about diving in the future, you start thinking about buying new stuff... and the bit of gear I always wanted to get was a rebreather.

About 90% of diving practice is about managing gas: Having enough to breathe, keeping insulated from the colder water, not letting it cause the bends, etc.

Conventional scuba gear, you breathe in from the cylinders full of compressed air on your back, and breathe it out into the water.

As you probably know, the air is roughly 20% Oxygen and 80% Nitrogen. When you breathe out, it's generally in the region of 80% Nitrogen, 17% Oxygen, and 3% Carbon Dioxide.

So there's a lot of useful gas gets wasted when you breathe out if it just bubbles away.

What's more, because pressure goes up by one atmosphere every 10 meters (30 foot), the gas is twice as dense and therefore you waste twice as much at 10 meters. You waste three times as much at 20m, and four times as much at 30m. Etcetera etcetera.

So if, instead, you were to breathe in and out of a bag, you wouldn't lose the gas. Much more efficient.. except you'd die when you used up the Oxygen. But if you plug in a supply of pure Oxygen to keep it topped up, then you would die of CO2 toxicity instead. Unless you put in a scrubber to remove the CO2.

What you have if you do this is a rebreather: You keep breathing the same gas, removing CO2 and adding O2 to keep it at a breathable level. This can make a huge difference: A 30m dive at 20m could use up some 2000 litres of air with a conventional scuba setup; whereas you would use barely 30 litres of Oxygen and the odd few litres of air on a rebreather.

Advantage one: Smaller cylinders and longer dive times.

Your body does nothing with the Nitrogen. It just takes up space in the air supply. What's more, Nitrogen is narcotic, and makes you start to feel drunk from 30-ish meters down. Additionally, Nitrogen is what gives divers the bends: It dissolves into your body fluids at the higher pressures, then comes out of solution as pressure decreases. Just like a bottle of coke starts to fizz when you open the lid. Come up slowly, that excess gas comes out slowly enough to be gotten rid of safely. Come up too fast, and it's like shaking that bottle of coke before opening it.

You might think that breathing pure Oxygen instead of air would therefore be a great idea: No bends and no narcosis.

And it would, if only Oxygen weren't toxic in high concentrations. You can't breathe pure Oxygen deeper than six meters within recreational diving limits.

But you can increase the amount of Oxygen in the mix you breathe, so instead of air at 20% you have Nitrox at 32% or 36% - it'll cut down on the amount of Nitrogen in your body.

You can also breathe higher-Oxygen mixes as you ascend. 50%, 80% and 100% Oxygen are popular for this. After all, if you have too much Nitrogen in your body, breathing in more of the stuff is going to make it harder for your body to get rid of it than breathing pure Oxygen.

Trouble is.. if you want to breathe 32% at the bottom, and then 50% followed by 100% on the way up, you've got to take at least three cylinders. That's getting heavy!

Unless you're on a rebreather, where you can simply add Oxygen to the air until you have whatever Oxygen percentage you want at any time in the dive.

Advantage 2.

Also, you can replace Nitrogen with some other inert gas to stop it being so narcotic. Helium is used here. It's much less narcotic, but sadly it's a lot more expensive.

A rebreather diver uses much less gas per dive: It's a lot cheaper & easier to use Trimix (Helium/Nitrogen/Oxygen) with his equipment.

Advantage 3.

The downsides?

Well, rebreathers are a lot more expensive. They require a completely different skill set. They can go wrong 'silently'. They require more attention and setting up. And so on.

The first rebreather to make it big in the UK was the Buddy Inspiration: The first rebreather to get CE approval. It has three Oxygen sensors to keep track of your breathing mix, and a computer to keep it at the right amount. If the sensors start to disagree, it uses 'voting logic' to decide which to believe. You're supposed to monitor your Oxygen at all times in case the computer gets it wrong.

I wouldn't buy an Inspiration. It'd be too easy to get used to the computer thinking for me, and stop bothering to monitor it. I know I would get complacent.

I'd buy a KISS. This has three sensors, but no computer. It has a valve that puts in Oxygen at roughly the same speed as your body will use it up, and you handle anything else yourself, manually.

Unlike the Inspiration, then, you can't get complacent and leave it to it. You have to monitor it regularly, because your gas WILL go wrong if you don't.

I like that. I like the way the counterlungs (the bags the gas go into when you breathe out) are on the back instead of the front. I like how simple it is, and how many clever features it's got.

When I finally have the time and opportunity to get back into diving, I'll probably buy a KISS and relearn to dive using a rebreather instead.

If nothing else, that plan guarantees it'll be a few years before I start splashing out on dive gear again :o)

Leave a comment • Categories: Omni, My Life

Tue, May 06, 2008

[Link][Icon]My feet hurt

It's a nice sunny day today. And has been for several days. And I had nothing to do.

So I put my new camping stuff into my rucksack and went for a walk.

Not intending to camp out, you understand. Just to check things like the weight and how easy it was to erect the tent.

I was out for a few hours. The ground was STILL thick mud, so I had to go off-path quite a bit. Into brambles. Wearing shorts.

And it was hot. I had a bottle of water, but it didn't last long. Eventually I stopped for lunch, and pitched my tent.

[Tent]

[Tent]

It's a pretty good bit of kit. Astonishingly light, well put-together, and fairly easy to put up. Roomy enough for even my 6'4" self to fit in, and with a space outside to leave my rucksack in.

Then I took it down, packed it back away, and walked another hour or so. All told, I was out nearly three hours. I bought two bottles of drink and an ice-cream while I was out there. They helped.

Overall conclusions:
The new camping stuff was worth the cost. It's light and tough and good at its job.

The Visor Buff is still the comfiest anti-sun headwear I've ever encountered: Keeps the sun out of your eyes and off your neck without any problem.

Espadrills are surprisingly good all-terrain footwear when it's hot.

Taylor's aftershave lotion is the best thing I've ever found to put on my skin. My ankles were scratched to Hell and itching like... something itchy. A liberal smearing of their stuff solved the problem. I guess it makes sense, really: If all you've got is dry skin, any oily gunk will make it feel better. But when it's being applied to freshly-shaved and possibly cut skin.. it's GOT to be good!

And I need a bigger water bottle before I start backpacking properly.

5 comments • Categories: Omni, Health, Exercise, My Life

[Link][Icon]Ehhh..?

K&R 4.5: Add things like sin and pow to the calculator

Okay. So you just put in the math.h library and off you go. Right?

Apparently.. wrong.

It SAYS it works, but it gives me the wrong answers for the sin/cos/tan stuff.

1 s
        0.84147098
2 s
        0.90929743
3 s
        0.14112001

Must have coded it wrong.. right?

So let's try something a bit simpler. A bit of code to calculate sin(0-10):

#include <stdio.h>
#include <math.h>

int main()
{
        int i;

        for (i = 0; i < 11; i++)
                printf("sin %d = %f\n", i, sin(i));
        return 0;
}

Result?

sin 0 = 0.000000
sin 1 = 0.841471
sin 2 = 0.909297
sin 3 = 0.141120
sin 4 = -0.756802
sin 5 = -0.958924
sin 6 = -0.279415
sin 7 = 0.656987
sin 8 = 0.989358
sin 9 = 0.412118
sin 10 = -0.544021

Same numbers that my calculator code gives me.

But not the same numbers that any other scientific calculator I try gives me.

What's going on??

6 comments • Categories: Omni, Programming

Mon, May 05, 2008

[Link][Icon]Why bother?

In reply to some posts recently, questions have been asked such as "Why learn C instead of going straight to Python?" and "Why implement manually something that's in the standard library anyway?"

Rather than just shunt it into a rather long comment, I'm writing a post on the subject. Here it is.

So.. what difference does the language make? Well, let's take the most recent example I've been working on: A calculator.

If you wanted to do addition in assembly, say 6 + 7, you'd have a laborious bit of work to do. You'd have to write code to load the value of the first number, 6, into one memory register; load the value of the second number, 7, into another memory register; and then tell the computer to add the value of the first memory register to the value of the second register and put the new value into a register so you could do something with it later.

In C, which is rather more abstracted from how the computer 'thinks' you can just tell it to create two variables, and print their combined values: int i = 6; int j = 7; printf("%d plus %d equals %d\n" i, j, (i + j)); will do what you want.

In Python? Well, you run the python executable, and type "6 + 7":

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 6 + 7
13
>>>

Doesn't get much easier, does it?

Thing is.. when I tried to learn Python a while ago, I was hamstrung because there was too much basic knowledge I didn't have. I could understand what the code said, but I couldn't have written it myself because I didn't know enough.

Sticking with the calculator example: I've known about reverse Polish notation for a long time. Erwin talked like Yoda for a while because of its 'backward' way of entering the two numbers and THEN telling the calculator what to do with them.

I couldn't imagine, years ago, what possible reason there could be for something as daft as this.

In a normal calculator, to find out six plus seven, you type '6' '+' '7' '=' and get the answer. In this thing, you'd have to do '6' 'enter' '7' 'enter' '+' 'enter'

How inefficient! Why would anybody set it up like this??

Because it's how computers work. They take two numbers and perform a function on them. A normal calculator has to remember the numbers and what function you want it to perform. Reverse Polish notation only remembers the numbers, and just performs the function.

It's much quicker and easier to do the sum in Python. But it doesn't give you any idea what the computer's actually DOING when it does that sum. It just does it. All cleverly automated and simple.

The trouble with automation is, it only works when it works. When it doesn't, you need to be able to do it yourself.

The other day, I was struck by something printf does: It turns a number into an ASCII string for you. How, I wondered, did it do that? The number 182, for instance, is stored as the binary number.. just a second... 10110110

Yes, I just worked that out in my head. I like binary. It's a sickness.

So.. how does 10110110 get turned into a '1', an '8', and a '2'? How does it work it out?

It tells you, in K&R. Take your number, use the modulus operator to find the remainder when you divide it by the base you want. That gets you the last digit of the number. Add that to the char '0' and you've got your first character. Then divide the number by your base. Repeat.

This gets you the number, the wrong way round. So reverse it, and you've done your conversion:

182 % 10 = 2
2 + '0' = '2'
182 / 10 = 18
18 % 10 = 8
8 + '0' = '8'
18 / 10 = 1
1 % 10 = 1
1 + '0' = '1'
1 / 10 = 0
Reverse '2' '8' '1' = '1' '8' '2'

Why does it matter? you might ask. printf() does it all for you. There's no value in doing it that way round.

And you're quite right. A %d in printf() will turn 10110110 into "182". Quick and easy.

But.. what if you don't want the decimal value? Or the oct or hex.. what if you've been told to print the answer it base 7? Base 18? Base 3?

If you know how the number is converted into a string, this is no problem. Just a slightly tedious bit of coding. If you rely totally on printf doing it for you.. Well, you're stuffed. Basically.

Before I started learning C, I couldn't understand why reverse Polish notation had ever existed. Upon having to write a calculator, I've discovered that it's the easiest way to write a calculator program.

Yeah, maybe I could get by without the knowledge. The world is FULL of people that can write all kinds of software without knowing the nuts & bolts of it.

But the world is also full of people that can't use a language that doesn't do garbage collection for them. It's full of people who can only write code where 9/10s of the work has been done for them by somebody else.

The parallels between writing code and using software are fairly blatant. Take Linux: How successful it's becoming recently, with Ubuntu and PCLinuxOS and Suse etc. The numbers of users are going up all the time.

Because a while ago, people were saying "We've got this really good powerful system, but it takes time and effort for people to be able to use it." And they 'fixed' this problem by automating things, stopping people being obliged to do them.

There was a time when you had to compile a custom kernel to get Linux working properly on your system. There was a time when you were unable to use it unless you knew how to use the CLI. There was a time when virtually every Linux user had an opinion on the "vi or emacs?" question.

Trawl through the Ubuntu forums. See just how many users today have to be hand-held through every step of using the CLI when they have a problem. There are people out there using Linux every day who have no idea how to even get to the CLI, let alone how to use it. They don't NEED to know, and they're HAPPY not to.

Good for them.

I'm not.

For me, a Linux computer without a CLI is worse than Windows. I can cope without Firefox, without Pidgin, without VLC.. but not without bash.

Because whilst things being done automatically by a clever bit of software may work 99 times out of 100... that 1 in 100 time can be a killer.

I once lost my grub config file. I booted up to nothing but a grub prompt. It was a 10-second inconvenience, because I know how to use grub, and I told it where to find the kernel and what partition to make the root, and in less than a minute I was back into my fully-functional Linux OS. The average 'new' Ubuntu user? Wouldn't stand a chance.

XMMS wouldn't start once. No error message, it showed up in a 'ps', I just didn't get anything on my screen. Ever. No message telling me why. It just didn't work. Even re-installing it didn't fix it. I launched it from the CLI via the strace command and discovered it was trying to access a /tmp file. Deleting that file fixed the problem. Solving that problem without the CLI? As far as I know, it couldn't be done.

My computer locked up every time I booted once. It got as far as starting the X prompt, and then froze. So I told grub to pass it the "Don't start X" command, scanned the X error messages with less, discovered that it was crashing because it couldn't find /dev/mouse, edited udev's conf file to create a symlink /dev/mouse to /dev/psaux, and then started X manually. Problem solved.

Solved, not by helpful forums or a nearby Linux guru. Solved by me, because I know how to use Linux without all the GUIs and helpful wizards. Because where some people have only ever used Ubuntu, I started with Slackware, moved onto LinuxFromScratch, spent a long time on Gentoo, and only THEN came to try out Ubuntu.

Yes, most of the time, it's pointless knowing what's going on under the hood. The majority of people spend the majority of time not knowing or caring.

I'm not the majority of people.

I don't like helpful software. I don't like having config files I don't know how to edit by hand. I don't want to just shrug and let the standard library do things without having a clue how it does them. I don't like the attitude of "If a language doesn't fix my mistakes, it's a crap language" which is what most "C is rubbish because it doesn't do garbage collection" arguments boil down to.

C isn't a bad language, and it doesn't have memory management problems. The only problem it has is the age-old PEBKAC one. YOU have to use it properly. Languages like Python are a lot more forgiving, but if all you know is Python, then you're going to have the same problems that a user who only knows Ubuntu has: Sometimes, it WON'T do it for you, and you won't know how to do it yourself.

As the old saying goes: Linux is user-friendly. It's just very selective about who its friends are.

I hope that answers the questions about why I'm learning C, and why I'm learning it in the way I am :o)


:: Next Page >>

Categories

May 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Search

Misc

XML Feeds

What is this?
eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

powered by
b2evolution

blank