4 ms·
> PS: What do you think of C++ as a language? I hate C++, although I'm using it right now since python lacks libraries I need (http://www.cgal.org/ http://www.
by yummyfajitas 19y ago
> PS: What do you think of C++ as a language?
I hate C++, although I'm using it right now since python lacks libraries I need (http://www.cgal.org/ http://www.cgal.org/).
But I hate C++/STL/Boost far less than I hate C++. The STL and Boost make C++ feel almost like statically typed python, (while occasionally driving you mad with pages full of template errors).
An example (g is a graph):
list<Edge> to_remove;
BOOST_FOREACH( Vertex v, vertices(g)){
if (degree(v,g) > 2){ //Try to remove some ambiguity
BOOST_FOREACH(Edge e, out_edges(v,g)) {
...Do some euclidean geometry...
if (...Geometric constraint not satisfied...){
to_remove.push_back(e);
}
}
}
}
BOOST_FOREACH(Edge e, to_remove){
remove_edge(e,g);
}
This is almost a direct translation of what I'd write in python (if python had graphs as a data structure), except of course that to_remove is a list of edges.
Some people insist on programming C++ like it is c. I.e., they will build an array (hoping it's big enough, sometimes they will even error check if it's not), cast the edges to int's, keep track of how many array members represent edges and how many do not. If you do that, your life will suck.
- kashif 19y agoThanks.
- st3fan 19y ago"""This is almost a direct translation of what I'd write in python""" Except that the C++ version can be highly concurrent and 100 times faster :-) I'm exaggerating a bit here of course, but in many cases C++ can certainly be a better choice. Even though it is MUCH more verbose. S.
- tptacek 19y agoYou are going to have a hard time making a case for a situation where C++ is better than C + Python.
- palish 19y agoIt would be difficult to implement Megatexture in Python without writing most of it in C/C++ and a shader language like GLSL/HLSL. Also, having a Python interface to Megatexture wouldn't buy you any flexibility because Megatexture's job is well-defined. It's mostly an optimization problem. http://en.wikipedia.org/wiki/MegaTexture http://en.wikipedia.org/wiki/MegaTexture
- yummyfajitas 19y agoOne situation I ran into recently: computational geometry. It's not usually just an inner loop that needs to be carefully optimized, often there various levels of calculation that need to be done. I'd actually much prefer to use Ocaml for that use case, but libraries made the choice of C++ for me. (C++ is also good to have on the resume.)
- lpgauth 19y agoLearn STL and Boost if you want to enjoy your experience a little. I first learned C++ like an extension of C and it was hell.