Tuesday, September 10, 2024

Different meanings of "any" in C# and Python

I first learned to program in Python and now work in C#.

Python has the function "any", which takes in any number of parameters and checks whether any of them are truthy. This makes sense since Python has a concept of object truthiness.

C# has the Linq method "Any", which takes in an IEnumerable<T> and a Func<T,bool>. It calls the function on each element of the collection and checks whether any of these calls returns "true". This makes sense since C# has no concept of truthiness; a hypothetical C# "Any" method that did not pass in a function could only take a collection of boolean values.

Additionally, C# has a separate Linq method "Any" that takes in only a collection. It checks whether the collection has any elements in it. C# can have two methods called "Any" since it, unlike Python, has method overloading.

Despite this very logical reasoning, I periodically end a long bug hunt by discovering that, having a list of bools, I called "Any()" on it instead of "Any(a => a)".

I miss F#'s "IsEmpty".

If you can, avoid using the same term for two different concepts.

Saturday, September 7, 2024

Puzzled by the beginning of Good Omens by Terry Pratchett and Neil Gaiman

This morning I tried this Terry Pratchett novel I picked up at the thrift store. (I know next to nothing about Neil Gaiman. I do have friends named "Gehman". Maybe they are distantly related?) I read up through the Eleven Years Ago section, or page 64 of 369, and my opinions should not be construed to reflect the bits I have not read. I will read and consider any comments telling me that I am missing the point and should continue.

