Points about Function Pointers
I didn't have enough time to really read through loads of blogs and forums about the function pointers proposal but I did read this PDF. It seems to be like a very straight forward thing: basic function pointers, or delegates if you're familiar with dotNet. There are some points I'd like to make regarding the proposal itself, and then some points from my own experience with dotNet's delegates.
- Removing "final" requirement The paper proposes to not use the same "final" requirement for closures, or annonymous methods, the same way it is required when making annonymous classes. Further, the paper suggests to remove this requirement from annonymous classes as well, as it claims it doesn't offer much anyway, and I tend to agree. The "final" requirement seems to make code more readable by preventing weird situations in multithreading code, but these situations could occur if you write bad code anyway. If I'm mistaken here, and surely there are those who would say I am, please correct me.
- Changing the "throws" syntax The proposal suggests using a vertical bar ( | ) to separate between exceptions that might be thrown from a method. The reason they give is sensible, although I don't like the syntax of 'vbar' they suggest. I much prefer removing the ability to define more than one variable of a function pointer instead of changing the throws syntax to something ugly. That's me, though.
- Autoboxing into interfaces It seems like the idea is to autobox an interface into a function pointer. That means, to my understanding, that interfaces with a function that answers a certain function pointer type could be autoboxed to that function pointer type. This would make it easy for API developers to switch from interfaces to function pointers. The example given in the proposal is the
Runnableinterface, where a function pointer of typevoid()could be used instead. Usually, that would break code, and this is where the autoboxing option comes to the rescue. I think that's a great idea, at least for a while, to help users of APIs adjust to the changed API. I also think that this sort of autoboxing should generate a warning which would help developers to switch their code to the new semantics.