Posts Tagged ‘.net’

The meaning of RAII — or why you never need to worry about resource management again

Saturday, January 2nd, 2010

I tried really hard to come up with some witty title or pun to weave into the title of this post. I couldn’t. RAII is just a ter­ri­ble name, and it isn’t really clever or funny. Unfor­tu­nately, it is also the sin­gle most impor­tant key to C++. It is not just an idiom but a fun­da­men­tal phi­los­o­phy used to solve almost any prob­lem in the lan­guage. So we can’t really avoid it.

If I had to pin­point one thing that marked the dif­fer­ence between a skilled and an unskilled C++ pro­gram­mer, it would be “do they under­stand RAII”. Many peo­ple don’t, hence this post. (more…)

A .NET Developers Guide to C++ (part III)

Thursday, October 1st, 2009

We’re near­ing the end!

Part I focused on the very fun­da­men­tals of C and C++, mak­ing sure that you under­stand the build sys­tem and the very basics of the syntax.

Part II expanded on this to teach you all the C++ you’ll need to do basic work in the lan­guage, includ­ing a few use­ful parts of the stan­dard library, such as vec­tors and strings.

You now know all the basics we need, and the actual Win32 API should now be very sim­ple to deal with. Not ele­gant or con­sis­tent, but com­pre­hen­si­ble as long as you keep a close eye on the doc­u­men­ta­tion and take noth­ing for granted.

(more…)

A .NET Developers Guide to C++ (part II)

Tuesday, September 8th, 2009

Wel­come to the sec­ond install­ment in my guide of “what you need to know if you’re a .NET pro­gram­mer who wants to be able to write C++ code and call native APIs”. It took me much longer to get this posted than I’d hoped. My work on my the­sis has kept me more busy than I’d orig­i­nally expected. Sorry for the delay!

In part I, I went through a min­i­mal “Hello World” pro­gram in some detail, and attempted to explain the arcane work­ings of the C/C++ com­pi­la­tion model. Some may argue that this had no rel­e­vance to my tar­get audi­ence, but I think it is a nec­es­sary evil. Almost all C++ pro­gram­mers get tripped up at some point by the the dif­fer­ence between com­piler and linker errors, and what exactly the #include direc­tive actu­ally does. Hope­fully, by read­ing part I, you’ll be able to avoid this.

With that out of the way, we can get started on the inter­est­ing part, though. Part II will focus on actual C++ code. We won’t con­sider man­aged interop or even the Win32 API yet, though. This part will still take place in native C++-land only. In short, the pur­pose of this part is to enable you to write sim­ple C++ pro­grams, and more impor­tantly, to under­stand the C++ sam­ple code you prob­a­bly run into from time to time.

(more…)

A .NET Developers Guide to C++

Monday, August 17th, 2009

One of my cowork­ers is essen­tially a self-taught pro­gram­mer, but he is inter­ested in, and wants to learn, absolutely every­thing. A year or two back, he asked me to give him a crash course in C++, because he felt it was a prob­lem that when­ever he needed to do some­thing that required func­tion­al­ity not exposed by the .NET frame­work, he essen­tially hit a wall.

So we took an after­noon out to run through some basic C++ code, and while we had fun doing it, and I’m pretty sure he found it inter­est­ing, it didn’t really achieve the goal of mak­ing him com­fort­able with writ­ing small C++ pro­grams to com­mu­ni­cate with native APIs such as the Win­dows one.

(more…)