<?xml version='1.0' encoding='utf-8' ?>

<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Snail#</title>
  <link>https://snailsharp.dreamwidth.org/</link>
  <description>Snail# - Dreamwidth Studios</description>
  <lastBuildDate>Thu, 23 Mar 2023 20:31:48 GMT</lastBuildDate>
  <generator>LiveJournal / Dreamwidth Studios</generator>
  <lj:journal>snailsharp</lj:journal>
  <lj:journaltype>community</lj:journaltype>
  <image>
    <url>https://v2.dreamwidth.org/16164916/4065555</url>
    <title>Snail#</title>
    <link>https://snailsharp.dreamwidth.org/</link>
    <width>100</width>
    <height>100</height>
  </image>

<item>
  <guid isPermaLink='true'>https://snailsharp.dreamwidth.org/2995.html</guid>
  <pubDate>Thu, 23 Mar 2023 20:31:48 GMT</pubDate>
  <title>Using F# collections in C# records for immutability and structural equality</title>
  <link>https://snailsharp.dreamwidth.org/2995.html</link>
  <description>Posted by: &lt;span lj:user=&apos;isaacschemm&apos; style=&apos;white-space: nowrap;&apos; class=&apos;ljuser&apos;&gt;&lt;a href=&apos;https://isaacschemm.dreamwidth.org/profile&apos;&gt;&lt;img src=&apos;https://www.dreamwidth.org/img/silk/identity/user.png&apos; alt=&apos;[personal profile] &apos; width=&apos;17&apos; height=&apos;17&apos; style=&apos;vertical-align: text-bottom; border: 0; padding-right: 1px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;https://isaacschemm.dreamwidth.org/&apos;&gt;&lt;b&gt;isaacschemm&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
    &lt;p&gt;When working in .NET, it can be awkward to figure out whether two
      objects are &quot;equal&quot;. With reference types, two variables might
      refer to the same object on the heap, or to two different objects
      with identical properties. In the picture below, changing Snail
      C&apos;s shirt would also change Snail B&apos;s, because they are the same
      snail, while the otherwise identical Snail A is unchanged.&lt;br&gt;
    &lt;/p&gt;
    &lt;p&gt;&lt;img src=&quot;https://isaacschemm.dreamwidth.org/file/22869.png&quot; alt=&quot;A points to one drawing, B and C both point to another        identical drawing; A is not equal to B, but B is equal to C&quot; title=&quot;&quot;&gt; &lt;/p&gt;
    &lt;p&gt;Value types are more like C structs. So giving Snail C a jacket
      and hat does not affect Snail B. It wouldn&apos;t make sense to do a
      &quot;reference comparison&quot; on a value type; the objects are always
      stored in different places (setting aside explicit pointers to
      objects in memory, of course - something C# also allows for).&lt;br&gt;
    &lt;/p&gt;
    &lt;img src=&quot;https://isaacschemm.dreamwidth.org/file/22718.png&quot; alt=&quot;A      and B point to separate but identical drawings, and are equal; C      points to a different drawing, where the snail has a hat, and is      not equal to B&quot; title=&quot;&quot;&gt;
    &lt;p&gt; Immutable types with built-in structural equality checks are a
      great way to work around this issue, but there&apos;s still the
      question of what to do for collection types - the standard .NET
      HashSet, List and Array types aren&apos;t immutable, and even
      ImmutableList and ImmutableSet don&apos;t consider two lists or two
      sets with the same items to be &quot;equal&quot;. But there&apos;s a very easy
      way to handle this problem: you can use the collection types in
      the F# standard library (FSharp.Core), even without using F#.&lt;/p&gt;
    &lt;span class=&quot;cut-wrapper&quot;&gt;&lt;span style=&quot;display: none;&quot; id=&quot;span-cuttag___1&quot; class=&quot;cuttag&quot;&gt;&lt;/span&gt;&lt;b class=&quot;cut-open&quot;&gt;(&amp;nbsp;&lt;/b&gt;&lt;b class=&quot;cut-text&quot;&gt;&lt;a href=&quot;https://snailsharp.dreamwidth.org/2995.html#cutid1&quot;&gt;Read more...&lt;/a&gt;&lt;/b&gt;&lt;b class=&quot;cut-close&quot;&gt;&amp;nbsp;)&lt;/b&gt;&lt;/span&gt;&lt;div style=&quot;display: none;&quot; id=&quot;div-cuttag___1&quot; aria-live=&quot;assertive&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=snailsharp&amp;ditemid=2995&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://snailsharp.dreamwidth.org/2995.html</comments>
  <category>fsharp</category>
  <category>csharp</category>
  <category>dotnet</category>
  <lj:security>public</lj:security>
  <lj:poster>isaacschemm</lj:poster>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://snailsharp.dreamwidth.org/2111.html</guid>
  <pubDate>Thu, 19 Jan 2023 21:08:31 GMT</pubDate>
  <title>This whole blog post is also a .NET UTF-32 string library</title>
  <link>https://snailsharp.dreamwidth.org/2111.html</link>
  <description>Posted by: &lt;span lj:user=&apos;isaacschemm&apos; style=&apos;white-space: nowrap;&apos; class=&apos;ljuser&apos;&gt;&lt;a href=&apos;https://isaacschemm.dreamwidth.org/profile&apos;&gt;&lt;img src=&apos;https://www.dreamwidth.org/img/silk/identity/user.png&apos; alt=&apos;[personal profile] &apos; width=&apos;17&apos; height=&apos;17&apos; style=&apos;vertical-align: text-bottom; border: 0; padding-right: 1px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;https://isaacschemm.dreamwidth.org/&apos;&gt;&lt;b&gt;isaacschemm&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;hljs&quot; style=&quot;display: block; overflow-x: auto; padding: 0.5em; background: rgb(240, 240, 240); color: rgb(68, 68, 68);&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// UTF-32 is a Unicode encoding that uses exactly four bytes for each&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// codepoint. Unlike UTF-8 (used widely on the Web) or UTF-16 (used in Java&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// and .NET), each codepoint / character takes up the same number of bytes,&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// making it much easier to do string processing (counting, substrings) based&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// on character count.&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// One common application is applying styling or custom behavior to Twitter&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// posts based on the data provided by the API:&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: rgb(136, 136, 136);&quot;&gt;// https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities&lt;/span&gt;
&lt;/pre&gt;
&lt;span class=&quot;cut-wrapper&quot;&gt;&lt;span style=&quot;display: none;&quot; id=&quot;span-cuttag___1&quot; class=&quot;cuttag&quot;&gt;&lt;/span&gt;&lt;b class=&quot;cut-open&quot;&gt;(&amp;nbsp;&lt;/b&gt;&lt;b class=&quot;cut-text&quot;&gt;&lt;a href=&quot;https://snailsharp.dreamwidth.org/2111.html#cutid1&quot;&gt;Read more...&lt;/a&gt;&lt;/b&gt;&lt;b class=&quot;cut-close&quot;&gt;&amp;nbsp;)&lt;/b&gt;&lt;/span&gt;&lt;div style=&quot;display: none;&quot; id=&quot;div-cuttag___1&quot; aria-live=&quot;assertive&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=snailsharp&amp;ditemid=2111&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://snailsharp.dreamwidth.org/2111.html</comments>
  <category>fsharp</category>
  <category>dotnet</category>
  <lj:security>public</lj:security>
  <lj:poster>isaacschemm</lj:poster>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://snailsharp.dreamwidth.org/548.html</guid>
  <pubDate>Sat, 03 Dec 2022 16:56:04 GMT</pubDate>
  <title>My favorite single line of code: sortable ProductVersion type for .NET</title>
  <link>https://snailsharp.dreamwidth.org/548.html</link>
  <description>Posted by: &lt;span lj:user=&apos;isaacschemm&apos; style=&apos;white-space: nowrap;&apos; class=&apos;ljuser&apos;&gt;&lt;a href=&apos;https://isaacschemm.dreamwidth.org/profile&apos;&gt;&lt;img src=&apos;https://www.dreamwidth.org/img/silk/identity/user.png&apos; alt=&apos;[personal profile] &apos; width=&apos;17&apos; height=&apos;17&apos; style=&apos;vertical-align: text-bottom; border: 0; padding-right: 1px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;https://isaacschemm.dreamwidth.org/&apos;&gt;&lt;b&gt;isaacschemm&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sometimes I need to take a version number - something like 5 or
6.4 or 2.25.1 - and see whether it&apos;s newer or older than another
version number, or maybe just take a list of version numbers like
this and put them in order.&lt;/p&gt;
&lt;p&gt;The projects I&apos;m working on usually have at least a bit of F#
code, or a dependency on an F# library (even if most of the code
is C#), and once I&apos;ve taken the dependency on FSharp.Core, I might
as well use it to create an equatable, sortable, and immutable
&quot;version number&quot; type.&lt;/p&gt;
&lt;p&gt;This might be absolute favorite line of code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;type ProductVersion = { components: int list }&lt;/code&gt;&lt;/pre&gt;
&lt;span class=&quot;cut-wrapper&quot;&gt;&lt;span style=&quot;display: none;&quot; id=&quot;span-cuttag___1&quot; class=&quot;cuttag&quot;&gt;&lt;/span&gt;&lt;b class=&quot;cut-open&quot;&gt;(&amp;nbsp;&lt;/b&gt;&lt;b class=&quot;cut-text&quot;&gt;&lt;a href=&quot;https://snailsharp.dreamwidth.org/548.html#cutid1&quot;&gt;Read more...&lt;/a&gt;&lt;/b&gt;&lt;b class=&quot;cut-close&quot;&gt;&amp;nbsp;)&lt;/b&gt;&lt;/span&gt;&lt;div style=&quot;display: none;&quot; id=&quot;div-cuttag___1&quot; aria-live=&quot;assertive&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=snailsharp&amp;ditemid=548&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://snailsharp.dreamwidth.org/548.html</comments>
  <category>fsharp</category>
  <category>dotnet</category>
  <lj:security>public</lj:security>
  <lj:poster>isaacschemm</lj:poster>
  <lj:reply-count>0</lj:reply-count>
</item>
</channel>
</rss>
