7 ms·
To be fair, after coming back to C++ after years in the world of Python and Haskell, it's not as bad as I remembered. C++ is actually a moderately effective fu
by yummyfajitas 17y ago
To be fair, after coming back to C++ after years in the world of Python and Haskell, it's not as bad as I remembered.
C++ is actually a moderately effective functional programming language. With reasonable knowledge of the standard data structures, and using BOOST, one can actually write fairly expressive and effective C++ code.
Most of the time, I feel like all I'm doing is writing a much more verbose version of Python. The rest of the time, I'm hunting nightmarish segfaults and segfault and template errors.
- joe_the_user 17y agoOddly enough I'm back to C++ too, after Ruby. One nice thing is; in a fast language, tests run quickly too. Also, Python and Ruby don't have the equivalent of an ASSERT (you could roll your own but it's not standard practice). Also, C++ has standard hash lists and complicated data structure are actually going to run quickly. And while memory management can be a pain, you are doing it yourself so you can track down memory leaks rather than having them be inherent in the interpreter... ...as in Ruby AND Mono.
- hazzen 17y agoC++ doesn't actually have a standard "hash list" (I assume you meant hash map or hash set?). Depending on your implementation, you either have hash_{map,set}, unordered_{map,set}, both, or something entirely different. tr1 specified unordered_{map,set}, but tr1 is only technically a proposal, not a standard. I think a safe assumption is that tr1::unordered_{map,set} will be available in all implementations by now, but until C++0x is ratified and implemented by major compilers, you will run into different platforms having (possibly) different implementations. And lets be honest - even after C++0x has been implemented in major compilers, you will still have subtly different/buggy implementations. edit: I had conflated {hash,unordered}_{set,map}. Fixed
- queensnake 17y agoNah, the committee isn't going to change unordered_set or unordered_map; they're struggling with far more urgent things, to finish the std off. Those have already gotten the full treatment, they have the usual std:: collection interface; what's to change?
- grogers 17y agoOr you can use boost::unordered_set right now, in any compiler, whether it supports tr1 or not.
- ubernostrum 17y agoAlso, Python and Ruby don't have the equivalent of an ASSERT (you could roll your own but it's not standard practice). Ahem: http://docs.python.org/reference/simple_stmts.html#the-assert-statement http://docs.python.org/reference/simple_stmts.html#the-asser...
- deleted 17y ago[deleted]
- icefox 17y agoRubyOnRails is very test gunghu, but to run a hello world test takes seconds, anyone know why? This seems very odd. Is this one of those do what I preach, not what I do things?
- techiferous 17y agoI doubt it takes seconds to test a hello world program in Ruby. However, to test a hello world Rails application is a different story, as you have to start up the web server, which takes seconds (even though it eventually just serves a simple page).
- maurycy 17y agoNot necessarily the web server. Standard `rake test:units` (or even `ruby test/units/model_test.rb`) takes the whole Rails stack so it adds up.
- techiferous 17y agoYou're right and I agree. But let's be careful not to equate Rails with Ruby. Rails tests may have a slow startup time, but Ruby tests do not and other Ruby web framework tests may not.
- fauigerzigerk 17y agoBecause if "performance doesn't matter" is repeated often enough people actually start to believe it, and if enough people believe it, it becomes false. Is there a name for this logic? :-)
- Luyt 17y agoConfirmational Bias followed by a Self-fulfilling Prophecy. But you knew that and I think your question was purely rhetorical ;-)
- SamAtt 17y agoThe question isn't "Can C++ work?" or "Will C++ be faster?" because we all know it can work and that it will be faster. The question is "At what point does the extra development time become more expensive than just adding another server to my Ruby/Python/C#/Whatever App" For me, someone who learned C++ in school but has been in managed enviornments ever since, I'd be too scared to use C++. I'm not ashamed to admit I get a lot of help from the Internet when I'm stuck on a problem and that help is available because everyone else is using the same tools I am. Using C++ to code web apps puts you out in the wilderness as far as I'm concerned and I just don't think I could do it.
- techiferous 17y ago"because we all know it can work and that it will be faster" Speed of execution depends more on the programmer's expertise than the language used.
- jrockway 17y agoNot really true. I can write the same algorithm in Perl as in Haskell, and the Haskell always runs faster.
- dualogy 17y agoSo maybe he meant "on the expertise of the programmer" -- of the language/compiler...
- fhars 17y agoBut then your expertise is not that different from your expertise. Your perl will probably still be faster overall than a beginner's haskell, not for the same algorithm, but for solutions to the same problem. Knowing which algorithms perform well for a given problem solved in perl is the most relevant part of expertise.
- anonjon 17y agoChances are that the majority of developers won't find the most efficient algorithm to solve the problem. (vs. the most efficient implementation of that algorithm... which is clearly going to be in a combination of C and assembly anyway). Anyway, the guy using the good algorithm ends up with the fastest code. Different compilers will produce different quality of code. Question is, if I am using C++ vs. a guy using Perl, will I ever reach the efficient algorithm? I might call it quits when I finally get something to compile and not segfault. (Of course even this is kind of a strawman, because the perl guy can just reimplement in C++ when he figures out that he wants more speed out of his good algorithm).
- abrahamsen 17y agoYour experience with Python and Haskell has most likely made you a far better C++ programmer than you were before.
- yummyfajitas 17y agoThis is absolutely the case. I'm now used to first class functions, currying, etc. C++ actually has them, hidden in the stl and boost::function. Whatever I can't do using those, I can usually do by creating a family of classes which only implement operator() (I've only needed to do this once or twice, and it might have been avoidable). Due to using a language with native dicts (and syntactic sugar), they are now part of my vocabulary. This means I immediately reach for std::map or boost::unordered_map when it makes sense. Similarly, python generators and haskell lazy lists have made view sequences as reasonable objects to generate and iterate over. Custom iterators are just the same thing with added verbosity. If I never used higher level languages, I'd still be treating C++ as C with objects.
- scott_s 17y agoIn C++, I'm more likely to write a struct/class which implements operator() than an actual function. It lets me write code like this, which does mutate state, but I put it off as long as possible: xformerlist& lbrace = node.children.front().xformations; xformerlist& rbrace = node.children.back().xformations; fn_and<shared_variable> row_and_flat(&shared_variable::is_row, &shared_variable::is_flat); const sharedset& flat_ins = filter(row_and_flat, set_union_all(in, inout)); const sharedset& flat_outs = filter(row_and_flat, set_union_all(out, inout)); const sharedset& flat_all = set_union_all(flat_ins, flat_outs); make_conditions<gen_in<row_access> > make_gen_in_row(parcond, conds, local_depths); make_conditions<gen_out<row_access> > make_gen_out_row(parcond, conds, local_depths); append(lbrace, fmap(make_gen_in_row, flat_ins)); append(rbrace, fmap(make_gen_out_row, flat_outs)); I imagine that code would give a lot of people fits. In my current project, I ran with a more functional approach to C++. I don't know if I'll keep everything I've used in this programming style, but I certainly will keep some of it.
- capablanca 17y agoSo, what is great, modern C++ code to read?
- jbarham 17y agoIt's a book but Accelerated C++ by Koenig and Moo has been well reviewed.