Anti-pattern: parallel collections

(Note that I’m not talking about "processing collections in parallel, which is definitely not an anti-pattern…) I figured it was worth starting to blog about anti-patterns I see frequently on Stack Overflow. I realize that some or all of these patterns may be collected elsewhere, but it never hurts to express such things yourself… it’s a good way of internalizing information, aside from anything else. I don’t guarantee that my style of presenting these will stay consistent, but I’ll do what I can… The anti-patterns themselves are likely to be somewhat language-agnostic, or at the very least common between Java … Continue reading Anti-pattern: parallel collections

Diagnosing issues with reversible data transformations

I see a lot of problems which look somewhat different at first glance, but all have the same cause: Text is losing "special characters" when I transfer it from one computer to another Decryption ends up with garbage Compressed data can’t be decompressed I can transfer text but not binary data These are all cases of transforming and (usually) transferring data, and then performing the reverse transformation. Often there are multiple transformations involved, and they need to be carefully reversed in the appropriate order. For example: Convert text to binary using UTF-8 Compress Encrypt Base64-encode Transfer (e.g. as text in … Continue reading Diagnosing issues with reversible data transformations

Stack Overflow question checklist

My earlier post on how to write a good question is pretty long, and I suspect that even when I refer people to it, often they don’t bother reading it. So here’s a short list of questions to check after you’ve written a question (and to think about before you write the question): Have you done some research before asking the question? 1 Have you explained what you’ve already tried to solve your problem? Have you specified which language and platform you’re using, including version number where relevant? If your question includes code, have you written it as a short … Continue reading Stack Overflow question checklist

Stack Overflow and personal emails

This post is partly meant to be a general announcement, and partly meant to be something I can point people at in the future (rather than writing a short version of this on each email). These days, I get at least a few emails practically every day along the lines of: "I saw you on Stack Overflow, and would like you to answer this development question for me…" It’s clear that the author: Is aware of Stack Overflow Is aware that Stack Overflow is a site for development Q&A Is aware that I answer questions on Stack Overflow … and … Continue reading Stack Overflow and personal emails

Diagnosing weird problems – a Stack Overflow case study

Earlier, I came across this Stack Overflow question. I solved it, tweeted it, but then thought it would serve as a useful case study into the mental processes I go through when trying to solve a problem – whether that’s on Stack Overflow, at work, or at home. It’s definitely worth reading the original question, but the executive summary is: When I compute the checksum/hash of c:\Windows\System32\Calc.exe using various tools and algorithms, those tools all give the same answer for each algorithm. When I try doing the same thing in Java, I get different results. What’s going on? Now to … Continue reading Diagnosing weird problems – a Stack Overflow case study

Upcoming speaking engagements

It’s just occurred to me that I’ve forgotten to mention a few of the things I’ll be up to in the near-ish future. (I’ve talked about next week’s Progressive .NET session before.) This is just a quick rundown – follow the links for more blurb and details. .NET Developer Network – Bristol, September 21st (evening) I’ll be talking about async in Bristol – possibly at a high level, possibly in detail, depending on the audience experience. This is my first time talking with this particular user group, although I’m sure there’ll be some familiar faces. Come along if you’re in … Continue reading Upcoming speaking engagements

Writing the perfect question

Update: now that I’ve actually posted this, I’ve added a tinyurl to it for easy reference: http://tinyurl.com/so-hints. Nice and easy to remember for comments 🙂 A while ago, I wrote a blog entry on how to answer questions helpfully on sites like Stack Overflow. Recently I saw a meta question about bad questions and thought it would be worth following up with another blog post on asking questions. For the sake of convenience – and as Stack Overflow is so popular – I will assume the question is going to be asked on Stack Overflow or a similar Stack Exchange … Continue reading Writing the perfect question

"Magic" null argument testing

Warning: here be dragons. I don’t think this is the right way to check for null arguments, but it was an intriguing idea. Today on Stack Overflow, I answered a question about checking null arguments. The questioner was already using an extension similar to my own one in MiscUtil, allowing code like this: public void DoSomething(string name) {     name.ThrowIfNull("name");     // Normal code here } That’s all very well, but it’s annoying to have to repeat the name part. Now in an ideal world, I’d say it would be nice to add an attribute to the parameter and have the … Continue reading "Magic" null argument testing

Just how spiky is your traffic?

No, this isn’t the post about dynamic languages I promise. That will come soon. This is just a quick interlude. This afternoon, while answering a question on Stack Overflow1 about the difference between using an array and a Dictionary<string, string> (where each string was actually the string representation of an integer) I posted the usual spiel about preferring readable code to micro-optimisation. The response in a comment – about the performance aspect – was: Well that’s not so easily said for a .com where performance on a site that receives about 1 million hits a month relies on every little … Continue reading Just how spiky is your traffic?

Revisiting randomness

Almost every Stack Overflow question which includes the words "random" and "repeated" has the same basic answer. It’s one of the most common "gotchas" in .NET, Java, and no doubt other platforms: creating a new random number generator without specifying a seed will depend on the current instant of time. The current time as measured by the computer doesn’t change very often compared with how often you can create and use a random number generator – so code which repeatedly creates a new instance of Random and uses it once will end up showing a lot of repetition. One common … Continue reading Revisiting randomness