Skip to content

Commit

Permalink
Prepare article for publication
Browse files Browse the repository at this point in the history
  • Loading branch information
ploeh committed Sep 25, 2023
1 parent a1c167b commit 03d2bb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h3 id="b73fe8b865384190a031e05915227d9a">
<li><a href="/2023/04/17/a-restaurant-example-of-refactoring-from-example-based-to-property-based-testing">A restaurant example of refactoring from example-based to property-based testing</a></li>
<li><a href="/2023/09/04/decomposing-ctfiyhs-sample-code-base">Decomposing CTFiYH's sample code base</a></li>
<li><a href="/2023/09/18/do-orms-reduce-the-need-for-mapping">Do ORMs reduce the need for mapping?</a></li>
<li>The case of the mysterious comparison</li>
<li><a href="/2023/09/25/the-case-of-the-mysterious-comparison">The case of the mysterious comparison</a></li>
</ul>
Some of these articles also use code examples from other sources, or code written specifically for that post, but whenever you see a code example from the <em>restaurant reservation</em> domain, it's from the book's code base.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: post
title: "The case of the mysterious comparison"
description: "A ploeh mystery."
date: 2023-09-14 20:00 UTC
date: 2023-09-25 5:58 UTC
tags: [Code]
---
{% include JB/setup %}
Expand All @@ -12,7 +12,7 @@
<em>{{ page.description }}</em>
</p>
<p>
I was <a href="">recently playing around</a> with the example code from my book <a href="/2021/06/14/new-book-code-that-fits-in-your-head">Code That Fits in Your Head</a>, refactoring the <code>Table</code> class to use <a href="https://blog.ploeh.dk/2022/08/22/can-types-replace-validation/">a predicative NaturalNumber wrapper</a> to represent a table's seating capacity.
I was <a href="/2023/09/18/do-orms-reduce-the-need-for-mapping">recently playing around</a> with the example code from my book <a href="/2021/06/14/new-book-code-that-fits-in-your-head">Code That Fits in Your Head</a>, refactoring the <code>Table</code> class to use <a href="/2022/08/22/can-types-replace-validation">a predicative NaturalNumber wrapper</a> to represent a table's seating capacity.
</p>
<p>
Originally, the <code>Table</code> constructor and corresponding read-only data looked like this:
Expand Down Expand Up @@ -120,7 +120,7 @@ <h3 id="fded951b0b3a4cac848941153e84eaa6">
First, if the immediate solution turns out not to work, you can waste much time trashing, trying various 'fixes' without understanding the problem.
</p>
<p>
Second, even if the resolution is easy, as is the case here, if you don't understand the underlying cause and effect, you can easily build a <a href="https://en.wikipedia.org/wiki/Cargo_cult">cargo cult</a>-like 'understanding' of programming. This could become one such experience: <em>All wrapper types must implement <code>IComparable</code></em>.
Second, even if the resolution is easy, as is the case here, if you don't understand the underlying cause and effect, you can easily build a <a href="https://en.wikipedia.org/wiki/Cargo_cult">cargo cult</a>-like 'understanding' of programming. This could become one such experience: <em>All wrapper types must implement <code>IComparable</code></em>, or some nonsense like that.
</p>
<p>
Unless people are getting hurt or you are bleeding money because of the error, seek first to understand, and only then fix the problem.
Expand Down Expand Up @@ -215,7 +215,7 @@ <h3 id="0db463ec75d64f93a1b188af9fe731f3">
Notice how the first line of code calls <code>Schedule</code>, while the rest is 'just' assertions.
</p>
<p>
Since I had noticed that <code>OrderedEnumerable`1</code> on the stack I was on the lookout for an expression that would sort an <code>IEnumerable&lt;T&gt;</code>. The <code>ScheduleImp</code> method surprised me, though, because the <code>reservations</code> parameter is an array. If there was any problem sorting it, it should have blown up much earlier.
Because I had noticed that <code>OrderedEnumerable`1</code> on the stack, I was on the lookout for an expression that would sort an <code>IEnumerable&lt;T&gt;</code>. The <code>ScheduleImp</code> method surprised me, though, because the <code>reservations</code> parameter is an array. If there was any problem sorting it, it should have blown up much earlier.
</p>
<p>
I really should be paying more attention, but despite my best resolution to proceed methodically, I was chasing the wrong clue.
Expand Down Expand Up @@ -400,7 +400,7 @@ <h3 id="534a507621b840dfb566cdb359261840">
<a href="https://learn.microsoft.com/dotnet/standard/linq/deferred-execution-lazy-evaluation">Deferred execution</a> can confuse even the most experienced programmer. It took me some time before it dawned on me that even though the the <code>MaitreD</code> constructor had run and the object was 'safely' initialised, it actually wasn't.
</p>
<p>
The implication is that there's a 'disconnect' between the constructor and the <code>Allocate</code> method. The error actually happens during initialisation (i.e. in the constructor), but it only manifests when you run the method.
The implication is that there's a 'disconnect' between the constructor and the <code>Allocate</code> method. The error actually happens during initialisation (i.e. in the caller of the constructor), but it only manifests when you run the method.
</p>
<p>
Ever since <a href="/2013/07/20/linq-versus-the-lsp">I discovered the IReadOnlyCollection&lt;T&gt; interface in 2013</a> I've resolved to favour it over <code>IEnumerable&lt;T&gt;</code>. This is one example of why that's a good idea.
Expand Down

0 comments on commit 03d2bb1

Please sign in to comment.