Reentrant programs have a number of advantages: they are easier to test and analyze; automated tools can ensure some types functional correctness, instead of mere syntactic accuracy; but in particular, they are guaranteed not to result in thread conflicts since they only utilize local and passed variables.
Danny Dig's Refactoring for Reentrancy is a program designed to analyze and modify code to bring it back to the functional utopia of reentrance. By converting static variables into local ones and flagging access to global variables or libraries, programmers can more easily ensure the thread-safety of their programs.
The things the Reentrancer can do are interesting, but the things it can't do I find even more interesting. Namely, it has no way to assure the reentrant qualities of library calls, and can only infer it by comparing log files. This reveals an interesting limitation of Java I had not previously considered: you can declare Java methods as static, forcing them to utilize only static variables, but you can't do the opposite; you can't declare Java methods as reentrant, forcing them to utilize only local and passed parameters. The synchronized keyword can simplify the creation of reentrant methods, but it cannot guarantee it. It seems that this would be a useful addition to the Java language, particularly help clarifying certain attributes of library calls.
Functional programmers would argue that its almost nonsensical for a function to behave inconsistently, depending upon a global state. For some insight, I returned to 1890 for a brief conversation with master of logic and nonsense: Lewis Carrol.
Kurt: Mr. Carrol, when do you think it's appropriate for a logical function to return different answers?
Carrol: Well, a close friend of mine once faced this dilemma:
And on mid-summer mornings, she'd slip back in the hole,
To see what the darkness could lend,
But each interaction left her clarity dulled,
Since the liars all claimed they were friends.
And the truth-tellers told her the truth time-to-time,
And at other points offered a joke.
But she never could tell which was which in their rhyme,
Since all of them laughed when they spoke.
Each time they would offer the same foreign names,
And spoke in the same awkward voices.
But it never was clear if their stories were games,
Since each time they would make different choices:
Was it blue he preferred? No, this time it was red,
Though Alice had asked the same question.
She never was sure why the Cheshire said
"You must make your discourse reentrant."
OMG THIS IS SO BOOOOZZZZZZZZZ!
ReplyDelete