P
Phil Tomson
Seems like things are a bit slow on the list these days, so here's a
little rant...
I'm taking a class on layout algorithms (layout of wires on a chip). Most
of these tend to be graph algorithms. One of the assignments is to
implement the Kernighan-Lin partitioning algorithm; and it must be
implemented in C/C++. Now there's really no good reason why it has to be
in C++ other than maybe that's all the instructor knows how to read. So of
course I prototyped it in Ruby first - took about 2 hours to
implement in Ruby including debugging the algorithm and testing. Now I
kind of thought, "Hey, I finished this thing three weeks early in
Ruby why not ask the prof if he'd be willing to accept it in Ruby since
it's so early?". Of course he said it _wasn't_ alright and I'd be ding'ed
one letter grade if it's not in C or C++.
So I dug out my Stroustoup and another book on STL. Took me about three
hours just to get the file parsing part of it working (a simple CSV
format). And I've been working on the algorithm part for the last day and
a half; it's almost done, but it probably needs at least 2 or 3 more hours
of work.
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.
Of course the algorithm has to do a lot of iteration over containers
(sets), stuff like (in Ruby):
b.each {|n|
if adj_hsh[node].include? n
external_cost += 1
end
}
Five lines in Ruby. In C++:
for(LI n=b.begin();n!=b.end();++n)
{
if(_adj_map[node].find(*n) != _adj_map[node].end())
{
external_cost++;
}
}
Seven lines in C++ (8 if you include the typedef for the set iterator,
LI). OK, that's not that many more lines, but there
certainly are a lot more characters to type and it's nowhere near as
comprehensible.
Oh, my aching wrists!
....rant over.
Phil
little rant...
I'm taking a class on layout algorithms (layout of wires on a chip). Most
of these tend to be graph algorithms. One of the assignments is to
implement the Kernighan-Lin partitioning algorithm; and it must be
implemented in C/C++. Now there's really no good reason why it has to be
in C++ other than maybe that's all the instructor knows how to read. So of
course I prototyped it in Ruby first - took about 2 hours to
implement in Ruby including debugging the algorithm and testing. Now I
kind of thought, "Hey, I finished this thing three weeks early in
Ruby why not ask the prof if he'd be willing to accept it in Ruby since
it's so early?". Of course he said it _wasn't_ alright and I'd be ding'ed
one letter grade if it's not in C or C++.
So I dug out my Stroustoup and another book on STL. Took me about three
hours just to get the file parsing part of it working (a simple CSV
format). And I've been working on the algorithm part for the last day and
a half; it's almost done, but it probably needs at least 2 or 3 more hours
of work.
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.
Of course the algorithm has to do a lot of iteration over containers
(sets), stuff like (in Ruby):
b.each {|n|
if adj_hsh[node].include? n
external_cost += 1
end
}
Five lines in Ruby. In C++:
for(LI n=b.begin();n!=b.end();++n)
{
if(_adj_map[node].find(*n) != _adj_map[node].end())
{
external_cost++;
}
}
Seven lines in C++ (8 if you include the typedef for the set iterator,
LI). OK, that's not that many more lines, but there
certainly are a lot more characters to type and it's nowhere near as
comprehensible.
Oh, my aching wrists!
....rant over.
Phil