Top 5 favorite modern C++ features

I must say, when I first started dabbling in computer programming, C++ was not at all my first choice of language. The general perception of C++ that I got from my friends and from forums were like…

C++ is a language for really, really smart people.
Each line of code is about 30-40 characters long on average, if not longer.
Everything is needlessly difficult and fraught with pitfalls.
There are so many *, #, &, <>, (), {}, /, [ ], <<, ::, and ! symbols everywhere that it looks like comic book characters swearing.
Before you even think of attempting C++, you should first know C well.
It is impossible to know the whole language. Even people who have been learning it for 15 years have barely even scratched the surface of what is possible.
Template metaprogramming is the devil.

Looking back on these statements today, as someone who now programs mostly in C++ for fun, I see a grain of truth in each of them. C++ is certainly not perfect. Far from it; it is a flawed, verbose, error-prone, needlessly complicated, sometimes rage-inducing language.

But why do I write in it, then, if it’s so terrible? And why for fun? Well, I probably would have never picked up C++ in the first place if the ISO C++11 standard hadn’t come out.

At the time, I was playing around with straight C for a while since I moved to Linux, though with time I found it to be a little too spartan for my taste. I was interested in learning C++ to make games since many well-known game frameworks use the language natively, and I wanted to carry over my C knowledge.

Originally dubbed “C++0x” before delayed to 2011, the C++11 standard added a ton of new and attractive features which attracted people like me, who were previously used to C#, Java, Go, Ruby, Python, etc. Due to extremely positive reception in the C++ community, the ISO committee has been hard at work creating the C++14 standard, and the up-and-coming C++17 standard. These last few iterations have been made such radical changes to the core language that they are colloquially referred to as “modern C++.”

C++11 feels like a new language. I write code differently now than I did in C++98. The C++11 code is shorter, simpler, and usually more efficient than what I used to write.

β€” Bjarne Stroustrup, creator of C++,

These features made me comfortable enough to dive into C++, though they are not necessarily the reasons why I decided to stay. I stayed because I could now work almost as efficiently as I could in C# or Java, but at the same time I had the gory insides of the machine exposed to me. That’s right, I actually found it refreshing to see why the computer behaved the way it did, and not only that, I loved the fact that I could drop the fancy object-oriented stuff and fall back to glorious old C if I ever needed to. C++ also blew my mind several times over in regards to what I thought was possible to get computer programs to do (I’m looking at you, template metaprogramming).

So grab a beverage and some popcorn, because here come my top 5 favorite “modern C++” features.

Read more

Library Review: SFML

Visit SFML's project page

Hello everybody and welcome! I decided that I will review a very, very useful cross-platform library that I have been using often lately called SFML, which stands for “Simple and Fast Media Library”. For those who don’t know, SFML is a game library (at version 1.6 at this time of writing), which is a collection of C++ functions that can aid you in making games, and is similar in spirit to another more mature game library called SDL (“Simple DirectMedia Layer”).

Let’s say that you wish to create a sidescroller like Mario, for example. Instead of researching deeply through the net and going into the nitty-gritty of setting up the window and coding unimportant (but complex) components, you could simply bundle SFML together with your project’s code. SFML can take care of playing the sound effects or video cut-scenes, displaying textures and loading game maps, interacting with OpenGL for 3D graphics, etc. while you focus on actually writing the game logic itself.

❗ NOTE: SFML is not a game engine! It is a bit more low-level than that, and it does not include any drag-and-drop editors or media creation tools. It’s purely source code, and you are expected to already know how to program in order to use it. However, itΒ  is powerful enough that it could actually help you create a game engine of your own.

In this review, I will go over the features of the library and explain what it can do. I will also supply an example C++ snippet that demonstrates how to initialize SFML, along with step-by-step explanations of what the program does and how it works. I will finish by outlining SFML’s pros and cons, summarizing my overall impressions, and telling you whether it is worth being in your toolbox as a programmer.

Read more

Better WPF tab controls, anyone?

As my first post (w00t!), I’d like to give a shout out (and hopefully direct some traffic) to a great project going on at CodePlex for some time now: FabTab. These guys have been developing a wonderful replacement for the stock WPF tab control for some time now, and since I like to use it, I thought this would be a nice first post to repay them. It’s got tons of improvements, including a built-in “Close tab” button, an Internet Explorer-esque “QuickTab” capability, a tab list, real-time pop-up thumbnails, badass animations when switching between tabs, drag-and-drop tab reordering, and lots more. I’ve been using it for a while and I love it!

If that sounds pretty good to you, and you’d like to learn more or download this library (as a *.dll to link with your application), you can get it at their project page at CodePlex. Below is a screenshot of the example program in action, and it’s pretty epic.

Anyway, I think that the FabTab library is great, and I give major props to the devs. πŸ™‚