Category Archives: Today I Learned

Today I Learned: Tail Call Elimination

Who said interviews were just about testing knowledge? In some cases, it can be a bit of a learning experience for everyone involved. Case in point, I was asked about what kind of compiler optimization may be made from the following code:

int CountOccurences(LinkedNode const * const head, int const dataToCount, int occurences)
{
	if (head == nullptr)
	{
		return occurences;
	}
	if (head->data == dataToCount)
	{
		++occurences;
	}
	return CountOccurences(head->link, dataToCount, occurences);
}

My initial reaction was that maybe the compiler would attempt to do something to our const vars on the stack, considering they never change in the function. Turns out, there is something more going on here.

Continue reading

Recommended Viewing: Ubisoft CppCon 2014

Checkout these two great talks from Ubisoft @ CppCon 2014 featuring multicore C++11 development and how C++ is used to develop AAA games at Ubisoft. I briefly met Nicolas Fleury and learned many tips from blurbs he’s written about good C++ practices and such. He’s very talented.

 

 

Today I Learned: Range Insertions Are Better

Happy fourth-of-July, my American brethren. Sorry Canada, I went home for the weekend!

During my flight home, I started musing some of my unread C++ ebook collection and decided to start with Effective STL by Scott Meyers, the same author as the awesome Effective C++ book I reviewed. One of the first Items covered is how range member functions are better than single elements! I find this extremely intriguing. I never heard of this and I sure wasn’t taught this amazingly simple and clearly superior concept in school.

Continue reading

Recommended Reading: JURASSIC PARK: TRESPASSER CG SOURCE CODE REVIEW

Jurassic Park Trespasser, in 1998, had ridiculously awesome features being touted for its time. Fully detailed outdoor environments, hyper realistic physics, advanced graphic features like bump mapping. It was way ahead of its time. But it didn’t sell too great!.

This interesting article takes a look at the source code behind the project which, for its time, may have been “too complex” for C++ which has since evolved a ton. Interesting how no precompiled headers weren’t used so therefore hours of compile time were done. Good reading.

Today I Learned: Struct Packing With A Microsoft Twist

Member declaration order for structs and classes are important. You want to order the smallest to the largest (or vice versa) in order to avoid what’s known as ‘padding’. Padding is basically what the compiler will use to keep the memory allocation of the struct/class aligned in memory. This padding tends to be wasted space unless some compiler specific enhancement is occurring.

What I learned today was that Microsoft’s C++ compiler actually has extra padding involved, by design. And the solution to avoid the extra previous memory being stolen from you? Quite elementary, how could you not know? Inheriting from an empty abstract class makes your objects smaller.

Continue reading

Today I Learned: Never Rely On Memory – Let The Code Do It For You [If You Can]

So this is something I’ve seen two large camps pitted against each other for. Programmers should always be responsible for the code they write and should always be actively trying to write responsible code in itself. I think everyone can get behind that without much quarrel. But! One camp tends to argue that the programmer should ensure there is ~absolutely~ no way for things to blow up while the other camp argues that the programmer should place ‘checks’ in the code in the possibility that it does.

Hopefully the issue is clear.

Should a programmer place checks in their code to not only protect users in the future, but also themselves? “Why wouldn’t you?” your reaction may be. Well, you might have a complex piece of code that would take a lot of resources to constantly check will work properly. The goal is to make sure your code is exception-safe as much as possible, but there is always someone out there who will holler out “at what cost?!” If something is expected to work one way, that should be the ~only~ way it will ever work they argue!

It boils down to a kind of elite purist paradigm vs a human-error safe paradigm. Both have merit!

I made a pretty timely and amateur mistake today because I was running the purist paradigm. I’ll talk about how I should have placed checks to save myself and evidently my boss about 2 hours of time. But at the same time the issue could’ve been easily avoided and no check at all would’ve been needed if I didn’t rely on my faulty memory.

Continue reading

Today I Learned: Connections Can Come From Anywhere

So GDC 2014 starts this Monday and as much as I want to go, I only went last year to shoot for an awesome internship. The people, the booths, the information were all great but its hard to justify the cost to get down there right now especially now that I do have an awesome internship at Ubisoft.

But something hilarious happened today in relation to GDC and, to some it might not be a big deal, but to me its just… WOW the coincidence. And its just so inspiring and now if I truly had the money, I’d jump right back on the plane to GDC again.

Continue reading

Today I Learned: WPF Templates

Ugh XAML. Functional its really nice, and with Windows Presentation Foundation, it makes for some really awesome GUIs. You can do all kinds of cool data binding and automatically display information. A few projects about a year or so back using WPF XAML and C# is what reinvigorated my love for programming, which admittedly was looking down for awhile. But damn is it messy. Quick example: You can make an excel grid automatically display the data members in your class. If you had a class of Customers, with all kinds of Customer info, you can bind the grid to a list/array or collection of Customer and have it automatically display this info. So awesome! But, what if you wanted a specific kind of grid with specific properties? Continue reading