Monday, October 22, 2012

Isn’t it ironic, don’t you think?

Irony has long been among my favourite forms of humour. It comes from unexpected places, and sources of irony make great talking points most of the time. It also helps you to realise that the world isn’t as boring or predictable as it sometimes seems. I derive a sense of joy from that.

So the fascinating (but all too brief) experience I had on Debunking Christianity – Why All Oppressed Minorities Should Reject Christianity certainly left me with a considerable sense of my beloved irony. I am banned from all future posting by the site’s owner, John Loftus. Follow the link, read the comments, and see if you can work out why.


Thy hammer of ban. Note: text has been obscured in the interest of preventing the insignificant trickle of traffic to this page from potentially cutting into John’s advertising revenue. If you want to read the post and subsequent exchange, do so there.

To recap, John thinks all groups that have been oppressed by Christians ought to reject Christianity on that basis alone. Or, at least, that fact alone ought to be sufficient grounds for rejection without considering any other factors, and he finds it almost unthinkable that anybody would adopt the religion of those that oppressed their ancestors.

As you will find out if you follow the link, disagreeing with this and explaining why places you in any or all of the following categories:

  • A bigot.
  • A liar.
  • A misogynist.
  • An apologist for racism.
  • A Christian pretending to be an atheist (a sheep in wolf’s clothing, if you will).
  • Entirely unwelcome.

While I fully expect less-than-charitable responses from the long-term residents who fuel John’s echo chamber, I was most surprised by the dismal conduct of John himself. I invite anybody who trips over a tumbleweed and lands face-first at the foot of my own excuse for a blog to see for yourself if all the invective, accusations against my honesty and integrity and subsequent banishment were merited. And, since I’m denied any further right of reply over there, any discussion worth salvaging may as well take place here. I seriously doubt it will though. This is more to prove a point.

Anyone who sympathises with my take on the situation would probably share my sense of disappointment at the behaviour of a man who, by his education, literary achievements and reputation, really ought to have made a far, far better account of himself. This disappointment gives rise to speculation. Going forth with the assumption that I was not entirely out of line, was he simply having a bad day? Has he grown lazy from constant reinforcement and praise from followers who hang on his every word? Has he become simply so entrenched into a siege mentality from years of blogging and arguing that he sees the “enemy” everywhere?

Or, if I am permitted a moment of unashamed vanity, was my dizzyingly short tenure at DC (when others more rude, more inflammatory than I have survived much, much longer) simply down to the perception on John’s part that I made him look bad? And that my repeated calls for him to address the arguments (and not beat a path directly to ad hominems and banning) and support his accusations went unanswered simply because he couldn’t (at least not without taking a backward step or two)?

It would be easy for me to leave it there, having quickly reached a conclusion which paints John in a bad light while I emerge unscathed. No. Too easy. I ultimately think this is still the case, but I have to at least try out the idea that it isn’t, and play Devil’s Advocate with myself.

If I am honest, I must own up to the fact that this sort of thing happens to me quite often. Tempting though it may be to lay the blame at the feet of others, the common denominator is me. Moreover, I am quite sure that John is not incapable of defending his views, and isn’t afraid of debate (having had numerous public debates in his time) so the idea that he ran from me or acted out of cowardice is not consistent with observed reality. Clearly, the reason lies elsewhere. Evidently, I am excellent at rubbing others the wrong way. Why?

I stumbled upon a potential insight while reading through The Promise and Perils of Authorial Voice, an article by author and philosopher, Eric Reitan. My authorial voice probably registers somewhere in the vicinity of nails across a blackboard, and without my talent at pouring a perfect beer I’d have few redeeming features at all. It would seem that, despite my best efforts to the contrary, this aspect of my personality still comes though as strongly off-putting as it ever did.

With all that said, and despite his obvious intelligence, John also has an extremely polarised view on religion and his thinking is not immune to error, nor is he impervious to accepting sophistry because it aligns with his own preconceptions. Nor am I. Nor is anybody. There appears to be little or no middle-ground, concession, or acknowledgement of any grey area. This seems to be so much the case that his mental landscape does not allow for such an oddity as a fellow atheist who is unimpressed with one particular display of his “cleverness”. The reaction was clear evidence of this: brand me a Christian-in-disguise and drop-punt me from the arena with all due haste.

Based on a string of unimpressive encounters with fellow atheists that finally culminated in this towering dick-move from somebody who is often mentioned in fairly elite company, I am becoming increasingly disillusioned with people who are perhaps somewhat too eager to attach to themselves labels such as “freethinker”, “rationalist”, and so on, just because they don’t believe in gods.

