From: Niklas Frykholm Date: 2003-11-17T18:37:22+09:00 Subject: Re: Reason #642 to use Ruby instead of C++ -Carpal Tunnel Syndrome > Of course the file parsing part in Ruby was just: > > adj_hash = {} > tmp_hash = {} > IO.foreach(filename) {|line| > node,*adj_nodes = line.split(',').map{|n| > unless tmp_hash.has_key? n.strip > tmp_hash[n.strip] = Graph::Graph::Node.new(n.strip) > else > tmp_hash[n.strip] > end > } > > That's just 10 lines. I won't post the C++ abomination for accomplishing > the same thing here, let's just say that it's 45 lines long. I love Ruby's structure and convenience functions so much, I often try to mirror them in C++. For example: void split( std::vector* results, const std::string& s, const std::string &split_by) { std::string::size_type start = 0; while(1) { std::string::size_type found = s.find(split_by, start); if (found != start) results->push_back( s.substr(start, found - start) ); if (found == std::string::npos) break; start = found + split_by.size(); } } It's a bit extra work to write such general functions, but think how much easier it will be the next time you want to move some code from Ruby to C++. // Niklas