LINQ: Clarity, complexity, and understanding

This is part of a short series on the basics of LINQ:

At CareEvolution, we tend to develop using JavaScript on the front end, and C# on the back end (with some Python, PowerShell, CoffeeScript, R, SQL, and other languages thrown in when appropriate or technical debt dictates). We have hackathons every eight weeks where we get to be creative without the constraints of day-to-day work. We have a brown bag lunch talk every Wednesday. We work hard at embracing change, exploring new ways of doing things, and sharing what we have learned with each other. Quite often, leading figures in a particular technology emerge within our organisation: Brian knows JavaScript, Chris knows CSS, Brad knows SQL. While I doubt I know even half of the things about LINQ and its various implementations for database, Web API, or file interaction, I know enough to make it useful in my day to day work and I seem to be the one that employs it most in their code. I know LINQ.

I am certain this is going to sound familiar to many, but while my colleagues and I embrace all things as a collective, quite often a specific technology or its use will be avoided, derided, and hated by some. Whether driven by ignorance, a particular terrible experience, or prejudice1, these deep-seated feelings can create conflict and occasionally hinder progress. For me, my use of LINQ has been a cause for contention during code reviews. I have faced comments like "LINQ is too hard to understand", "loops are clearer", "it's too easy to get burned using LINQ", and "I don't know how to use it so I'd prefer not to see it". And that's all true; LINQ can be confusing, it can be complicated, it can be a debugging nightmare. LINQ can suck. Whether you use the C# language keywords or the dot notation (a debate almost as passionate as tabs versus spaces), LINQ can tie you up in knots and leave you wondering what you did to deserve this fresh hell. Yet any technology could be described the same way when one doesn't know anything about it or when early mistakes have left a bitter aftertaste.

Tabs vs Spaces

In response to these dissenting voices, I usually indicate the years of academic learning and professional experience it takes us to learn how to code at all. None of it is particularly easy and straightforward without some education. Don't believe me? Go stick your mum or dad in front of Visual Studio and, assuming they have never learned anything about C# or programming, see how far they get on writing Hello World without your help. Without educational instruction, we would not know any of it and LINQ is no different. When review comments inevitably request that I change my code to use less LINQ, none at all, or more understood language features like `foreach` and `while` loops, it frustrates me. It frustrates me because I usually feel that LINQ was the right choice for the job. I feel like I am being told, "use something I already know so I don't have to learn."

Of course, this interpretation is hyperbole. In actuality, when presented with opposing views to our own, it is easy to commit the black or white fallacy and assume one must be right and the other wrong, when really we should accept that we both may have a point (or neither) and learn more about the opposing view. Since I find, when used appropriately, LINQ can provide the best, most sublime, most elegant solution to problems that require the manipulation of collections in C#, I desperately want others to see that. It is as much on me as anyone else to try and correct for the disparity between what I see and what others see when I write LINQ. So, with my next post we will begin a journey into the basics of LINQ, when to use it2, when to use dot notation over language keywords (or vice versa), and how to avoid some of the more common traps. We will begin with the cause of many confusing experiences; deferred execution.

  1. we all know someone in the "That's new, I hate it" crowd []
  2. even I recognize LINQ is not a golden hammer; it's more of a chainsaw that kicks a little []

Ignorance Is No Joke

The age of social media has given us a new host for the pathogens commonly referred to as memes. Quite often these are innocuous, humorous quips that could lighten anyone's day. Unfortunately, they are also often misleading, false, and destructive. Many lie, and some, like the one that brought me to write this post, celebrate ignorance in a way that saddens me.

The specific meme that I am referencing implies that learning algebra was a waste of time. It is often posted with some comment that seems to indicate algebra is nothing more than a pointless punishment thrust upon poor school children for no other reason other than to satisfy the blood lust of an evil teacher.

Algebra meme
Algebra meme

Why does this upset me?

It upsets me because it not only validates ignorance, but it encourages it, it legitimizes the desire for people to not try learning it (imagine a kid at school seeing this, what is it teaching them about perseverance and education?).  I get it; if you struggled with algebra, it's comforting to laugh it off as useless anyway, but this is short-sighted. Even in jest, sharing this sentiment is damaging. This comfort blanket for you might mean an under-achieved potential for your child, or someone else's. Many future and current careers use and build upon the foundations laid by algebra in school (you think Facebook was created by people who did not get algebra?). Let's not do a disservice to the next generation by perpetuating and legitimizing ignorance just so we can feel more comfortable with our own. We all use the principles of algebra, whether we recognise it or not. Reworking a recipe for four people so that it will feed two, splitting a bill in a restaurant, or working out a budget, we use algebra. It may not look like algebra because we rarely write down some equation and then tell us to "solve for X", but it is algebra all the same.

Of course, it is not just anti-algebra sentiment that is being spread by misleading or seemingly innocuous memes. There are far more egregious examples, like those that perpetuate the myths that vaccinations cause Autism or harm more people than they help. These memes have the potentially deadly effect of reducing herd immunity and putting our most vulnerable individuals at risk; those that cannot be vaccinated at all.

