Friday, December 14, 2012

auto overused

I had recently read on an article on a programming subject not related to C++11 but which uses C++11 constructs to explain the point. It is nice to see that C++11 is being adopted this way. However one thing that scared me was the overuse of auto keyword.

const auto MAXSIZE = 10000;

for (auto i = 0; i < MAXSIZE; ++i)
{
...
}

This chills me to the bone. Why not use int or size_t? Of course this simple code doesn't show the complete threat that is the overuse of auto. But this introduces a culture where is OK to use auto everywhere.

My feeling about auto is that it is a tool best fitted for generic programming or where writing the type is difficult, complicated or impossible. Compare this:
std::vector<int> v;

for (std::vector<int>::const_iterator it = v.begin(); it = v.end(); ++v)
{}

with the better:

std::vector<int> v;

for (auto it = v.begin(); it != v.end(); ++v)
{}

but this is even better and clearer:
std::vector<int> v;

for (int &i : v)
{}


Excessive use of auto can lead code that is hard to read and to maintain. Maintenance is all about code reading. Please take care.

Sunday, December 02, 2012

Why another XML parsing library?

Some may have noted that in the December 2012 release of my MinGW Distribution I have included yet another XML parsing library: pugixml. Why this if it already has libxml2?

Well, while libxml2 is a complete, standard-compliant XML parsing library it lacks a DOM interface. With DOM it is easier to handle and to walk through the XML representation.

I have evaluated many simple to use, fast libraries: RapidXML, FastXML, AsmXML. And, of course pugixml. However pugixml is fast, has a good documentation and a DOM-like, modern interface that fits well with STL and C++11 ranged-for and lambdas. That was I was looking for.

MinGW Distro - December 2012 Release

Some people have reported that my website is down. Unfortunately depending where in the world you are the site is accessible or not. I'm investigating this issue with my hosting provider. Because of this issue and to ease the release process, this and next releases will be published here, in this blog in addition to the website.

MinGW Distro - December 2012 Release

Updates: binutils 2.23.1, Boost 1.52.0, PNG 1.5.13, TIFF 4.0.3, cURL 7.28.1, GraphicsMagick 1.3.17, POCO 1.4.5, SQLite 3.7.14.1.
New: pugixml 1.2

MinGW-Distro.exe - 43 Mb - Full
SHA1: 92d09d316c17da21c1607ba0938f260b67c8b8b8

MinGW-Distro-Core.exe - 16 Mb - Core Components
SHA1: b3ad4e5e587c915b25acbabd1fdfa0edda69d93f