Thursday, January 19, 2012

Why not C++ all the time?

In the why-we-don't-prefer-programming-in-c++ exhibit of evidence:

python: 
  result = line.split(',')

C#:
  var result = line.Split(',');

C++:
  vector<string> result;
  ostringstream sourcestream(sourceString);
  copy(
     istream_iterator<string>(sourcestream), 
     istream_itearator<string>(), 
     back_inserter<vector<string> >(result) 
  );


Special thanks to StackOverflow  Zunino at Stack Overflow for this answer, one of the most concise and standards-respecting.