[Snark] F# No Whitespace

Stephen Paul Weber singpolyma at singpolyma.net
Fri Nov 9 02:00:29 UTC 2018


>for i in str.Split(' ') do

I do like the subtle terribleness of naming the variable holding each word 
in a phrase `i` just because this is technically a kind of for loop.

>          && Array.exists
>                 (fun x ->
>                 x = System.Convert.ToString(i.[0])
>                     + System.Convert.ToString(i.[1])
>                     + System.Convert.ToString(i.[2])) consonants then

This is delightfully verbose.  Not only is the string slicing bad, but it is 
done once for every element in `consonants`.

>           i.Substring 3 + System.Convert.ToString(i.[0])

lol.  So there is a "Substring" function.  This code feels like it was 
written by two different people, or amended later by a less experienced 
person who added the above condition without reading this line.

>                      (Array.map (fun x -> x + "qu") consonants) then
>           i.Substring 4 + System.Convert.ToString(i.[0])
>           + System.Convert.ToString(i.[1]) + "quay"

This one is fun, because it *could* be actually a good code re-use, re-using 
the consonant detection and a combinator to get the "qu" case.  Except that 
it's completely inlined into the giant if-else-if as a special case so only 
the consontant array is shared.

>       else if i.Length > 3
...
>           i.Substring 3 + System.Convert.ToString(i.[0]) + "quay"

And then it really hits, repeating the exact same special case for a 
different word length.  If there was just one case it wouldn't be great, but 
like this it provides a great example of code-non-reuse masquarading as code 
reuse.  Love it.

>   if i = str.Split(' ').[str.Split(' ').Length - 1] then printf "%s" word
>   else printf "%s " word

Because how else would you tell if you're at the end of the phrase?  Nice.

There's nothing notably bad about overall approach here, but the encoding 
has some great nuggets of terrible, and the giant-if-else-if structure is a 
nice touch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://snark.badcode.rocks/pipermail/snark/attachments/20181108/647b2c10/attachment.sig>


More information about the Snark mailing list