Slashdot Mirror


Ask Slashdot: Is C++ the Right Tool For This Project?

ranton writes: I am about to start a personal project which I believe should be done in C/C++. The main reasons I have for this are the needs to manage memory usage and disk access at a very granular level and a desire to be cross-platform. Performance is also important but I am unlikely to spend enough time optimizing to be much faster than core libraries of higher level languages.

On the other hand, network access is also a critical part of the project and I am worried about the effort it takes to make cross platform code for both network and disk access. I have been working in the Java / C# world for the past decade and things like TCP/IP and SSL have just been done for me by core libraries. Do libraries like Boost or Asio do a good job of abstracting these aspects away? Or are there other options for doing granular memory and disk management with more high level languages that have better cross-platform library support? I am willing to brush up on my C/C++ skills if necessary but want to spend as much time as possible developing the unique and potentially innovative parts of my project. Thanks for any advice you can provide.

9 of 296 comments (clear)

  1. If you do go with C++ by TsuruchiBrian · · Score: 5, Informative

    I would recommend using Qt for a cross platform framework. I haven't tried every C++ framework, but of the ones I have tried, Qt is by far the best.

    1. Re:If you do go with C++ by Noughmad · · Score: 5, Informative

      Agreed. Not only it makes programming easier, the code also tends to be more similar to Java and C#, which he has used before.

      --
      PlusFive Slashdot reader for Android. Can post comments.
    2. Re:If you do go with C++ by gladish · · Score: 5, Interesting
      I think that really depends on your definition of "best". I've used Qt (and still use it sometimes) and initially I thought I liked it, but over time began disliking it a lot. For one, I've seen the signal/slot mechanism used to create really hard to understand code. I've seen memory allocated via new and then the pointer passed into emit only to be deleted on the other end of a signal/slot chain.

      Posted says, "needs to manage memory usage and disk access at a very granular level and a desire to be cross-platform". Stdio/stdlib takes care of that. I don't see any mention of GUI, so if GUI is necessary, then I'd say, ya, just use Qt, because it probably is the best and it does come with a lot of other stuff, so you when in Rome...

      Boost. What you'll get from boost is the filesystem stuff. It'll be similar in functionality as System.IO.FileInfo System.IO.Directory in .NET, but way more confusing to use. At least at first.

      It's funny, the filesystem api was proposed over 9 years ago for c++.

      http://www.open-std.org/jtc1/s...

  2. C or C++ by Anonymous Coward · · Score: 5, Informative

    Decide whether your project is to be done in C or C++. Choose one and embrace it.

    There's an illusion that because these two languages share a common origin that they're somehow the same, bundled together as "C/C++". Especially since C code can often be valid in a C++ compiler.

    In reality, the good programming styles in each of these two languages differ substantially. Start wedging bits of C code inside a C++ program and you'll soon find yourself fighting the language and core libraries. Likewise, the conventions for core concepts like objects and linked lists in C are somewhat different to C++ and with their own strengths. Both are powerful languages for large projects, but not the same language.

  3. If you cannot answer your own question.. by thesupraman · · Score: 5, Interesting

    Then C++ is almost certainly not the language for you, unless it is a pure learning experience.

    Really.. C++ is a relatively high commitment language, and performance is one of its mainstays, however you dont feel you will spend much time optimising it?
    If you cannot look quite quickly over the descriptions of Boost/ASIO and see what they do (and dont) bring to the table, then you will be fighting a very
    uphill battle.

    The reference to TCP/IP being 'done for you' is worrying.. do you think people program raw TCP in C++?

    If you value your project at all then I would suggest C++ is not sounding like your solution.. especially if you need cross
    platform. Your reasons seem almost to be reasons NOT to use an unfamiliar language.

    As almost everything else has equal or better cross platform support, it seems to me like you need to look more closely to what you mean/need by
    'granularity' and perhaps change your mentality using familiar languages, and the solutions for problems in those areas.

  4. What else do you need? by rippeltippel · · Score: 5, Informative

    You said nothing useful about your project

    C++ could be a good choice for all the things you've mentioned. Networking is not an issue, as there are many open source libraries (e.g. libcurl - http://curl.haxx.se/), and using Boost is often a good thing anyway. Also, there are at least two good memory allocators: tmalloc (http://goog-perftools.sourceforge.net/doc/tcmalloc.html) and jemalloc (http://www.canonware.com/jemalloc/) so you may not need to write your own. (I assume that the above open source licenses are good for you, but they are just examples...)

    However... I doubt that your project will be only Network + Memory + Disk. What else do you need? Some UI? Should it interact with the Web? Or with services in the Cloud? There's no easy answer to your question without knowing what else you need, and I wouldn't even exclude a hybrid-language approach (e.g. C++ / Python / JavaScript*).

    * Before someone starts ranting about JavaScript having to run in a browser: NO - JavaScript runs perfectly fine withouth a browser, and can easily interact with C++. Have a look at V8 or SpiderMonkey, just to name some JavaScript engines.

  5. Re:C++ is never the right tool by rippeltippel · · Score: 5, Funny

    Can you hear it, my son? This is the voice of ignorance.

  6. Re: C++ is never the right tool by loonycyborg · · Score: 5, Insightful

    I think that using smart pointers and RAII pattern is in all respects better than garbage collection.

  7. Re:There is no perfect lang by DrVxD · · Score: 5, Insightful

    C++ is often unreadable

    That's not a problem with the language, it's a problem with whoever wrote the code.
    I've been writing software for about 40 years - and one of the things I've observed in that time is that it's possible to write unreadable code in pretty much any language. I've also observed that it's possible to write readable code in pretty much any language.

    --
    Not everything that can be measured matters; Not everything that matters can be measured.