Moreso than ever does the tagline for the now-dormant Common Sense Atheism ring true: atheism is just the beginning; now it’s time to solve the harder questions.

Friday, July 29, 2011

Every instance is equal; some are more equal than others

A friend contacted me recently with a rather vexing problem he was experiencing with XML serialisation in .NET. A very simple class containing only integers and strings was causing an exception with the message:

“System.InvalidOperationException: A circular reference was detected while serializing an object of type Common.Models.Member”.

After a few minutes, the intertubes suggested to me that the problem was likely caused by classes in the inheritance hierarchy referencing each other, which they weren’t. Eventually, I happened upon an offhand suggestion that led to investigation of the class’s equality checking. Common.Models.Member inherited from Common.Models.Reference, the latter of which contained the following:

public override bool Equals(object obj) { Reference other = obj as Reference; if (other == null) return false; return this.id == other.id; }

In addition to the method itself, two factors set off alarm bells:

  • Reference was not abstract. Moreover, it contained a method to return a new and separate Reference instance from any subclass, using its id value.
  • An override of Equals was not present in any of Reference’s subclasses.

Right away, this meant that multiple separate instances of different types could be considered equal, and that usually makes me feel uneasy.

As it turned out, overriding Equals in Reference’s suptypes to avoid the above confusion allowed the classes to be proccessed by XmlSerializer, but this seemed to be symptomatic of a deeper problem: how should equality be properly implemented in .NET?

As usual, I fully intend to fall well short of attempting to answer this question definitively, as should be the case. Far smarter and more informed developers than I have tackled this issue and reached different conclusions. So here are some more thoughts to cloud the issue.

The how, the what, and the why

Before any meaningful discussion about equality comparing can begin, it is essential to be mindful of some basic properties of equality:

Reflexive
For any a, a = a
Symmetric
For any a and b, if a = b, then b = a
Transitory
For any a, b and c, if a = b and b = c, then a = c

As we will see soon, the symmetric property is quite easy to violate.

Now that we have a basic understanding of what equality is, the next question is how to check for it. The answer, not surprisingly when speaking of .NET, is “lots of different ways.” And, equally unsurprising, some of them can yield different results even when comparing the same objects.

They are (all belonging to System.Object):

  1. Object.ReferenceEquals(x, y)
  2. Object.Equals(x, y)
  3. (x == y)
  4. x.Equals(y)

Only ReferenceEquals always returns the same value irrespecetive of the order of x and y; the other three offer no such guarantee. This should be the dawning realisation that you should tread carefully here. ReferenceEquals, however, is extremely basic: it checks to see if its two arguments occupy the same location in memory, and that’s it. If this doesn’t sound like such a bad deal, consider that the following expression evaluates to false:

if (object.ReferenceEquals(42, 42)) // unreachable code...

There aren’t many situations where you would expect or want a value to not be equal to itself, so this method is of limited utility. Object.Equals(x, y), on the other hand, wraps a polymorphic call to x.Equals(y) after checking that x and y are not the same reference and that neither are null.

The equality operator (==) wraps a call to ReferenceEquals, unless overloaded (note, not overridden) in a subtype of Object. Because operators are static, they are not polymorphic, and so the following code worryingly evaluates to false:

Uri a = new Uri("http://hinternets.blogspot.com"); Uri b = new Uri("http://hinternets.blogspot.com"); if (a == b && (object)a == b) // unreachable code...

Fairly warned be yea, says I.

Common pitfalls

Sooner or later, you are probably going to create a type that implements custom equality checking. As many people before you have done, you may try something like this simplified example (null checking and other error handling is omitted for brevity):

public class T { public int ID; public T(int id) { ID = id; } public override bool Equals(object obj) { return obj is T && ID == ((T)obj).ID; } }

With a minimal subclass:

public class U : T { public string Data; public U(int id, string data) : base(id) { Data = data; } public override bool Equals(object obj) { return base.Equals(obj) && obj is U && Data == ((U)obj).Data; } }

Each type compares all its members, and even leverages existing functionality like all good object-oriented code should. To those who have spotted the impending disaster, congratulations. To those who haven’t, watch on in horror as the symmetric property leaves the building:

T a = new T(1); T b = new U(1, "boogers"); if (a.Equals(b) != b.Equals(a)) Console.WriteLine("This cannot be!");

What went wrong here? In this example (and the case that prompted this post) the most direct answer is because the is operator tells you whether the instance can be casted to the specified type. That means that it includes any base types or interfaces, and so any U is therefore a T. T.Equals returns true because the type check passes, and only the value of ID is compared; U.Equals returns false because T is not a U, and even if it somehow were, it would fail when comparing the value of Data.