(I do appreciate the dedication to G.K. Chesterton. It helps explain why I like Pratchett's humor so much.)

WARNING: I am making no attempt to avoid spoilers and don't know what will turn out to be a spoiler anyway.

Caring for the first humans

The book begins by taking shots at God's judgment in the Garden of Eden. Whatever; Pratchett baiting the Christians is nothing new. God has shut us all up under sin so that he may have mercy on us all. I like the point about Adam and Eve needing protection after the Curse from wild animals, which I had not considered before. I am a bit ticked that God leaves them to fend for themselves and an angel has to go behind his back to help them--a subtle shot at God that I didn't notice until I reread it. Pratchett does this quite often, though without using God's name. (You can hurl all sorts of blasphemies without offending anyone so long as you use such euphemisms as "nature" or "religion" or "tradition". Or, slightly more respectably, you can do as Pratchett does and imply theological conclusions without explicitly stating them. If you are reading or listening, always consider logical implications.)

Good and evil

The point of the introduction, however, is to introduce the good/evil dichotomy and the beings who participate in it. God and the angels do good and the demons do evil. Humans, we will later learn, do either depending on the situation and their own reasons, having free will. Presumably, the authors do not believe in beings that do not have free will; Crowley is said to have picked it up from humans later, which is obviously nonsense. I rather agree with the authors' skepticism in the existence of conscious beings without free will, though I don't limit free will to humans. God does whatever he wants, so he obviously has free will, and angels and demons probably have free will since they do stuff.

This framework leaves plenty of room for the idea of the depravity of man, by the way, especially once Crowley starts innerly monologuing on how humans don't need temptation to do evil.

I'm never quite sure Pratchett (in this book or others) is arguing for moral relativism or for resisting evil. You can't argue in one breath that "Good and evil...[are] just names for sides" (52) and in the next that some actions are Wrong and others are Right, or however you split morality. Actually, many moral relativists attempt to do just that, but I expect more of Pratchett.

Good is not good?

My main miff with the book is with the oxymoronic popular idea that Neutral is better than Good (and I would like to bestow an especial "may your memory be forgotten" on the webcomic Looking for Group by Ryan Sohmer and Lar DeSouza, of which this fallacy is the entire worldview and point). The chain of reasoning goes like this: "Good, as I understand it, is boring and ineffective. Boredom and ineffectuality are bad. Therefore, Good is not all that good." Only, most people state only the first premise aloud, leave the second to be assumed, and make jokes implying the conclusion to loud laughter, somehow entirely missing the obvious logical contradiction. If boredom and ineffectuality are not good, then Good is logically neither boring nor ineffective. Therefore, if you perceive Good as boring and ineffective, then, necessarily, either boredom and ineffectuality are not so bad after all or you perceive incorrectly.

When the Antichrist is on the way, we find that the forces of Good want Armageddon and eternal Heaven, the forces of Evil want Armageddon and eternal Hell, and the Neutrals want to preserve Earth because Hell is bad and Heaven is boring. First, if I interpret my Bible correctly, God lives in Heaven, whereas the dead in Christ go to the New Jerusalem, which is some sort of terrestrial habitation designed for humans. Second, Crowley claims that all interesting aspects of culture belong to Hell. What on Earth, or whichever realm? Crowley says that Beethoven, Bach, and Mozart go to Hell, but we sing songs composed by them in church. He says that Heaven doesn't get salt or eggs, but God created both. Whatever we see that is desirable, either our desire is wrong or we see good, and our new home can have all the good. I'm sure I'm missing something here. Perhaps something satirical?

And whyever was it necessary to provide the young supposed Antichrist with an evil influence as well as a good one? The Force doesn't need balanced1; more good is truistically better. The kid wasn't going to bring about Armageddon if he was good; the angels were waiting for the demons to do that.

Other picked nits and miscellany

"God does not play dice with the universe; He plays an ineffable game of His own devising, which might be compared, from the perspective of any of the other players, to being involved in an obscure and complex version of poker in a pitch-dark room, with blank cards, for infinite stakes, with a Dealer who won't tell you the rules, and who smiles all the time" (pages 11-12). But didn't God tell us the rules in the Bible?

"Hastur cleared his throat. 'I have tempted a priest,' he said. 'As he walked down the street and saw the pretty girls in the sun, I put Doubt into his mind. He would have been a saint, but within a decade we shall have him'" (page 16). That seems a bit horrifying for the comedic context: The man was not only damned but also turned into a creep who lusts after women significantly younger than himself. Also, demons don't know the future, do they? Or maybe Hastur is merely boasting rather than stating fact, in which case two wrongs do make a right.

"Technically Aziraphale was a Principality, but people made jokes about that these days" (page 38). Principalities and powers are demons, whereas Aziraphale is an angel.

"No one bothered to take up this matter with the nice Mr. A. Ziraphale, who ran the bookshop two doors along and was always so helpful with the translations, and whose handwriting was instantly recognizable" (page 45, footnote). I so badly now wish for an angel eyewitness to help us with the Bible translation. That's not happening, though, since we are to judge the angels by the Scriptures, not the other way around (Galatians 1:8, which, by the way, is one use of the word anathema, which appears elsewhere in the book).

Crowley says that Heaven will have the movie The Sound of Music (page 50). After Maria and the Captain fall in love, Maria has a song where she speculates that she must have done "something good" to merit a future with the Captain, thus showing ingratitude to God for his undeserved gift of human love. Either Heaven will not have The Sound of Music in the form we know it, or at least its viewers will not "enjoy it". (Anyway, the book was much better.)

"Crowley looked up slyly. 'Then you can't be certain, correct me if I'm wrong, you can't be certain that thwarting it isn't part of the divine plan too. I mean, you're supposed to thwart the wiles of the Evil One at every turn, aren't you?'" (page 51). Good on Crowley for identifying a huge problem with fatalism as commonly exercised. The Christian must never allow evil to stand unopposed, arguing that whatever happens must be the will of God. By that logic, if you oppose the evil, your opposition must have also been the will of God.

Predictions in case I continue reading: The supposed Antichrist is totally going to name the hellhound; children love dogs. And the actual child of the Devil is going to be a girl.


1 This is a reference to Darths and Droids, not to Star Wars. I recognize that the balancing of the Force in Star Wars is not between Good and Evil.

Stuff I don't understand about C#

Rant ahead. Criticisms of the language and the language idioms are interspersed. Disclaimer: I've been wrong about C# before. My lack of...