Eric Lippert, a former C# compiler designer at Microsoft, writes about language design, programming concepts, and recreational coding projects.
Commenters call his series classics, citing wizards and warriors, monads and LINQ, Game of Life, and vexing exceptions.
Holy strawmans, Batman! This article sets up a false dichotomy (virtually nobody argues for designing for "future needs", it's more like varying degrees and definitions of "cleanliness"), then gives examples of terrible code at both ends of this dichotomy, and settles it with very mediocre code in the middle. IExternalRuleService? Is that supposed to resemble anything anyone sane would ever do? Do people literally write "Car : Vehicle" out of their 1st year of college anymore?
Let's assume we're all past those strawman examples and talk about the proposed "Balanced Approaches" instead.
ShoppingCart looks to be re-writing an in-memory collection. Is it actually adding anything beyond "Collection<Item>"? (Substitute with whatever collection type you like in your language). Do you actually need a class at all? There simply isn't enough specified in the article to tell. Therefore there's no lesson here: the code as-is shouldn't exist, and we can't tell what ShoppingCart is actually supposed to be doing. If it's making database calls, you have multiple major problems. The best advice I can give in that situation is: don't do, just plan. RemoveItems should take something that can be interpreted into SQL (or whatever's appropriate for the persistence you're using) and return a plan that can be composed with other plans.
IRefuelable, IParkable, IEngineOperable ... these seem to be missing the point that interfaces are defined by their consumers, not by their implementations. You…
So, I don't get all the pain. There are a lot of 'rules' around monads, but conceptually they are widgets in a workflow.
In imperative programming you say what you want to do and do it at the same time.
With monads, you assemble a chain, just like dropping boxes on a workflow UI. Just like a workflow, you have 'defined' what to do, but not done anything with it yet. When you give it input, the chain performs the transforms you have defined for it, and you can pull out the result.
Again, not a 'technical definition' but this paints a picture in people's heads that they can appreciate and follow it up with details.
For serious learning, I recommend Eric Lipperts blog post on the subject:
http://ericlippert.com/category/monads/
Thanks for the link. I hadn't read the interview, though I had read the following by Eric Lippert where he references it:
https://ericlippert.com/2014/03/03/living-with-unchecked-exceptions/
I'm not really a fan of checked exceptions either for the reasons that Anders Hejlsberg outlines in the interview.
However, the bit where he writes:
"I'm a strong believer that if you don't have anything right to say, or anything that moves the art forward, then you'd better just be completely silent and neutral, as opposed to trying to lay out a framework."
Isn't that exactly what has happened with unchecked exceptions in C++ and C#? They've added complexity compared with C style error codes, without actually moving the art forward.
There's an Eric Lippert post from a few years back about working on the C# compiler, where he followed a similar spec-guided approach, with simpler benefits for both making the code clear and making sure the spec was reasonable:
> [...] I wrote all the conversion logic in Roslyn, and I did so for the most part by carefully following the specification. This had two purposes; first, to be sure that I was implementing the actual specification, and second, as yet another chance to ensure that the specification made sense. For much of the conversion code I have methods where each method implements one line of the specification, for this reason.
https://ericlippert.com/2015/05/26/a-different-copy-paste-error/
"[My probabilistic languages] team in particular was at the point where we were regularly putting models into production that on net reduced costs by millions of dollars a year over the cost of the work.
...
We foolishly thought that we would naturally be protected from any layoffs, being a team that reduced costs of any team we partnered with.
...
The whole Probability division was laid off as a cost-cutting measure. I have no explanation for how this was justified and I note that if the company were actually serious about cost-cutting, they would have grown our team, not destroyed it."
https://ericlippert.com/2022/11/30/a-long-expected-update/#:~:text=We%20were%20very,not%20destroyed%20it.
There is a more-or-less comprehensive archive[1] up to 2019 (which should probably be scraped and hoarded). The article in question is there, comments included[2].
Side note: Michael Kaplan’s blog, which Microsoft took down in a remarkably shameful manner, has also been archived[3], while Eric Lippert reposted (most of?) his old articles on his personal WordPress instance[4].
[1] http://bytepointer.com/resources/old_new_thing/index.htm
[2] http://bytepointer.com/resources/old_new_thing/20110921_226_why_do_windows_functions_all_begin_with_a_pointless_mov_edi_edi_instruction.htm
[3] http://archives.miloush.net/michkap/archive/
[4] https://ericlippert.com/