Max Lybbert
Posts: 314
Nickname: mlybbert
Registered: Apr, 2005
|
|
Language design
|
Posted: Aug 22, 2006 3:31 PM
|
|
"A better way of thinking is: 'this is easily abused, but programmers who program in this language are smart, so they won't abuse it.'"
Or, perhaps, "this can be bad when XXX, or can be dangerous because YYY, therefore we will ZZZ." Why? Because given a choice between having the programmer's smarts save the day and having the compiler keep track of the details, I'll pick the compiler. I want the feature, but I don't want to be the one to keep things straight.
For instance, people can learn multi-threading in 100-line toy programs, but then they have serious trouble keeping things straight when the program grows to something more realistic. Given a choice between a langauge that says "our programmers are smart enough to keep track of details" and a compiler that keeps track of those details for me, I will likely pick the compiler (so long as I can override the compiler if it's ever wrong).
And how would the compiler keep track of the details? In another thread, I suggested a strongly typed language can guarantee that a variable is locked before access, and unlocked as many times as it's been locked by (1) creating only unlocked_access_variable s, (2) defining a conversion between unlocked_access_variable s and locked_access_variable s that does the necessary locking/unlocking, and (3) defining all functions to take locked_access_variable s.
That doesn't solve deadlock, which is where the language/compiler comes in. The language/compiler can guarantee that a variable is locked in the same order every time regardless of which order the programmer passes it to a function (for instance, by building up a list of variables that a function wants to lock, ordering that list based on some invariant that the compiler knows about {perhaps a unique ID that is assigned to each object upon creation}, and then locking in that order). This would (1) free me from keeping track of a detail, (2) at least not prevent me from locking things by hand if I wanted to, and (3) also not prevent me from using various lock-free techniques if I wanted that as well.
|
|