Ars Technica recently posted an article taken from Stack Exchange about comments in code. It’s a thorny subject with programmers. “Why should I comment my code – I know what it does?”.
Sure, you do. But what happens if I need to come and work on your code – in a hurry?
I’m speaking from experience here. Bitter experience. I’ve had to dive into code, in a hurry, to fix something, because a client is on the phone, screaming, and screaming loudly that this needs to be fixed. Today. Or There Will Be Consequences.
And the code was horrible. Layer upon layers of classes with cryptic but “self-descriptive” names. Sure, he was following the “Code Complete” method of working – “regard every comment as a personal failure”. “Clean Code” has the same thing.
Here’s a tip for you: take those two books, find the pages where it says this about comments, and cross it out. Because while both books are incredibly useful, they are completely and utterly wrong about comments. Their advice is harmful, dangerous, and leads to sloppy, unmaintainable code. It promotes a sheer lack of professionalism, and it’s dangerous. If either of the authors came to me for a job, I would turn them down, even if I were short staffed and they were the only candidate, for this reason, and this reason alone.
What I needed in that circumstance wasn’t “self-documenting code”, what I needed was signposts – I needed to be able to find my way to the trouble spots – fast. Even single-line comments giving a brief description of what the class did would have helped. I’ve worked on badly written projects that were more maintainable than ones that are paragons of excellent code entirely due to this issue. I’d take a well-commented, bug-ridden crawling horror over some comment-less mediocrity any day.
Comments are not a failure, nor should they be regarded as such. One answer they mention in Ars demonstrates exactly and precisely why comments – even bad ones – are essential, without even realising it. Take a look at this, from an answer by Paul:
They often lie. You cannot trust comments and must read the code instead. Which raises the question: why would you need the comments at all?
// this method returns the sum of 'a' and 'b'
public int GetHash(int a, int b)
{
//the calculation of the hash
int result = a*b;
}
(The hash is not the sum but the product.)
Sure, that’s a bad comment. But it documents what the programmer was expecting the code to do. If this is where the error is found, then it should raise alarm bells. Check your source code control logs (you do use Subversion, TFS, git, or something like that – right?). Is it simply a typographical error? Did it get changed for debugging and nobody changed it back? Did it get changed – even though it’s wrong – to get a badly written test to pass? I’d argue that the comment isn’t wrong here, not at all – it’s a clue as valuable as the curious incident of the dog in the night-time.
But let’s diverge for a moment – what if the comment were more illuminating?
// this method used to return the sum of 'a' and 'b'
or how about the even more useful:
// this method used to return the sum of 'a' and 'b'
// 1999.09.09 (SC) changed to be compliant with protocol v2
In reality, I don’t think anyone that doesn’t comment their code can, or should, ever be called a “professional” programmer. I’ve worked with many bright minds who develop over-complicated systems that have caused their colleagues problems when the inevitable happens, and they have to take over the maintenance of the project.
It’s not for nothing that Microsoft StyleCop bitches when you don’t comment what your code does. Much as I don’t particularly enjoy working with StyleCop’s rules, that’s one I’m totally in favour of.
In short folks, my attitude is simple: either learn to write effective comments, that signpost what the things you have written are supposed to do, or go find a job doing something else. Because until you can write effective comments that enable other people to modify your code, you’re not a professional who makes positive contributions at work – you’re a dangerous liability who is endangering your employer’s very existence.
Rant over.
May 13
18
Intel – takeover target, or takeover king?
Posted by simon on 2013/05/18
Posted in Comment | Tagged With: Android, Apple, ARM, Google, Intel, iPad, iPhone, Microsoft, Oracle, Windows, Windows 8 | No Comments yet, please leave one
There’s been an awful lot of rumours about Intel and takeovers recently. One, that Intel is about to buy (or merge) with AMD. Another, that Apple might be about to buy Intel. Well, there aren’t that many companies that have the financial clout to buy Intel, but there are a few that might want to buy them. Here’s what I think.
A takeover of Intel by Apple would make perfect sense for Apple, if not Intel. In fact, I’d say it ought to be right at the top of Tim Cook’s “To Do” list.Apple have recently started designing their own ARM chips for iPads and iPhones. It would make sense to buy Intel, decommission some of the products and turn their fabs over to making their own chips – which they’ve been designing themselves for a few years now. It means not having to deal with pesky outside suppliers like Samsung, with whom they have a bit of a history.
It would prove disruptive in the external market too – they could easily drop the mobile chips for external suppliers, which although it would pass the market over to AMD for Windows laptops, and effectively kill the Surface Pro, it would have a strategically far more important result – ending Intel’s push for Android. And more traction for Android is something Apple can’t really allow to happen.
Oracle earn bucketloads of cash, and already own the SPARC architecture through Sun – a hardware business they’ve been growing. Owning Intel would give them a way into the x86 server market, either with Solaris on x86 or their own version of Linux. It would also essentially give Oracle a very hefty slice of the “Windows tax”, as they would now be providing the chips for probably 80% of the Windows market. It would give them access directly to Intel’s design department, with the inevitable consequence that Intel could produce a line of processors “optimised for Java”.If Oracle really wanted to play hardball, of course, it wouldn’t then be out of the way to suggest to Microsoft that if they want that ready supply of Intel chips to continue, they might want to consider discontinuing that pesky “SQL Server” product with immediate effect – whether that’s legal or not, I’ll let the lawyers fight over, but I can imagine it causing Larry Ellison to purr with delight; it is, after all, pretty much the same sort of squeeze Microsoft put on OS/2 back in the day.
Legally speaking, this one would probably be the most difficult to achieve. I can imagine the DoJ would have something to say, and AMD would be right there, knocking on the door.Nevertheless, Intel’s recent announcement of upcoming Android notebooks must be alarming Redmond, and I can imagine that being pretty high up on Microsoft’s list of “things we really don’t want to happen”.
This one is quite the maverick on this list, but let’s think a moment.Google got into the hardware market by buying Motorola – mainly as a hedge to get Microsoft off Android’s back. That didn’t work. Owning Intel would pull the rug out from Microsoft, and essentially reverse the balance of power between the two companies, forever. Google would be able to dictate terms, and Microsoft could do little more than acquiesce meekly, knowing that Google essentially controlled enough patents, and enough of the market structure, to play enough hardball to strangle Microsoft’s businesses at any second. Certainly, the “Android tax” would stop overnight – it would have to, if Microsoft wanted to continue to work with the makers of Android – who would now be the largest supplier of the chips on which the vast majority of their software runs. Their only route out would be to push Windows entirely to an ARM-based infrastructure – something that’s not working very well right now.
As John-Louis Gassee pointed out, Intel are weak right now. They’re ripe to be taken over. For Apple or Google, Intel would represent the prize: control of the industry.
If Intel survives as a separate entity by the end of the year, I’ll be extremely surprised.
And once they’re gone, who’ll buy AMD?