A recent highly-voted-up question on Programmers asked what’s wrong with comments that explain complex code? I think quite a bit about how I comment my code but rather than posting an answer on Programmers I thought I’d blog about it a bit here. I already discussed this topic — HOLY GOODNESS TEN YEARS AGO wow I have been writing this blog for a long time — and everything I said then still applies. But today thanks to Roslyn being open-sourced there is now a large corpus of my code on the internet so I can talk about my comment strategy in the context of real production code. Continue reading
Author Archives: ericlippert
ATBG: Ontogeny, phylogeny and virtual methods
I’m back! As always, I had a delightful August visiting friends and relatives in Canada. It was even more fun than usual because I’ve got a new boat. That is, a new-to-me boat; the boat is almost as old as I am. It’s a 1976 avocado-green Hobie 16. Here’s a video I shot of my first time trying it out: (I recommend watching it in HD resolution.)
Well enough chit-chat, back to programming language design. Today on the Coverity Development Testing Blog’s continuing series Ask The Bug Guys I’ll discuss how C++ is like a discredited theory of evolutionary biology and why that means you should not call a virtual method in a constructor.
What is up with transparent identifiers? Part two
This will be my last post before I head off for my annual vacation in Canada; see you again in September for more Fabulous Adventures in Coding!
Last time on FAIC I suggested a rule for translating nested “from” query expressions into a much simpler form than the C# specification requires. Why does the C# specification not use my simplified form?
In fact what I showed yesterday is pretty close to what the LINQ translation rules for SelectMany queries looked like shortly before shipping C# 3.0. The problem with it becomes apparent when you consider the following: Continue reading
What is up with transparent identifiers? Part one
A query expression in C# is, as you probably know, just a syntactic sugar for a bunch of method calls. For example,
from customer in customers where customer.City == "London" select customer.LastName
is a syntactic sugar for
customers. Where(customer => customer.City == "London"). Select(customer => customer.LastName)
A great many queries are straightforward variations on this pattern: the query is translated into a series of method calls where the arguments are lambdas formed from the range variables and expressions in the query. However, some of them are weird. This one is straightforward: Continue reading
Casting: making a green sand mold
Today another episode in my seldom-updated series about building a home aluminum foundry.
The technique I use for casting aluminum is called “green sand” casting not because the sand is green (though the sand I use is in fact slightly olive coloured) but because the sand is moistened with water and clay rather than oil. I made the sand myself; it’s a mixture of about ten parts olivine sand to one part finely powdered bentonite clay, and then “tempered” with water until it feels right. (Use a spray bottle set to a fine mist and stir the sand as you temper it.) It should feel like perfect sand castle building material: wet enough to hold its shape but not so wet that you can squeeze water out of it. If you can make a “snowball” of sand with a fist and break it cleanly in half, that’s probably good. Continue reading
Short questions
Finishing off my series of questions people asked during my recent webcast that I didn’t have time to answer, some short Q&A: Continue reading
Analyzing test code
Continuing with my series of answers to questions that were asked during my webcast last week…
Do the “checkers” (algorithms that find specific defect patterns) find defects in unit testing code?
If you want them to, yes. Continue reading
Copy-paste defects
Continuing with my series of answers to questions that were asked during my webcast on Tuesday:
The copy-paste checker example you showed was interesting. I’ve heard that NASA disallows copy-pasting in code because it is so error prone; is this true?
For readers who did not attend the talk: my favourite Coverity checker looks for code where you cut some code from one place, pasted it in another, and then made a series of almost but not quite consistent edits. An example taken from real world code is: Continue reading
Analysis vs code review
Thanks to everyone who came out to my “webinar” talk today; we had an excellent turnout. Apologies for the problems with the slides; there is some performance issue in the system where it works fine when it is not under load, but when there are lots of people using it, the slides do not advance as fast as they should. Hopefully the hosting service will get it sorted out.
As I mentioned last time, the recording will be edited and posted on the Coverity blog; I’ll post a link when I have one.
We got far, far more questions from users than we could possibly answer in the few minutes we had left at the end, and far too many to fit into one reasonably-sized blog post, so I’m going to split them up over the next few episodes. Today:
What percentage of defects does the Coverity analyzer find that should have been caught by code review? Continue reading
Avoiding C# defects talk Tuesday
Hello all, I have been crazy busy these last few weeks either traveling for work or actually programming with Roslyn — woo hoo! — and have not had time to blog. I’ve been meaning to do a short tour of the Roslyn codebase, now that it is open-sourced, but that will have to wait for later this summer.
Today I just want to mention that tomorrow, July 15th, at 8:30 AM Pacific Daylight Time, I’ll be doing a live talk broadcast on the internet where I’ll describe how the Coverity static analyzer works and what some of the most common defect patterns we find are. In particular I’m very excited by a new concurrency issue checker that looks for incorrect implementations of double-checked locking, and other “I avoided a lock when I should not have” defects. My colleague Kristen will also be talking about the new “desktop” mode of the analyzer.
If you’re interested, please register beforehand at this link. Thanks to Visual Studio Magazine for sponsoring this event.
If you missed it: the webcast will be recorded and the recording will be posted on the Coverity blog in a couple of days. The recording will also be posted on the Visual Studio Magazine site link above for 90 days.