The Great Divorce
Posted
by BlackRabbitCoder
on Geeks with Blogs
See other posts from Geeks with Blogs
or by BlackRabbitCoder
Published on Wed, 14 Apr 2010 20:28:35 GMT
Indexed on
2010/04/15
3:33 UTC
Read the original article
Hit count: 396
I have a confession to make: I've been in an abusive relationship for more than 17 years now. Yes, I am not ashamed to admit it, but I'm finally doing something about it.
I met her in college, she was new and sexy and amazingly fast -- and I'd never met anything like her before. Her style and her power captivated me and I couldn't wait to learn more about her. I took a chance on her, and though I learned a lot from her -- and will always be grateful for my time with her -- I think it's time to move on.
Her name was C++, and she so outshone my previous love, C, that any thoughts of going back evaporated in the heat of this new romance. She promised me she'd be gentle and not hurt me the way C did. She promised me she'd clean-up after herself better than C did. She promised me she'd be less enigmatic and easier to keep happy than C was. But I was deceived. Oh sure, as far as truth goes, it wasn't a complete lie. To some extent she was more fun, more powerful, safer, and easier to maintain. But it just wasn't good enough -- or at least it's not good enough now.
I loved C++, some part of me still does, it's my first-love of programming languages and I recognize its raw power, its blazing speed, and its improvements over its predecessor. But with today's hardware, at speeds we could only dream to conceive of twenty years ago, that need for speed -- at the cost of all else -- has died, and that has left my feelings for C++ moribund.
If I ever need to write an operating system or a device driver, then I might need that speed. But 99% of the time I don't. I'm a business-type programmer and chances are 90% of you are too, and even the ones who need speed at all costs may be surprised by how much you sacrifice for that.
That's not to say that I don't want my software to perform, and it's not to say that in the business world we don't care about speed or that our job is somehow less difficult or technical. There's many times we write programs to handle millions of real-time updates or handle thousands of financial transactions or tracking trading algorithms where every second counts. But if I choose to write my code in C++ purely for speed chances are I'll never notice the speed increase -- and equally true chances are it will be far more prone to crash and far less easy to maintain.
Nearly without fail, it's the macro-optimizations you need, not the micro-optimizations. If I choose to write a O(n2) algorithm when I could have used a O(n) algorithm -- that can kill me. If I choose to go to the database to load a piece of unchanging data every time instead of caching it on first load -- that too can kill me. And if I cross the network multiple times for pieces of data instead of getting it all at once -- yes that can also kill me. But choosing an overly powerful and dangerous mid-level language to squeeze out every last drop of performance will realistically not make stock orders process any faster, and more likely than not open up the system to more risk of crashes and resource leaks.
And that's when my love for C++ began to die. When I noticed that I didn't need that speed anymore. That that speed was really kind of a lie. Sure, I can be super efficient and pack bits in a byte instead of using separate boolean values. Sure, I can use an unsigned char instead of an int. But in the grand scheme of things it doesn't matter as much as you think it does.
The key is maintainability, and that's where C++ failed me. I like to tell the other developers I work with that there's two levels of correctness in coding:
- Is it immediately correct?
- Will it stay correct?
That is, you can hack together any piece of code and make it correct to satisfy a task at hand, but if a new developer can't come in tomorrow and make a fairly significant change to it without jeopardizing that correctness, it won't stay correct.
Some people laugh at me when I say I now prefer maintainability over speed. But that is exactly the point. If you focus solely on speed you tend to produce code that is much harder to maintain over the long hall, and that's a load of technical debt most shops can't afford to carry and end up completely scrapping code before it's time. When good code is written well for maintainability, though, it can be correct both now and in the future.
And you know the best part is? My new love is nearly as fast as C++, and in some cases even faster -- and better than that, I know C# will treat me right. Her creators have poured hundreds of thousands of hours of time into making her the sexy beast she is today. They made her easy to understand and not an enigmatic mess. They made her consistent and not moody and amorphous. And they made her perform as fast as I care to go by optimizing her both at compile time and a run-time.
Her code is so elegant and easy on the eyes that I'm not worried where she will run to or what she'll pull behind my back. She is powerful enough to handle all my tasks, fast enough to execute them with blazing speed, maintainable enough so that I can rely on even fairly new peers to modify my work, and rich enough to allow me to satisfy any need.
C# doesn't ask me to clean up her messes! She cleans up after herself and she tries to make my life easier for me by taking on most of those optimization tasks C++ asked me to take upon myself. Now, there are many of you who would say that I am the cause of my own grief, that it was my fault C++ didn't behave because I didn't pay enough attention to her. That I alone caused the pain she inflicted on me. And to some extent, you have a point. But she was so high maintenance, requiring me to know every twist and turn of her vast and unrestrained power that any wrong term or bout of forgetfulness was met with painful reminders that she wasn't going to watch my back when I made a mistake. But C#, she loves me when I'm good, and she loves me when I'm bad, and together we make beautiful code that is both fast and safe.
So that's why I'm leaving C++ behind. She says she's changing for me, but I have no interest in what C++0x may bring. Oh, I'll still keep in touch, and maybe I'll see her now and again when she brings her problems to my door and asks for some attention -- for I always have a soft spot for her, you see. But she's out of my house now. I have three kids and a dog and a cat, and all require me to clean up after them, why should I have to clean up after my programming language as well?
© Geeks with Blogs or respective owner