The immediate solution is to replace the is check with GetType() == obj.GetType(). But should we look deeper?

Navel-gazing

Returning to the initial example, instead of simply patching the problem with an explicit type check, it is worth questioning the relationship between Reference and Member, and also whether Reference should even exist in the first place, considering that it consists of nothing other than an ID value and an overridden method.

At best, it should probably be marked abstract because it probably doesn’t convey enough information about anything to be useful on its own. Subtypes are invariably going to be compared in different ways in order to prevent this type of confusion, and rather than enter a murky world of incessent overriding of behaviour, it is probably much more flexible and less problematic to simply write:

if (a.ID.Equals(b.ID)) // do something...

And be done with it.

Just because one type’s members are a subset of another does not automatically mean that they should be related by inheritance. It may be convenient not to have to rewrite a little bit of code here and there, but sometimes the price you pay for blurring the lines of identity just isn’t worth it.

If this isn’t your cup of tea because you prefer a greater degree of encapsulation, then this behaviour can be rolled into custom comparer classes that implement IComparer<T> and IEqualityComparer<T>, both under the System.Collections.Generic namespace. This is handy for, if nothing else, avoiding the tiresome repetition of null checks on both operands.

public class UComparer : IEqualityComparer<U>, IComparer<U> { public static readonly ByID = new UComparer(); private UComparer() { }; public bool Equals(U x, U y) { return x.ID.Equals(y.ID); } public int GetHashCode(U obj) { return obj.ID.GetHashCode(); } public int Compare(U x, U y) { return x.ID.CompareTo(y.ID); } }

And the above example is rewritten:

if (UComparer.ByID.Equals(a, b)) // do something...

Additional comparers can be created for the purpose of ordering or collating a data type in different ways. These comparers can also be fed into collection classes such as SortedSet<T> and others that are sensitive to order or duplicate elements. Both they, and their methods, can be passed around:

Array.Sort(arrayOfU, UComparer.ByID.Compare);

Alternatively, when dealing with collections, a dictionary or or lookup (under the System.Linq namespace) can be used with the desired property extracted as the key. In the following example, an array of U instances are grouped on arbitrary members.

// Get the count of each distinct Data in descending order. var countByData = arrayOfU.ToLookup(u => u.Data) .Select(g => new { g.Key, Sum = g.Count() }) .OrderByDescending(t => t.Sum);

This only works well in simple cases, but it is ad hoc and therefore very flexible. It also avoids having to create a large amount of dedicated comparer classes to achieve the same result.

Only half the story

No discussion on equality is complete without addressing hash codes as well, since the two are tightly intertwined. This, however, will require another post, preferrably after a good night’s sleep or two, and, if I’m honest, a glass of red to steady my nerves.

There will be maths involved. Mark my words.

Sunday, May 16, 2010

Coming full circle

Atheism is an increasingly hot topic across the world, with bus campaigns, this year’s global convention and an influential presence on YouTube.

The last bit may sound a bit trite, especially to people who think YouTube is all about dramatic hamsters, lolcats and skateboarders doing face-plants for our amusement, but YouTube has provided a legitimate frontline in the conflict between skepticism and faith, particularly in the realm of science and creationism. It has enabled both laymen and professionals alike to engage on equal footing to a captive audience. The ‘video response’ feature has greatly facilitated the dialog and collateral drama, allowing users to more easily follow the continuing soap opera.

The result of the conflict as of now is that, on YouTube, creationism has been more or less smashed to a pulp. Scientific channels such as Thunderf00t, Aron Ra, cdk007, Don Exodus and others have gained massive popularity, mostly at the expense of cretionist channels: the most infamous of which was VenomFangX. The VFX saga was far too long and bizarre to go into any detail here but suffce to say that the closing of his channel was a mercy to the world. The runaway success of these channels (some run by professional scientists) has caused one to observe that “the internet is the place where religions come to die.” After consistent humiliation, the only card held by the creationists was the card of desperation, which they played heavily and aggressively for some time in the form of false (and illegal) DMCA (PDF) takedown notices, the use of scripts to massively downvote videos in order to bury their search rankings, and flagging campaigns to disingenuously mark videos as either spam or unsuitable for minors.

These concerted and organised censorship tactics were met by equally organised video mirroring, causing some targeted videos to go viral and receive many times more views than they otherwise would have.

So, a victory for rationality and free-thinking, right?

It’s lonely at the top

