
Can partial classes solve the expression problem?
Programmers are always defining types and operations to use these types. It's the essence of developing features in working software. The expression problem[1] asks how easy it is to define types and operations in a given programming language or paradigm, and is stated as follows:
Continue reading →"The goal is to define a datatype by cases, where one can add new cases to the datatype and new functions over the datatype, without recompiling existing code, and while retaining static type safety (e.g., no casts)."
LINQ Is Not Quick
Let me just say that I am not particularly a fan of either microbenchmarks or premature optimization. I also feel that LINQ extensions are a fine addition to the .NET standard library. The LINQ query syntax is also an integral part of the C# and F# languages.
That being said, there's an interesting and revealing tale to be told about the performance of LINQ to Objects.
Continue reading →Lazy sequences and streams
Functional languages have the notion of lazy sequences, which are an abstraction of infinite sequences that are stored using a small, finite amount of memory. It would be wasteful to realize an entire infinite sequence before even using it. The basic idea is to only call the function that generates the sequence when needed, and cache the results. With lazy sequences, you don't blow the stack and the elements in the sequence are not recalculated everytime.
Let's look at how the two most popular and functional JVM languages handle lazy sequences.
Continue reading →The WebBrowser nightmare
I recently had to use the WebBrowser
.NET component in a project. The control is essentially Internet Explorer embedded in a UserControl
component. Although the facilities for JavaScript interoperability and DOM manipualtion are pretty great, the control fails to meet simpler needs.
To override keyboard input handing in the control, we need to set the WebBrowserShortcutsEnabled
property to false
and handle the PreviewKeyDown
event.