Memes are powerful and yet so easy to spread. Just as with viruses that affect our physiology, some memes can be incredibly damaging, like a virus to the larger organism of society. My challenge to everyone is to think before sharing a meme, to fact check, to try to ensure a damaging myth or lie is not being perpetuated, perhaps share more positive memes that encourage rather than discourage. I know that some will think I am being far too serious and want to assert that "it's just a joke", but that does not change the way I feel, nor does it change the impact that "joke" has on others. I am not asking anyone to lose their sense of humour, just to think twice and share memes responsibly. Think about who might see a meme you share, what it might mean to them, and what they might learn from it.

Thanks for reading. Learn algebra.

How I got started with computers

I, like many others, enjoy the ramblings of Scott Hanselman. Recently, Scott posted a blog on how he got started in computers and programming and I thought I'd share my own story of getting started.

Domesday

It all began in the distant past (don't worry, the story isn't as long as it sounds) when I was at primary school (elementary school for those Americans reading). We were very fortunate in the UK during the 80s; the BBC was working hard to promote computer literacy. This culminated in a number of things, most notable (at least for this story) were the BBC Domesday Project and the BBC Micro.

The Domesday Project was a partnership between the BBC, Acorn Computers and various others to mark the 900th anniversary of the original Domesday Book, an 11th century census of England. It resulted in our school library having a laserdisc that gave us an unprecedented interactive view of the country.

The BBC Micro was the computing platform that formed a part of the Domesday Project and my formative programming experience thanks to the BBC's efforts to get one in every primary school in the UK.

A Domesday system at the Vintage Computer Festival 2010, Bletchley, UK
A Domesday system at the Vintage Computer Festival 2010, Bletchley, UK

We have lift-off!

It was a year or so after the Domesday Project had visited our school library. A BBC Micro sat conspicuously in my classroom day after day. I don't remember exactly how it started, but at some point I went from playing educational games on it to writing small programs in BASIC. I suspect it had a lot to do with a very inspirational teacher I had (Mr. Garbutt, I believe). He read fascinating books to us, he played guitar to us, he had us writing and remembering poetry and eventually, he had me writing software.

It was towards the end of my final year, shortly before my leap to high school, when I created my most elaborate program yet. It was a picture of a space shuttle complete with scaffold and a car with stickman owner for scale. It even had NASA written down the side (for someone who still struggled with some geometry at age 10, I am impressed with myself for rotating those letters). The program itself was more a feat of effort than it was of programming ingenuity; it was several hundred lines of MOVE and DRAW commands. However, that effort earned me a £10 book token and a printout of the drawing and the code used to create it. The printout has since been lost, but the book I purchased has journeyed with me and sits in my bookcase at home, inside it is taped the card that had contained the prize.

The book I purchased with my prize
The book I purchased with my prize
Inscription that accompanied my book token
Inscription that accompanied my book token

The Theory of Relativity

If it were not for the support and sacrifices of my family, that may well have been that. I would have left primary school and perhaps programming, behind. However, my parents recognized my interest and bought a home computer. It was a Tatung Einstein, a little known microcomputer and it was perfect for me to while away hours at home gaming and coding (now I come to think of it, this may be how I got my start with videogames too).

I wrote a whole host of programs for my Einstein including electronic versions of "choose your own adventure" books, an electronic Beatles album and a timetable manager for me and my classmates to use for who knows what. I even remember using the Einstein for our stall at a school business fair (I seem to recall it was some sort of murder mystery thing though I don't remember for sure).

Tatung Einstein and monitor
Tatung Einstein and monitor

Friend and Family

As my Tatung Einstein started to suffer from technical problems I set my sights on something grander; a Commodore Amiga 500. My parents sold our piano to afford this computer, much to the chagrin of my sister (and probably my piano teacher, although I'd already found my lack of talent by then). Meanwhile, at school I gained access to a 286 PC and an Apple Macintosh. The former was part of my science work and often included some lunchtime visits to Sid Meier's Civilisation with a very supportive science teacher, Dr. Stec; the latter helped me to write legible schoolwork for various classes (thanks, Mr. Simpson), assist in the publication of the school newspaper and learn about e-mail for the first time.

An Amiga 500 computer system, with 1084S RGB monitor and second A1010 floppy disk drive
An Amiga 500 computer system, with 1084S RGB monitor and second A1010 floppy disk drive (© Bill Bertram 2006)

And The Rest Is History

By the time I finished high school, my career aspirations were set and I headed off to get a degree in Computer Systems Engineering leading to my job as a software engineer. Along the way, I've had the opportunity to work with some amazing people on some great projects in some diverse circumstances and I owe it all to the opportunities I was given by the BBC, my schools, my teachers and my family. I will always be grateful for their support and the sacrifices that were made so that I could follow my ambitions.