Wednesday, February 26, 2014

TDD

Q: Why is TDD a good idea when bug fixing?
A:
Because sometimes the amount of work required to make a "red test" is so much that if you fix the bug first, you will never get around to writing the test infrastructure. (Plus, after you fix the bug, you don't have a good test case for writing that infrastructure.)

Case in point: I have an oData service which fails on certain queries, because the underlying CRM provider which services the queries can't handle certain LINQ expressions. There are likely to be other queries which fail in the future, and I need automated tests to prevent fixed queries from regressing as I tweak my oData service... but the bug repro I have is too heavyweight for a unit test. So instead of fixing the bug I just spent (three? five?) hours digging through dependencies with ILSpy and writing enough test infrastructure that I now have a failing "red test" to document the bug condition... only uses it uses mocks and reproes the bug without any network communication at all.

It's amazing how good I feel about the progress I've made even though the bug itself is still RIGHT THERE.

(Also, git's branch-per-feature paradigm is great for keeping my cognitive load modest while doing TDD.)

--
Deck thyself now with majesty and excellency; and array thyself with glory and beauty.
Cast abroad the rage of thy wrath: and behold every one that is proud, and abase him.
Look on every one that is proud, and bring him low; and tread down the wicked in their place.
Hide them in the dust together; and bind their faces in secret.
Then will I also confess unto thee that thine own right hand can save thee.

I could not love thee, dear, so much,
Loved I not Honor more.

Wednesday, February 19, 2014

Bayesian inference

[from another conference--a friend asked for a quick explanation of what Bayesian inference is]

The basic idea behind Bayesian reasoning is quite simple, it's simply quantifying with a formula what you do anyway instinctively. Here goes, without the math:

When you estimate probabilities, it's fair to say that you're guessing at the ratio of possible universes. Saying "Three out of four, Richard Nixon is a crook" means that of all the possible universes you can see from where you are today, Richard Nixon is a crook in three of them. "Fifty-fifty it comes up heads" means you think the possible universes are evenly balanced. That's the Bayesian view of probability, that it's a subjective estimate instead of something real.

Bayesian inference is about how your view of a given probability changes over time as you see new things. When you see something new, you delete all the universes in which that thing would not have happened, and then look at the ratio of remaining possibilities for the new probability. Example: say Nixon says "I am not a crook." If I estimate that Nixon would always say that in universes where he is a crook, and he wouldn't bother to say it in half the universes where he isn't a crook, then as soon as he says it, half of the universes where he was innocent vanish. Instead of 3/4 chance he's guilty, it's now a 6/7 chance. (Remember, the chance of being innocent drops from 1/4 to 1/8, and it's the ratio of 1/8 to 3/4 that matters because any universe not in that ratio has already been disproven.)

This doesn't just work for yes/no questions, it could be that I'm trying to decide between "Richard Nixon is a crook" vs. "Richard Nixon is incompetent." Either way I'm simply eliminating possible universes with each piece of evidence.

So far so good, but the great weakness of Bayesian inference is this: I'm simply narrowing down my hypotheses each time based on evidence. What if the truth isn't in any of my hypotheses? What if the real explanation is that "Richard Nixon is an alien"? Since Bayesian inference is all about ELIMINATING possibilities, I will never, ever tumble to the truth. Even if I see him beam himself up into his spaceship, Bayesianism has no way for me to deal with that. And yet in the real world, I would indeed change my mind if I saw his spaceship--I'd generate a new hypothesis on the fly. So my mind isn't Bayesian, it isn't deductive. What is my mind doing?

Bayesian inference is demonstrably the most reasonable way of deciding between two possibilities, but somewhere inside my head I must have a container that says "infinite number of other possibilities."

--
Deck thyself now with majesty and excellency; and array thyself with glory and beauty.
Cast abroad the rage of thy wrath: and behold every one that is proud, and abase him.
Look on every one that is proud, and bring him low; and tread down the wicked in their place.
Hide them in the dust together; and bind their faces in secret.
Then will I also confess unto thee that thine own right hand can save thee.

I could not love thee, dear, so much,
Loved I not Honor more.

Tuesday, February 4, 2014

Moroni

"Yea, verily, verily I say unto you, if all men had been, and were, and ever would be, like unto Moroni, behold, the very powers of hell would have been shaken forever; yea, the devil would never have power over the hearts of the children of men. Behold, he was a man like unto Ammon, the son of Mosiah, yea, and even the other sons of Mosiah, yea, and also Alma and his sons, for they were all men of God."

This is an interesting statement, considering Alma and Ammon's backstory as men over whom, at one point, the devil had quite a lot of power. So it's not something intrinsic to Moroni/Ammon/Alma, but rather a statement about the state which they had achieved by their faith in and obedience to Christ. And therefore you may wish to ponder whether you are, at this time, someone who would cause "the very powers of hell [to be] shaken forever." And if not, how can you become such?

That's what I get out of it, anyway.


--
Deck thyself now with majesty and excellency; and array thyself with glory and beauty.
Cast abroad the rage of thy wrath: and behold every one that is proud, and abase him.
Look on every one that is proud, and bring him low; and tread down the wicked in their place.
Hide them in the dust together; and bind their faces in secret.
Then will I also confess unto thee that thine own right hand can save thee.

I could not love thee, dear, so much,
Loved I not Honor more.