What's good about Redux
Redux is based on series of really simple what-if questions:
- What if all the data in your app was immutable?
- Okay, now it's stuck. But what if there was only a single solitary mutable variable holding the complete state for your entire app? To change any bit of state, you just assign a slightly different immutable tree to that variable.
- And what if the only way to mutate the state was to create a POJO describing a high-level action, and dispatch it through a single giant processing system, describing the change to make?
TypeScript multicast functions
thisreference is automatically bound to the object it belongs to. In JS a "method" is just an object property that happens to contain a function. If copied into a separate variable and then called, there may or may not be a problem depending on whether the function internally refers to
a function value (known as a "delegate") has operators
-=that allow it to be combined with other compatible functions to create a new single function that, when invoked, causes the constituent functions to be invoked.
The second one is what I'm interested in today, mainly because it's a nice example of something that we can strongly type check in TypeScript. Internally (at the "plumbing" level) we have to bypass type checks, but externally we can guarantee everything will work.
As great as Immutable.js is, especially with a TypeScript declaration included in the package, the
Record class leaves me a little disappointed.
- What does it mean for a programming language to be a superset of another programming language?
- What's a programming language?
- What's a program?
A new kind of managed lvalue pointer
It's already the evening and I haven't yet added anything to the C# compiler today, so here goes!
Properties have special support in C#, but they are not "first class". You can't get a reference to a property and pass it around as a value. Methods are
much better served in this regard: delegates are a way to treat a method as a value. But they are just objects with an
Using pointer syntax as a shorthand for IEnumerable
Another quickie extension to C#. In the current language, a type declaration
T! is shorthand for
But equally important in modern C# programs are sequences of values, so a similar shorthand for
IEnumerable would be ideal.
The asterisk symbol is underused (you can suffix a type with asterisk to make a pointer, but only in unsafe contexts), and
this was the choice made by the intriguing research language Cω
Adding crazily powerful operator overloading to C# 6
I'm going to show you how to enable a new kind of operator overloading by adding exactly four (4) lines of code to a single file in the C# 6 compiler preview. Yes, I was surprised too!
After seeing the video of Anders Hejlsberg showing how easy it is to hack the new open source C# compiler, I had to give it a try.
My aim was (I assumed) a lot more ambitious and crazy than his demo. I thought it would take ages to figure out. But it was still tempting to aim high and actually implement a substantial new feature, because there are a few I've been wondering about over the years.
Ever since LINQ query syntax was added to the language, I've wished that operator overloading worked the same way. The
where keyword gets turned into a
call to a
Where method. And it doesn't matter where or how that method is defined. It can be an extension method, an ordinary method, a
In fact there are few other language features that map to well known member names: a collection initializer is turned into several calls to a method called
Add, and the
await keyword expands into calls to several methods.
This project was a lot of fun, but it has a big roadblock that has to be overcome by any text-based project: internationalisation. Hence I don't see it being generally useful outside of Western-language-only projects without a lot more work.
Here is the demo page, which is very self-explanatory, in that it presents a bunch of information about the editor, inside the editor itself, so you can fiddle with it and instantly see how it persists the text in JSON. As you can see, it's quite far along. In fact I suspect it is already good enough for every way I currently make use of rich text in browser applications. If your browser is old, it will not work. (Hint: IE8 is way old.)
So... Why? What a crazy waste of time when browsers already have the marvellous contentEditable feature, right?