Well, not really. It turns out that even in the skeptics’ camp there is an undercurrent of the exact kind of herd mentality that theist footsoldiers are regularly criticised for. For instance, call out Pat Condell for hawking a racist and lunatic fringe party like Richard Coughlan did, and expect a torrent of brainless abuse and even death threats from the faithful. Not to mention false DMCAs as well. Every cowardly and dishonest tactic used against the atheist community in the past are now being used by elements within their ranks.

The irony is so staggering that it’s hard to find anything to say that isn’t completely redundant. At least theists generally only get this worked up in defense of the almighty creator of the universe; atheists meanwhile are every bit as vitriolic over a silly old man who makes essentially the same video 67 times.

Is it as simple as looking inwards for the ever-present need for conflict in the absence of traditional enemies?

Nah

No, that doesn’t add up. It may play a small part but it doesn’t explain the degree of hatred and hypocrisy. So then, is the atheist claim to superior critical thinking as vacuous as the theist pretense to moral superiority?

Perhaps this highlights the folly of associating virtues with something and then promoting it rather than the value itself. For instance, why promote atheism in the name of free thinking and rationality? Why not just promote free thinking and rationality directly? On the other side of the fence, why not promote selflessness, kindness and love without bundling them up into the worship of a deity as though one is not possible with the other?

As the backlash from criticising Condell shows, there is an element of drone mentality and irrationality that is not negligible, and can only serve to undermine the atheist image of intellect and reason. As atheism enjoys more acceptance and grows in number, a pattern is emerging where prominent celebrities (those such as Dawkins, Harris, Hitchens, PZ Meyers and, no less it seems, online personalities like Thunderf00t and Condell) attract increasingly mindless flocks of followers who lash out at criticism directed at the object of their reverence as though it was directed at them personally.

Does this sound familiar?

Mountains or molehills?

Taken in isolation, I am probably reading too much into it. Commenting on YouTube videos brings out the worst in people, and reading them often causes one to die a little on the inside. However, I am pretty sure that this isn’t an isolated incident. Not by far. I don’t think that many would try to deny that there are idiotic atheists in the world, and if they did they would only be helping to prove the point I’m trying to make in this post.

A more interesting question is whether or not atheists in general are noticably less prone to this kind of fanatical behaviour than theists, because it goes right to the heart of their credibility when they dish out ridicule and condemnation towards theists. It’s also a timely reality check for a group that is perhaps a little drunk on recent success. Also worth considering is the mutual exclusivity of quality and quantity: as something grows in popularity, standards almost invariably lower simply because more people are likely to accept it uncritically.

Another question is: should we even be surprised by this? Atheism is, afterall, the default position; theism of any kind is a learned behaviour. So why is there an expectation in the first place for atheists to exhibit any extra intellectual rigour? Or is the expectation for theism to be an impairment, and atheism wins by default?

Too many variables. Too many unanswerable questions. Only one thing is clear to me, and that is that the collective atheist ego needs a wake-up call lest this sort of behaviour become more commonplace.

Friday, January 01, 2010

Learning to fish

The SitePoint forums are a microcosm of a long-running and disheartening real-life trend towards instant gratification. In the interests of saving the reader a tedious mouse-click, SitePoint sells books about web design, boasts about how popular it is, and also offers a message forum.

The scenario I refer to involves people asking incredibly basic questions without having shown any suggestion of initiative or effort and, instead of being referred to lmgtfy.com or being told to RTFM, they are given the answer or the code they want by some “helpful” resident expert in pursuit of a “Mentor” badge of honour. This is the beat to which this forum moves.

Alternatively, trying to guide anybody into working it out for themselves (a much more worthwhile exercise IMLTHO) is rather like pushing water uphill. It’s an exercise in futility on two fronts. Firstly, gently guiding the learning process takes time and is almost always interrupted by somebody giving them the code, and secondly the culture there has produced impatience and laziness because of this. Seekers become petulant when not spoon-fed.

For a masochistic hobby, I try to see how close I can bring people to their own solution before somebody else swoops in and renders my efforts in vain. As a form of punishment it is highly effective: hopes are built and then dashed against rocks; the exact moment of demise can never be known, I only know that it is coming.

For some reason, I refuse to give up this almost unwinnable game. It’s a concession that I refuse to make, in a manner not entirely unlike Jean-Luc Picard in First Contact shouting “The line must be drawn here! This far, no further!” But perhaps not in such dramatic fashion. It’s not easy getting that worked up over an internet forum.

But it is both interesting and important as a new parent, and it just dawned on me that this might be the reason for why I persist. Cultivating perseverance in the face of failure and rejection is probably a good quality for a parent to have, especially with regards to the education of their children. I want mine to have the skills to blaze their own path in life: to learn from mistakes, to overcome difficulties rather than give up, to be themselves and make their own choices rather than be controlled.

