C++ Coding Standards

May 30, 2006 @ 1:22 | In Books, Programming | 1 Comment | del.icio.us digg devbump rss

C++ Coding Standards. 101 Rules, Guidelines, and Best Practices
Author: Herb Sutter, Andrei Alexandrescu
Pages: 220
Published: 2005

Although a little bit tired of reading gem style books (Effective C++, Game Programming Gems, AI Game Programming Wisdom, GPU Gems, ShaderX, …) the authority of the authors made me find time to read C++ Coding Standards. Definitely, it was well invested time.

The book is divided in twelve sections (Organizational and Policy Issues; Design Style; Coding Style; Function and Operators; Class Design and Inheritance; Construction, Destruction, and Copying; Namespaces and Modules; Templates and Genericity, Error handling and Exceptions; STL: Containers; STL: Algorithms; Type Safety) each one having ten topics (more or less).

The book is more high-level than other related books (Effective C++, Modern C++ Design, Exceptional C++) and all the topics about C++ can be found in those books. You won’t find new topics or advices. But this book is about standars for your development team. In fact, it is designed to be used as a basic for your team’s coding standards. You can get good ideas from this book to be discussed with your team (and in fact, you do not have to agree all of them): coding conventions, hungarian notation, automated build system, version control, code reviews, etc.

Definitely, this book will help to improve the code quality of a team. My recommendation: read it.

Rating: 8 / 10



Efficient update of stl containers

May 17, 2006 @ 23:08 | In Programming | 6 Comments | del.icio.us digg devbump rss

Update: Fixed some bugs in the sample code.
Update: Note added in the third option about the hint.

I have seen dozens of times code like this to update an entry in a map:

typedef std::map<std::string, int> Items;
Items items;

Items::iterator it = items.find(”counter”);

if(it == items.end())
{
   items.insert(std::make_pair(”counter”, 1));
}
else
{
   it->second++;
}

The problem with this code is that you are traversing the map two times if the item is not found in the map, one for the first find and one more for the insert.

You can improve the code with something like this:

std::pair<items ::iterator, bool> res = items.insert(std::make_pair(”counter”, 1));

if(!res.second)
{
   (*res.first).second++;
}

This is notably better. You only traverse the map one time. But there is still a problem with this code: you are creating the pair even when you do not need it. In this case the pair is simple and its creation is not a problem, but imagine a pair with more complex objects hard to create. You can avoid the creation with a code like this:

Items::iterator lowerBound = items.lower_bound(”counter”);

if(lowerBound != items.end()
   && !(items.key_comp()(”counter”, lowerBound->first)))
{
   lowerBound->second++;
}
else
{
   items.insert(lowerBound, std::make_pair(”counter”, 1));
}

Although being more efficient, this code is more obscure, so in case you do not need those nanoseconds you can live with the more clear second option. Apart from being more obscure, the hint is only that, a hint. The implementation can ignore it. As noted by Steven in the comments below, Visual Studio ignores it for the hash_map, hast_set containers.



Running your own server (@home)

May 15, 2006 @ 17:44 | In Internet, Linux | 7 Comments | del.icio.us digg devbump rss
http://entland.homelinux.com/images/zen.jpg

I wanted to start a topic (the first on Linux, I promise more on this) about the hardware machine where this blog is hosted: a machine installed in one corner of my living room. I bought the box to be the server for all my machines at home (personal computer, media center, videogame consoles, ip camera, fileserver…). Being network security one of my hobbies I am always playing with security tools. That is one of the reasons why I decided to host this blog in my home server: to play with a new toy. :-)

In the past, whenever I installed a linux distribution (SUSE most of the times) I always finished mutating it to my own distribution due to the fact that these clasic distributions evolve too slow. This was frustrating and time consuming for me because I had to mantain lot of packages and some big changes (gcc, glibc) could break the system. When I was starting to build my own personal distribution (based on Linux From Scratch) I discovered Gentoo. Gentoo Linux is the perfect distribution to me. It is based on source (every package you install must be compiled) and it is continuously evolving like an organic system.

This is the current hardware configuration for my Linux Box:

I have an internet connection with a dynamic IP. To be always accessible I’m using the services from DynDNS.

And that is enough for today, my next article on this topic will be about tips & tricks on security to avoid to be owned. :-o



E3 2006

May 9, 2006 @ 2:05 | In Videogames | No Comments | del.icio.us digg devbump rss

E3 2006 (the world’s premier computer and video game trade event) will open its doors in few hours.

Don’t miss the conferences given by the big ones in the preshow events: Sony (being retransmitted now by GameSpot), Nintendo (Tue. May 9, 9.30AM PDT) and Microsoft (Tue. May 9, 12.00PM PDT)

UPDATE: Live coverages of the events: Sony, Nintendo and Microsoft

UPDATE: Halo3 E3 Trailer 720p



Documentation using XML

May 2, 2006 @ 17:05 | In Programming | No Comments | del.icio.us digg devbump rss

I describe in this document the tools I have been using in my last work to generate the documentation of a big project (15+ people, and 3+ years). If you think the documentation process of your current project can be improved you should have a look at this. I expect this information to be useful to somebody.

Click to read the full article



Fri, 25 Jul 2008 11:38:38 +0200 / 21 queries. 1.487 seconds / 2 Users Online

gentoo link wordpress link apache link PHP link website stats

Theme modified from Pool theme. Valid XHTML and CSS