Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror

Comment Its about Types (Score 2, Insightful) 612

I think the main issue here is that when you're developing a type system, you generally want the types to classify objects into certain categories that tell you things about them. So if I define some kind of a reference type, what I am saying is that an object of that type is a kind of a pointer to something.

So now, if I allow null references, then my reference type is really saying that "objects of this type are pointers to either something or nothing". That's all well and fine, but it makes the type less precise, in that it conveys less information about the object it is categorizing.

As it turns out, this lack of information is quite important because one of the most common things you have to check when you're given a possibly-null reference is whether or not it is null. You need to insert "if (ptr == NULL)" all over the place. Thus reference types which allow null references ultimately give me less expressive power.

Most of the time null references are created because either an error condition must be reported (e.g. malloc fails), or it is unclear at some point in time whether or not an object exists. Error conditions can be better signalled using exception handling. As for cases where you're not sure if the object exists or not, then one possibility is to use an option type like in Standard ML:

datatype 'a option = SOME of 'a | NONE

This is a polymorphic type that says that either the object exists or it doesn't, and you can find out what the situation is by using a "case" statement on the datatype constructors:

case foo of
    SOME(x) ==> ... [do something with x] ...
| NONE ==> ... [the object doesn't exist] ...

Thus by combining a reference type without nulls with an option type, you can create "reference option" types, which have all the flexibility of "with-null" reference types.

But the cool thing is, you only ever need to check the "null-ness" of the object only once; once you do the check, you're handed a reference object which is guaranteed to be non-null. Thus you can easily partition your code into parts that will do the non-null check and those that assume all references handed to it are valid.

This is why a good type system can make programming so much cleaner and easier :)

Space

Lord British To Conduct Experiments On ISS 60

CR0WTR0B0T writes "Richard Garriott, AKA Lord British, will be part of three experiments on the International Space Station. 'Garriott has a ticket to the space station because he is an orbital spaceflight client of Space Adventures, the only company that provides commercial human space missions ... Garriott will be the first person in space who has had photorefractive keratectomy eye surgery. NASA has approved the PRK procedure for astronauts but has not yet been able to test its effects. Garriott will help scientists figure out if visual acuity of a PRK patient changes in orbit as inner eye pressure increases by up to 50% during space flights.' Mostly, NASA wants to know if he can heal himself or provide resurrection to the other astronauts in case the experiments goes awry."

Comment Graphics Programming (Score 4, Insightful) 1095

Being able to produce pretty pictures is always fun. I learnt programming by spending all my time drawing bouncing balls that changed colour in 320x200 VGA. Of course nowadays kids can use a lot more powerful graphics libraries like the aforementioned SDL, which can let them make a lot cooler stuff.

If he gets the hang of it, you could even teach him how to write a raytracer. That would also be good for his math, and be a nice project where more advanced programming techniques (e.g. data structures, recursion) and more advanced math (calculus, 3D geometry) have practical uses.

Slashdot Top Deals

Slowly and surely the unix crept up on the Nintendo user ...

Working...