I am at odds with the prevailing notion of letting children be children. Or at the very least I don’t agree with the degree to which it is commonly practiced. It seems unfair and damaging in the long run to insulate them from reality for as long as possible and then, when they turn 18, call them an adult and expect them to deal with everything. At what point along the way did they acquire the skills to do this?

In theory at least, the answer seems pretty simple: gradually introduce new responsibilities as needed (or earlier if they can handle it), and remove safety blankets at the same time. Or, in other words, the second they’re big and strong enough to push a lawnmower, put them to work in the yard. As soon as they’re tall enough to reach the sink, make them do the dishes. If they’ve any energy left after their chores, then they can play on their Wii, but not a moment before.

In practice I know it will be an entirely different matter. It won’t be easy to not give in to petulant demands in return for a bit of peace and quiet, whereas it will be easy to give up in the face of being berated with tearful tantrums and “But I don’t wanna!” I will have bad days at work, and I will come home tired and annoyed and won’t want to deal with any of it. In fact if I achieve half of what I set out to, I’ll be fairly happy so long as they have some basic survival skills and can tell right from wrong. There’s nothing wrong in aiming high.

But all the same, this is important because once they turn 18 they’re out, because on my wage we can probably only afford a 3‑bedroom house and I will want to reclaim my office as soon as possible. So they’ll need to be able to cook and clean or know how to unblock a drain, and I’ll make sure they can. It’s the least I can do.

Tuesday, December 29, 2009

The cow is better than you

Working the 9 to 5 grind at a desk for any length of time is almost guaranteed to, sooner or later, result in the question: “Is this really my life?” And unless this distraction prevents you from palming off work to somebody else, it may lead to other equally disturbing questions — disturbing in the sense that there are no immediately obvious answers.

Some such questions may take the following forms:

  • What is the point of it all?
  • Is this really what we were intended to be?
  • What have I ever accomplished?
  • When was the last time I was proud of something I did?
  • Why, oh why, oh why?

These and endless variations thereof are the lament of every person whose life mostly consists of getting up earlier than they would prefer, donning a corporate noose and fighting traffic to sit in a cubicle and drip-feed themselves coffee all day just to stay awake. It’s galling to contemplate a millennia of our ancestors fighting their way up the food chain, exploring the world, building great civilisations, just to end up here. It seems that a wrong turn was made somewhere.

You know there has to be something amiss when important decisions are entrusted to computers (at great cost in time, effort and money), while the people who use and build these systems are often treated like automatons. We repetitively enter the same data, and perform the same processes day after day.

Sometimes I wonder if perhaps the cows have got it right, and there’s just as much satisfaction to be had by grazing in a field and farting all day long. Is that any less useful or purposeful than what most people occupy their lives with? Whenever I bring up this observation, the prevailing opinion is that of course humans are more important. We contribute more to society. Or we have more potential.

My response to that is in the form of a question: We all consume resources from the moment we are born until the day we die. In between, what do humans do that makes us so special among living creatures?

Let us put it to the test, by comparing my life as a middle-aged man working in the IT sector to our humble aforementioned cow. I write software for a living, but what does that ultimately mean in the grand scheme of things? By the time I retire, my life’s work will have been made obsolete and replaced by something newer and shinier, and it will almost be as though I never did anything. No evidence of my toil will exist. My contribution to anything permanent or even lasting is more-or-less nil. Just like the cow eating grass, the grass grows back and will do so long after it dies. In both cases our lives’ work has amounted to nothing in the long run. I have contributed nothing more of meaning or substance than the cow. In fact, unless I can keep the emissions from my car and my electricity consumption to under what the cow will expel from its poop chute (which I am certain that I don’t), I am considerably behind in the net total.

The bottom line is that humans almost always take far more from the Earth than they give. This thought continues to bother me, perhaps mainly because I know that I am part of the problem. Granted, I am only a very small part of the problem but the point still stands. I know this and yet I don’t do anything about it because I am far too invested in the little world I have created for myself: a bubble consisting of a family and a means to feed that family. Would I stop tomorrow if I knew that my lifestyle is killing penguins? Undoubtedly no. “But honey, think of the penguins” probably wouldn’t cut it when we’re homeless.

Value and worth, then, must be found elsewhere because there seems no mileage in thinking that we as humans are the most important species in any way that is not imagined, arbitrary and self-serving. I can turn business requirements into software and Buttercup can’t; but does this make me more valuable? She can produce milk that feeds not just cows but people as well, while I have never produced a drop of milk in my life. Her contribution to society sustains life whereas I can only potentially make my employers a bit more money.

See what I mean? Buttercup wins. Flawless victory.