Thursday, November 20, 2008

Google goodness

If you write much code in c++ you might find the standard library a bit lacking compared to other languages. I know for example python and java both have a lot more stuff in the standard library. The C language has a lot of good stuff in libraries like glibc that can be used in C++, but it has always felt to me C++ lacks tools. Because of this lot of different third party library are out there. The thing I don't like about this is they are not standard and you end up with five libraries doing the same thing have way. Anyway enought ranting if I don't like it I should start using python. What I am trying to get to is lately I have found a lot of handly simple libraries coming out of Google. So I will list some and what they do and why I think they are nice.

Memory allocation with tcmalloc (google-perftools)

I have post about this before a little and how in linux at least it is very easy to change the libc memory allocator with others like jemalloc or tcmalloc. So far I have not used tcmalloc much but it is a nice tool to have around because it is suspose to be fast and not frament the memory as bad. It also has a lot of stuff to debug memory leaks and so on. The coolest thing is it is very easy to test you don't every have to recompile your code to see it in action just preload the library.

Command line parsing with gflags

In libc there is get-opt which is not a bad way of parsing the command line but it is C and very bare bones. The gflags library is a nice step up. I make a help flag for you and you can add flags in different parts of the code. I find that nice if I just need to make a setting I put the flag code there and move on. I sure some people who say it is bad for some reason, but to me in a small project it is easy and fast.

Logging with glog

I have looked into logging library a lot over the last few year. Now of them have every looked great to me. Log4cxx I discovered is powerfully and the best I have seen but it depends on a lot of stuff and is almost to complex. That is why when I turned up glog I was very happy today. I thought google would have a logging library but could not find it. I looks like the open source release of glog was very recent. I have not dug very deep but it looks like a good project done google style. It can also use gflags if you already have that which is nice. As it goes to a 1.0 release I think it might just become my logging library of choose.

Serialization with protocol buffer

Now this one is not just for C++ and has Google support for Java and Python with many other langages getting supported by the open source comunity. It appears this is one of Google's core technologies and I am betting must people have used them if they used the internet in a round about way. Anyway for C++ this is nice because again there is not standard serialization stuff. With C++ running closer to the metal serialization is not a fun cross platform thing to handle. Protocol buffer's has some nice ideas and seem easy to use for simple stuff. You just make a message in Google made up way and then it ran a compiler type thing that truns that into C++ and you are ready to put stuff on the disk or send it to Mars. It has nice stuff to add thing latter which is important.

Testing with gtest

Now that you have all these nice libraries to write code with you need to test that code. That is where gtest comes in. Again it seems simple, clean, and easy to use. It can even create colored output. If you are into unit test it seems a good as choice as any. I still don't know how to write good test and in some types of code it seems hard to test. But if I do I would look here first.

Compiling with distcc

Now that you writing all that code want compile it in a fast way. Well if you have a few computers setting around try distcc to speed up that compile time. While not created by Google it is now being develop by Google.

Well I am sure I forgot something but that is my list of Google goodness. Here at pezad games I see the tcmalloc, protocol buffers, gflags, and perhaps glog being the usefully. But until I quit stalking Google and start writing more code we will never know :).

2 comments:

Redsaz said...

Google just announced (a few hours before your post, before it hit major programming news sources) WHOPR, which is designed for whole program optimization (WHOle PRogram), instead of merely optimization within files themselves. Read more about it at their blog.

paul said...

Yea! I think we will still have to inline simple function in header file for now. Until this get done or LLVM over takes gcc and is better (if that ever happens). But very cool stuff.