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.

182 of 296 comments (clear)

  1. python with psutil by sandGorgons · · Score: 3, Interesting

    consider using python with py2exe, psutil and mmap. you may find what you are looking for !

    1. Re:python with psutil by The_Dougster · · Score: 4, Insightful

      Python can sure get you up and running like yesterday with a quick and dirty prototype. Bang it out in python and then port it to C++ at your leisure, if you even need to.

      Having a working solution *right now* is pretty nice, even if your ultimate goal is a C++ binary.

      --
      Clickety Click ...
    2. Re:python with psutil by dgym · · Score: 3, Insightful

      Having a working Python implementation will also give you a better understanding of which parts are performance/memory sensitive. This may help guide you while rewriting in a different language, or you may find that you can achieve your goals just by hot spot optimizing your Python code using some of these fine tools:

      http://www.numpy.org/ can give you compact arrays of unboxed types and fast operations over them.
      http://cython.org/ is an amazing and versatile tool which allows you to compile your Python code, optionally add type information, optionally manage memory yourself, optionally interact with C/C++ code very easily.
      OpenCL/CUDA if your work can take advantage of them.


      If the standard Python runtime isn't simply too big for your project I can't recommend Cython highly enough. Only tackling the parts that need it is one of the keys to successful optimization and Cython lets you do just that even if it is just one loop in an otherwise pure Python file.

  2. 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 GNious · · Score: 2

      Qt5 would abstract the bits that are platform specific, while still allowing low-level control where desired.
      Unless there is some specific reason not to use Qt, it would seem to match his requirements nicely.

    3. 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...

    4. Re:If you do go with C++ by BytePusher · · Score: 2

      Also agree. I personally find the only thing more elegant/friendly about python is modules vs headers and a generally robust toolbox of libraries. Qt get's you the majority of that and you get all the control you need without awkward language bindings. As another poster points out, RAII with smart pointers is pretty much superior to garbage collection in every way.

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

      If you're not writing GUIs there's no need to use Qt's signal slot system. Also, since C++11 you're able to use member function pointers instead of their mocking framework(thus you get compiler errors vs printouts at run-time.) And, yes, W(here)TF is the C++ filesystem std library?!?!

    6. Re:If you do go with C++ by ranton · · Score: 1

      There is no UI required for the project, although I realize you can use modules like QtNetwork without the UI libraries. I am a bit worried about tying myself too closely to the QT event loop. Can anyone provide any insight on if the event loop will complicate concurrency throughout the rest of the application or if it is even necessary? I have briefly read through some documentation but I am most looking for advice from someone who has used it before and has dealt with the gotchas that every framework has.

      I have leaned more towards trying Boost over QT mostly because it relates closer to the standard library and has less overhead and framework buy in necessary. Or at least that is my impression. Has anyone tried both and have any advice on which they prefer for a project where you don't want to completely drink the framework's Kool-Aid?

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    7. Re:If you do go with C++ by Anonymous Coward · · Score: 1

      Meh. RAII is always better in the case of non cyclic object ownership. shared_ptr works predictable and consistently. It's when you have cyclic ownership (weak_ptr) stuff that it starts to be too annoying to bother with. Java and C# (I assume python too. Though given the clusterfuck that is python 3, I can no longer say "because I assume a base level of competence") are both able to detect loops of dead objects and collect them. With C++, you have to manually break the cycle by using weak_ptrs, and not everyone really understands their object hierarchy.

    8. Re:If you do go with C++ by turbidostato · · Score: 4, Informative

      You know there's no need for a software project to be coded in any single programing language, don't you?

      You can properly modularize and then mix and match your project as different modules -or even programs, in different languages, i.e.: C for low level hardware access (and abstraction: first you say you want it multiplatform but then your message implies a monolithic approach !?), maybe C++ for the main logic, python to glue everything together, a toolkit like Qt for a GUI -maybe you don't need it now but it results in a good addition down the road, etc.

    9. Re:If you do go with C++ by narcc · · Score: 4, Insightful

      it would seem to match his requirements nicely.

      We don't even know what his requirements are!

    10. Re:If you do go with C++ by TsuruchiBrian · · Score: 2

      If done correctly signals and slots make very maintainable code. They allow you to decouple classes (remove dependencies from classes upon eachother), as opposed to mechanisms like callbacks/handlers. This leads to more modular 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.

      That's a c/c++ problem, not a Qt problem. You can't stop people from writing bad code, but you can make it harder.

      As far as memory management goes, Qt provides both QSharedPointers, which will perform reference counting and delete themselves upon the reference count reacing zero. They also provide a way to use their COW (copy on write) mechanism, so that you can treat references as values and the data is only copied when it is modified from the original (lazy copying).

      Memory management in C/C++ is error prone. Using reference counting pointers and COW makes it easy to do correctly.

      Qt also abstracts out the filesystem api as well.

    11. Re:If you do go with C++ by TsuruchiBrian · · Score: 1

      You are not forced to use the Qt event loop. You can use all blocking I/O and lots of threads if you really want. I personally find the event loop approach to result in more elegant code, and this concept is not unique to Qt. The logical mechanism of the event code is transferable to other frameworks, even if the actual code is not.

      There is no way to use a framework without writing code that is specific to that framework. My advice is to just pick one and drink the kool-aid. One way to get crappy code is to use a framework incorrectly.

    12. Re:If you do go with C++ by TemporalBeing · · Score: 1

      If you're not writing GUIs there's no need to use Qt's signal slot system.

      I would disagree. Even in a daemonized application the Qt (WxWidgets, Gtk, and Boost) signal/slot system works wonders.

      Like with anything else, it can be abused, but it is by far superior to alternatives like the Message Maps (Gtk, MSVC, WxWidgets).

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    13. Re:If you do go with C++ by TemporalBeing · · Score: 1

      There is no UI required for the project, although I realize you can use modules like QtNetwork without the UI libraries. I am a bit worried about tying myself too closely to the QT event loop. Can anyone provide any insight on if the event loop will complicate concurrency throughout the rest of the application or if it is even necessary?

      The QT Event Loop actually makes concurrency far easier. You can start each thread with its own event loop, and just pass objects back and forth between the threads using Signals/Slots. The Qt Signal/Slot automanages moving the objects between the event loops, and it all just works.

      So you can easily have one thread that just reads data from disk, while 5 other threads receive the data to process, all using Qt signal/slots and not give a lick about which thread it's running in.

      Furthermore, if you need to reduce it to one thread to debug, you can easily do so by changing which thread stuff lives in. So concurrency issues become easy to diagnose.

      Of course, there are also several Concurrency frameworks within Qt as well - QtConcurrent, QtFutures, etc. - so if you have massive parallism capabilities you can just use those instead. They're all very easy to use.

      Also, Qt integrates well with Boost. You can even use the Boost Signal/Slots (choose your version) if you like.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    14. Re:If you do go with C++ by Grishnakh · · Score: 1

      Oh my god. No offense, but I think that is a terrible idea. The Qt codebase is HUGE. You're literally advocating adding a gigabyte of code to a project just to get some networking code. Think about it. If someone wants to use his project, step 1 is to get Qt for that platform. That's fine for Ubuntu Desktop Linux or something totally mainstream, but it's a big deal if he wants to go embedded or to a RTOS.

      Wrong.

      The Qt code is modular; you only include the libraries you actually use.

      And Qt is very popular on embedded platforms (ones running Linux and having a display).

    15. Re:If you do go with C++ by pogopop77 · · Score: 1

      Another "me too" vote for Qt. It's a well-designed, cross-platform, highly-stable framework that is appropriate for a wide-variety of development tasks.

    16. Re:If you do go with C++ by TsuruchiBrian · · Score: 1

      Why does it matter if the QT codebase is huge? Qt is a general purpose framework. Of course it is going to be huge and have a bunch of stuff you don't need. Luckily you don't need the parts you don't need.

      The OP specifically wanted cross platform networking code, and your suggestion is to for him write platform specific network code for all the platforms he intends to use, effectively writing the functionality that a framework like Qt provides.

      He's asking for advice on the best hammer to buy, and you are suggesting that he should make his own hammer.

      Coincidentally I am currently working on porting an existing codebase that uses the Qt framework to not use *any* framework. This means I am writing all my own platform specific network code as you are describing (along with every other feature that used to depend on Qt). Nothing makes you appreciate something more than losing it.

      Having to redo all (actually only a fraction) of the work that Qt did really makes you appreciate the convenience that it provides. Our codebase is now much larger (i.e. the codebase we are responsible for maintaining).

    17. Re:If you do go with C++ by TsuruchiBrian · · Score: 1

      Those are gui toolkits, not cross platform frameworks.

    18. Re:If you do go with C++ by Giant+Electronic+Bra · · Score: 1

      Yup, agreed. Qt will provide you good libs for a LOT of things, not just UI stuff, though all of it is certainly written with client applications in mind.

      --
      "Malo periculosam, libertatem quam quietam servitutem." -- Jefferson
    19. Re:If you do go with C++ by turbidostato · · Score: 1

      "There's no need for a simple system level daemon to have a billion dependencies"

      Yes, you are right: there's no need to throw a billion dependencies in half a dozen programming languages for a simple system level daemon.

      No, you are wrong: nobody said this is for a "simple system level daemon" and, in fact, there're heavy hints on the contrary: it is an innovative and unique; needs to manage memory usage and disk access, both at a very granular level; it has be cross-platform and performant; it needs cyphered internet access.

    20. Re:If you do go with C++ by blackcoot · · Score: 1

      I have a very strong preference for boost where Qt and boost overlap for two reasons: first, Boost is a proving ground for future C++ standards; second, I avoid UI work like the plague.

    21. Re:If you do go with C++ by david_thornley · · Score: 1

      Memory management in C is error-prone. Memory management in C++ is far easier to do, with things like smart pointers.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    22. Re:If you do go with C++ by TsuruchiBrian · · Score: 1

      That's basically what I was getting at. The Qt pointers are flavors of c++ smart pointers. Smart pointers are possible with c++ but they are not language constructs or supported directly.

      The problem the OP referred to of "sending a pointer in a signal and having it deleted out from under you", is a c/c++ problem (rather than a Qt problem) in the sense that it is possible/probable for bad programmers to do these things in c/c++ because the language allows it, as opposed to GC languages (e.g. java), which don;t suffer from this particular problem.

      Memory management need not be a problem in C++. You are just required to know about smart pointers, and actually enforce their usage (if on a team).

    23. Re: If you do go with C++ by Craig+Ringer · · Score: 1

      Um... std::smart_ptr ?

      Present since c++0x TR1. It should not have taken that long and Microsoft's painfully slow adoption of TR1 hasn't helped. It's there though.

    24. Re: If you do go with C++ by TsuruchiBrian · · Score: 1

      That's a class not a language construct even if it's in the standard library. AFAIK You could make smart pointer classes for C++ since it's inception.

      In lots of other languages (e.g. java) you are prevented from making "dumb" pointers.

      My point is that using smart pointers is a choice you must make in C++, rather than a choice that is made for you.

      The fact that someone can make the wrong choice is not a problem with Qt (even if they are using Qt), the fact they were able to use dumb pointers is a feature of C++. No C++ framework is going to be able to change that.

    25. Re:If you do go with C++ by davester666 · · Score: 1

      Of course, the UI looks and works like shit, unless you effectively code the UI yourself for each target platform, except on Windows, where it looks and behaves like regular Windows apps. It still looks and works as initially described, it just fits in with all the other apps.

      --
      Sleep your way to a whiter smile...date a dentist!
  3. Not enough information. by Anonymous Coward · · Score: 2, Informative

    You haven't provided nearly enough information to make a decision here. You haven't defined what you mean by "granular level", whether you need a UI, what functionality you have to provide.

    1. Re:Not enough information. by ranton · · Score: 1

      You haven't provided nearly enough information to make a decision here. You haven't defined what you mean by "granular level", whether you need a UI, what functionality you have to provide.

      The project is very similar to writing an database management system. I didn't want to get too much into the details so people aren't commenting about the virtues of the project itself.

      By granular level I mean I cannot be in a managed environment like the JVM or .Net JIT compiler. I need to be able to allocate and release memory manually. I have done some prototyping in Java and C# hoping I could control garbage collection enough for my needs, but it isn't possible (or at least I can't figure it out).

      There is no UI and it will only communicate via networking. It will also be distributed and concurrency control will be important.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    2. Re:Not enough information. by SQLGuru · · Score: 1

      Why don't you mix languages? Write the pieces that are easier in the "higher" level languages in those (Java or C# since those are what you know) and write the pieces that need C/C++ in one of those languages? C# can call out to unmanaged code fairly easily but makes all of the simple tasks easy......I only do minimal amounts of Java, but I'm sure it can too. Back in the day, I used to write some C and every once in a while break out some ASM for those routines that needed to be closer to the hardware.....why should this be any different?

      We have all of these tools available to us and yet we always try to use a single tool as the end-all-be-all. [car-analogy]Sure, you can race the LeMans in a Volkswagon Beetle, but shouldn't you use a car better suited for it?[/car-analogy]

    3. Re:Not enough information. by david_thornley · · Score: 1

      The OP wanted cross-platform code, and C# is a bit shaky on that, although improving. Also, if OP needs manual memory management, C# or Java would have to use memory allocated in C or C++. Not only does that sound tricky to me, but garbage collection is a strong reason to use C# or Java, and so I don't think this is a good idea in this case.

      Modern C++ is not much harder to learn or use than C# or Java (although learning the whole language enough to understand most legacy code is considerably harder in C++), and I don't see much reason to use C# or Java here.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    4. Re:Not enough information. by ameoba · · Score: 1

      It's a very important project. If he told you the details, you'd need to sign an NDA so you don't steal his revolutionary ideas.

      --
      my sig's at the bottom of the page.
  4. 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.

    1. Re:C or C++ by dave87656 · · Score: 1

      Re: There's an illusion that because these two languages share a common origin that they're somehow the same

      I think most experienced C++ programmers know that the C-core of C++ is very similar to "C" but not exactly the same. But it's a good point. There are differences and they are not exactly the same and it can really burn you even if your program compiles.

  5. 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.

    1. Re:If you cannot answer your own question.. by SpaghettiPattern · · Score: 2
      Furthermore you should ask yourself why you would need such a low level access when low lever performance clearly isn't the main issue. Consider using available main stream OSS APIs and libraries to allow higher abstraction level. You could then contribute to improve the used library.

      Reuse components that others developed. It will most likely render you more effective and efficient. You would also pay the component developers back at least through lips service. The components will improve. Everyone will be a winner.

      --

      I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
    2. Re:If you cannot answer your own question.. by mwvdlee · · Score: 4, Insightful

      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.

      This.

      "Very high" is subjective. I've had programming tasks where every single byte of memory counted and was optimized for. But I've also had tasks where this meant I'd just have to keep memory usage down to a few MB; totally different interpretations of "very high granularity".

      Since you'll probably need to have a trade-off between memory and performance, which is more important? Can you spare a few KB to make your code run 2x faster? How about a few MB? Does code need to run as fast as possible or just fast enough to keep pace with the GUI?

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    3. Re:If you cannot answer your own question.. by rwa2 · · Score: 2

      Word.

      I've been pretty happy using python for prototyping, and it's actually fairly fast using a JIT wrapper like pypy. And the C++ bindings are there for when you have to rewrite one of your modules for performance. There's even an interface to Boost and maybe even ASIO if you want to tinker with those for some reason... I played with some Boost libs briefly years ago but found they added too much complexity and got by fine using much cleaner "pure" python modules instead.

    4. Re:If you cannot answer your own question.. by Goragoth · · Score: 1

      To be fair it is still somewhat simpler to get networking going in C# than in C++ with something like Boost. I ported a simple TCP/IP server from C++ to C# not long ago and it certainly was easier to get working in C#. It's not a massive challenge but for someone not terribly familiar with C++ it might take a while to figure things out.

      Personally, by the sounds of this project, I would probably code it in C# (or Java if that's your thing) and then bind in anything that those languages can't do using the native interface and a small C library (probably easiest to stick with straight C when doing native interop, though you can go C++ if you feel you really need it). For small projects I feel like going full native is rarely going to be worth it.

    5. Re:If you cannot answer your own question.. by Kagetsuki · · Score: 4, Interesting

      I program raw TCP in C++.

      I think maybe you meant to say "do you realize people program raw TCP in C++?" or something like that.

      Also, I agree with you that the person asking the question here should probably look for something else. It sounds like they are in over their head and I don't see them optimizing multi-threaded networking applications with real time IO in valgrind any time soon (though it sounds like an interesting Friday afternoon for me).

    6. Re:If you cannot answer your own question.. by ranton · · Score: 1

      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?

      I started my career working with C++ so I am not new to the language, but my work used very little of even the standard library let alone other third party tools. I used in house libraries that were already written. I was also a novice at the time, so a good deal of the last few months has been spent reading material like Effective Modern C++ and others in the Effective C++ series, along with a throwaway project to practice while reading.

      I am a firm believer that most performance is in the algorithms not the language, so I am definitely not choosing C++ primarily for performance reasons. I need certain aspects like memory management, but my choice is not because I think my algorithms will run faster in C++ vs Java. There will probably be some very important modules I need to optimize, but all of that will likely be long after I have a working prototype.

      I had a project a year ago where tokenizing terms needed to be as fast as possible, so I tried creating a C library to do it. I am confident I did it well by not copying memory but just keeping track of the location and length of each word in the existing character array, but I still couldn't match the performance of just doing it simply in LINQ (although it was almost identical performance). There is likely some kind of CPU caching or other tricks I was not doing right, but my point is I understand moving to C++ is not some silver bullet for performance, which is what I meant when I said I wasn't moving to C++ for performance reasons.

      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.

      I can and have read up on Boost::Asio and a little on QT, which is why I know how they would be useful to me in this project. But I am looking for advice from people who have used them extensively and know the gotchas. In my experience it takes a couple years to really know how certain aspects of a framework will affect your project long term and I want to gleam as much insight from the community as possible before I start down a certain path. It may not be possible to learn anything substantial with one Ask Slashdot post, but I figured why not try.

      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.

      Okay, basically I need to be able to allocate and release memory manually and without waiting for any garbage collection. I need complete control over concurrency and memory sharing, and as little overhead as possible when accessing the hard disk. I have not been able to find a way during prototyping to control memory enough in Java or C#. A language with a great cross platform library but no memory management would be perfect, and right now C++ is the only language I know of that comes close to those requirements.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    7. Re:If you cannot answer your own question.. by ranton · · Score: 1

      Personally, by the sounds of this project, I would probably code it in C# (or Java if that's your thing) and then bind in anything that those languages can't do using the native interface and a small C library (probably easiest to stick with straight C when doing native interop, though you can go C++ if you feel you really need it). For small projects I feel like going full native is rarely going to be worth it.

      The only thing stopping me from doing this now is I need the ability to release memory on demand, and System.GC.Collect() is not sufficient. I really wish it was since I would work in C# if it was sufficient, but all prototyping I have done so far has not been successful enough.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    8. Re:If you cannot answer your own question.. by TemporalBeing · · Score: 1

      Okay, basically I need to be able to allocate and release memory manually and without waiting for any garbage collection. I need complete control over concurrency and memory sharing, and as little overhead as possible when accessing the hard disk. I have not been able to find a way during prototyping to control memory enough in Java or C#. A language with a great cross platform library but no memory management would be perfect, and right now C++ is the only language I know of that comes close to those requirements.

      . Since you mentioned you have existing libraries, etc - QT certainly seems to be very beneficial here. With the QSharedPointer types (weak, strong, etc) and concurrency functionality (QtConcurrent, QtFuture) it seems to have the main tools you're looking for, and it will integrate well with other projects in that bringing in an existing library won't be much of an issue (well, unless it's a MSVC COM or something like that; those would need to be re-written). The main caveat is that it's a little harder to share Qt code in a static way (e.g libmyqtlib.a) from a Qt project to a non-Qt project; at least, I haven't tried that. Most just use a dynamic linker which works fine to do that.

      There's also a very health e-mail list and forums at qt-project.org that you can use to ask questions and get answers reasonably fast. I can't say the same for Boost, where each library may have its own list if anything at all.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    9. Re:If you cannot answer your own question.. by Frobnicator · · Score: 1

      I'm someone who gets contracted to optimize this kind of code. Unfortunately like most good technical problems, the answer is "it depends."

      Pulling in some quotes from your various replies and comments scattered across the discussion:

      My perfect solution would be developing it in C# while having complete control over memory allocation and release ... Linux+Windows ... I need to be able to allocate and release memory manually. I have done some prototyping in Java and C# hoping I could control garbage collection enough for my needs, but it isn't possible

      Since your replies are talking about cross-platform C#, that almost certainly means Mono instead of the MS implementation. That's a good thing for you.

      For your garbage collection concerns, Mono ships with two garbage collection implementations. One is SGen, the other is Boehm. Both can be modified for your needs, if necessary. Java's implementations vary by VM implementation, and that leads to problems for most developers.

      On the nature of GC and Java in particular, it is difficult to write code using existing libraries that is memory and cache friendly, as many libraries (especially in Java) perform small allocations and will duplicate data without thought. In one recent project I was brought it to help fix, the developers (in Java) were, as a general practice unexpectedly allocating and using large amounts of memory that destroyed performance. For example, the libraries and code would allocate and manipulate over 4MB of memory to manipulate a buffer that was guaranteed to always be under 80KB. They took warnings from static tools seriously even when it was unnecessary; Sonar warnings that data was shared is a security concern meant they would make a copy of huge amounts of data, even when the only consumer of the data was their own program on their own servers. It took some work but reducing all the processing of data in their server program so it fit into the L2 cache dropped latency from milliseconds to nanoseconds. It is certainly possible in Java and C# to tune your program to minimize cache misses and more carefully control object lifetimes, but it requires a serious effort. In my experience this is mostly about the developers, C# the developers tend to less frequently make use of an unbounded number of copies of objects. :)

      There is no UI required for the project, although I realize you can use modules like QtNetwork without the UI libraries. ... It is similar to writing an database management system ... There is no UI component

      In this case, writing your UI should be a separate endeavor from writing your main project. Use whatever tools and frameworks you are familiar with to build the UI, quick-and-dirty. Don't worry about the choice QT or other UI tools, focus instead on your communications protocol. Keep the data minimized and tight. If you decide to throw in an intermediate web server like Tomcat to give an HTTP interface, make that into a third, separate application. One application is your real server, one application is your tomcat server that talks to your server and to your clients, and your UI application. If scaling to large numbers is important, the extra layer can introduce some latency, but in exchange lets you take advantage of all of Apache's nice web page features without bloating your real server, which can be leveraged for scaling up to multiple load-balanced web server boxes that communicate with load-balanced core servers. (All depending on your project details that you haven't shared).

      In your project, remember to keep IO asynchronous from processing. Any communication you have through your network IO should be in a separate set of threads, and NOT in one thread per connection (a strangely common mistake). Boost's asio library is pretty good at this in a cross-platform situation, and is implemented with platform-specific libraries that

      --
      //TODO: Think of witty sig statement
    10. Re:If you cannot answer your own question.. by Darinbob · · Score: 1

      The only people programming raw TCP are those writing network stacks. In other words, the OS does this for you almost always or you get a third party library.'

      I'd avoid Boost myself. I found that when I had to use it that it sucked up my time: I didn't use it, just someone on the team used it for simplicity and then it doubled my workload when it didn't work well and I was stuck trying to debug the maze of twisty templates all intertwined. If you need portability, spend a couple of hours writing a portability layer, it's very simple. In some cases it is fine to reinvent the wheel to get a smooth ride instead of putting up with hexagonal wheels that break your back.

      I know I stuck my foot in it this time, as Boost is one of the world's major religions.

      For GUI stuff use Qt.

    11. Re:If you cannot answer your own question.. by Darinbob · · Score: 1

      I program raw TCP, but that's because I have to fix bugs in the IP stack. Most people though can just use their OS to do TCP for them. Very few people actually compose the raw IP/TCP headers themselves or use raw sockets.

    12. Re:If you cannot answer your own question.. by david_thornley · · Score: 1

      C++ is a high commitment language when you need to understand all sorts of legacy code. It's much easier if you learn it right (if your book has more than a passing mention of C-style arrays and strings, or raw pointers, find another) and start a project entirely in modern C++ code.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:If you cannot answer your own question.. by Kagetsuki · · Score: 1

      I'd say you're mostly correct and for the question this guy is posting I'd say you're dead on.

      Personally I've fit into the "very few" category you point out with specialized applications / working with a non-standard protocol server / interfacing with network hardware so much that even if I'm writing a standard HTTP client I write the headers and handle the streams myself. With HTTP 2.0 coming though I think I may stop that practice. Still, anyone writing a networking client should at least play with HTTP at least once - it's a very easy protocol to handle with tons of documentation and a myriad of reference implementations.

  6. 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.

    1. Re:What else do you need? by mishehu · · Score: 2

      In fact, to support your comments about Javascript, in the FreeSWITCH project, we have a VoIP softswitch that can directly interact with Javascript using mod_v8 (used to be spidermonkey), and can also interact with lua, perl, and other languages - scripted, compiled, managed, etc. in a similar fashion.

    2. Re:What else do you need? by ranton · · Score: 2

      The project is very similar to writing an database management system. I didn't want to get too much into the details so people aren't commenting about the virtues of the project itself.

      There is no UI component; it could be thought of as a cloud service.

      My perfect solution would be developing it in C# while having complete control over memory allocation and release. I have done extensive testing using System.GC.Collect() to manually control garbage collection with no luck.

      I started programming with C++ in high school and began my career with the language so I'm not too worried about moving back to the language, but I realize I am far more competent with higher level languages right now.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    3. Re:What else do you need? by rippeltippel · · Score: 1

      You said that it should be cross-platform, which rules out C#, IMHO

      Also consider that, if you go for C++, you'll have to compile it for each platform.

      Maybe you can have a C++ library that deals with memory and do the rest in a language you're more familiar with? e.g. using Boost.Python to interface with... well, Python.

      There are similar solutions for Java and other high-level languages (in general I tend to avoid mixing languages but sometimes it's a necessary evil).

    4. Re:What else do you need? by david_thornley · · Score: 1

      I'd expect manual memory management to be easier in languages that actually support it. If you use C++, for example, the language is set up well to support what you're describing (look for information on "placement new").

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  7. Re:C++ is never the right tool by rippeltippel · · Score: 5, Funny

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

  8. Contradiction ... by Ihlosi · · Score: 1
    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.

    You can pick one of the two and make no promises about the other.

    Or does "cross-platform" in this context mean "Linux+Windows"?

    1. Re:Contradiction ... by ranton · · Score: 1

      Or does "cross-platform" in this context mean "Linux+Windows"?

      Yes.

      Sorry I guess I am a bit too old and still don't think of mobile when I say cross-platform. But not old enough to immediately think embedded when saying cross-platform. I have been living purely in the desktop / server world for over a decade and that is where my project resides as well.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
  9. Perl, bootstrap C++ by holophrastic · · Score: 1, Informative

    you want everything -- memory, disk, network, speed -- and c++ will give you all of that just fine. And it'll give you the giant learning curve, and force you to take every hard road from start to finish.

    Have you considered using perl -- which is pretty well cross-platform -- and writing the few granular components in c++, bootstrapped into perl?

    That's pretty standard for i-want-to-use-perl-but-i-need-this-part-to-be-faster.

    1. Re:Perl, bootstrap C++ by mangobrain · · Score: 2

      Are you trolling? For anyone not already intimately familiar with the process, the vertical learning curve of writing Perl bindings for C++ code will cause more pain, anguish, wailing and gnashing of teeth than writing in either pure Perl or pure C++. You will also gain nothing in portability: in fact you will lose, because portability will be the lowest common denominator of both Perl and C++ (I won't argue over which is lower to start with, both can be high with the right libraries), with the added headache of having to deal with two orthogonal sets of problems, in different languages.

  10. Plain ol' C might a better option by Damouze · · Score: 1, Insightful

    Depending on how hard-core object-oriented you wish your program to be, plain old C might be a much better option, especially if you everything can just be command-line only and will not need a GUI.

    Otherwise, and I'm almost loathe to mention these, C# and Java might be even better ways to go.

    C++ is needlessly complicated.

    --
    And on the Eighth Day, Man created God.
    1. Re:Plain ol' C might a better option by Anonymous Coward · · Score: 2, Insightful

      You can treat C++ as the name implies; plain old C with some extra stuff you may or may not use.
      Nothing in C++ is forcing you to create object oriented code.

    2. Re:Plain ol' C might a better option by Damouze · · Score: 2

      But then you are simply programming in C.

      Nothing wrong with that, but why use a C++ compiler when a plain C compiler would spare you so much overhead?

      --
      And on the Eighth Day, Man created God.
    3. Re:Plain ol' C might a better option by jones_supa · · Score: 1

      You can treat C++ as the name implies; plain old C with some extra stuff you may or may not use.
      Nothing in C++ is forcing you to create object oriented code.

      Objects are the main benefit of C++ over C.

    4. Re:Plain ol' C might a better option by Xrikcus · · Score: 1

      Only in the most basic sense of data encapsulation. Most people are thinking of inheritance, run time polymorphism and a notion of representing concepts with objects when they talk about OO, and C++ requires none of that.

    5. Re:Plain ol' C might a better option by david_thornley · · Score: 1

      Objects are very useful, but I'd say the main benefit is the template system which underlies the STL.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:Plain ol' C might a better option by bstamour · · Score: 1

      Your code need not be object oriented, but you can write totally fine procedural code in C++ while gaining value from the standard containers and algorithms, such as vector, dequeue, et al. Think of it as a version of C without the need for malloc/realloc/etc.

    7. Re:Plain ol' C might a better option by Xrikcus · · Score: 1

      It's more the association of destructors with objects that makes C++ different. Ensuring that a particular function is called when an object is destroyed needs compiler support. RAII is a huge benefit of C++ over C. Although admittedly it is most important in the context of exceptions, which are themselves a C++ feature.

    8. Re:Plain ol' C might a better option by Darinbob · · Score: 1

      Start with C first. Then move to C++ is things are complex enough that you need better organizational tools. Then move to Java if performance and efficiency aren't all that important and you can get away with it. The move to a scripting language to do the stuff that can be really slow or you've got a big whopping PC.

      Doing it the other way around just seems bizarre to me. Sure, algorithms are important, but if you've got array sizes of 1000, then your dumbass O(n^2) bubblesort in C will be amazingly faster than an optimized mergesort of quicksort in a scripting language. But most of the high level languages rely on underlying libraries written in C to do the stuff that needs to be fast anyway.

      C++ is in the middle, depending upon the type of the programmer and style of programming. You can get some C++ programs where the programmer wasn't paying attention and ends up with a result that's slowering the interpreted scripting languages (the mantra is to never prematurely optimize, and instead wait for faster PCs with more memory).

    9. Re:Plain ol' C might a better option by Darinbob · · Score: 1

      Because you can use C++ as a better-C-than-C with no overhead. Better type checking, more consistent rules, use simple classes or namespaces for organization, avoid the bloat stuff like big templates or exceptions or RTTI.

    10. Re:Plain ol' C might a better option by Darinbob · · Score: 2

      Templates I think were a mistake to add to C++. It has removed a lot of object orientation from C++ programs, and it has bloated things up tremendously because of popular styles of using them and due to STL. Templates are essentially smart macros. You end up with duplicated code for each instantiation, and with some styles even the functions themselves are inlined. This only works because this style is big on the PC where there is massive amounts of RAM and cache space to soak up the inefficiencies. The current compiler/linker technology is not capable of effectively turning template heavy code into efficient code by recognizing when there is duplicated code that could be combined into shared object code. Often what is normally a library of object code in other languages turn into a library of header files in a template-heavy C++ style.

      Now templates as a concept aren't all bad. A small template that provides type safety while sitting on top of a small tight library is great. Programmers need to learn their tools, learn how to use them well, and learn when to not use them. But most programmers don't do this, instead they learn to follow what other people do blindly until it becomes a habit.

    11. Re:Plain ol' C might a better option by david_thornley · · Score: 1

      Templates have removed a lot of object orientation from C++, true, but I don't see what's wrong with that. O-O programming is really useful when doing some things, and not particularly useful in others. If you were try to replicate the STL in a straight O-O language, you'd enforce complicated inheritance trees and lose type safety, which I consider bad things.

      I'm not as concerned with current efficiency as some. OP said his code should work on PCs (Windows and Linux), and those handle templates reasonably well. People will figure out better ways of handling them in more restricted environments, and in the meantime they're extremely expressive.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Plain ol' C might a better option by david_thornley · · Score: 1

      That advice is twenty years out of date. C++ is not just a souped-up C. A good C++ program and a good C program are considerably different, and learning C well is an inefficient way to learn C++, and one that can lead to bad habits.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:Plain ol' C might a better option by Darinbob · · Score: 1

      Before STL was widely adopted I had used RogueWave (commercial) class libraries that operated using inheritance. These were honestly a lot easier to use in my opinion. You dealt with pointers to objects. Then the iterators didn't have to check against the "end" of a collection because it returned 0 at the end, as in "while (x=next())". This felt a lot more like classic OO languages like Smalltalk.

      With the STL you're constantly doing copy constructors because you're passing around objects instead of object references, etc. I have written some templates around an STL container of void* pointers, and some other stuff, with the template there to just do the type safe checking for you but it didn't replicate code over and over for each instantiation and it copied pointers instead of objects.

      When you get down to it, std::list should be able to share completely the object code for std::list, but in practice the compilers don't do this very well.

      Now for this simple example the amount of code growth is not very large at all, but in some large projects this extra code adds up to something very noticeable. You'd think that on a PC it should not matter, but it does become noticeable and important a lot of times. Bigger code means you're not using your cache as efficiently. PC games for example often take code size and speed very seriously. If you need to respond quickly to millions of queries then increasing speed even slightly can result in big improvements in responsiveness.

    14. Re:Plain ol' C might a better option by Xrikcus · · Score: 1

      std::vector a {1, 2, 3,4, 5};
      for(int &v : a) {...}

      Uses a reference, short and clean. Before C++11 the STL was a little copy constructor heavy, but only if you use it that way. If you use large objects, make your vector a vector of unique_ptr. It cleans up the data automatically when you delete the vector. On top of that, move construction/assignment should remove the majority of the cost of copying objects around in STL containers.

      An STL implementation presumably could fairly easily optimise a vector> to a single type erased implementation, as long as the code that called delete had the type available. In the end you're trading code growth against pointer indirection and most evidence I've seen suggests that code growth is the smaller issue in the majority of code bases. I'm sure there are exceptions though.

  11. C++ with Java for networking by Zumbs · · Score: 3, Informative

    It is possible to use C++ with Java. Try to look at Java Native Interface (JNI). It comes with a performance penalty on each call across the interface, but if you are using it for networking, the penalty will be negligible.

    If you are working on Windows, it is possible to do the same with C# using a CLI interface wrapper. I have no idea if that trick works on Linux/Mac.

    --
    The truth may be out there, but lies are inside your head
    1. Re:C++ with Java for networking by Kagetsuki · · Score: 4, Informative

      JNI is the absolute most awful native interface system I have ever seen. If you absolutely must go the JNI route may I recommend using SWIG to generate things for you. It will require some additional wrapping but at least it won't make you want to end your own life.

      As for performance penalties you'll have the additional overhead of a JVM as well. The whole setup you are proposing I'm guessing you've implemented before and are comfortable with but to me it sounds messy and unnecessary - especially with so many good networking libraries available for C++.

    2. Re:C++ with Java for networking by jdk1 · · Score: 1

      If you are working on Windows, it is possible to do the same with C# using a CLI interface wrapper. I have no idea if that trick works on Linux/Mac.

      We have a .NET C# project that uses C++ code for the nitty gritty bits, and it runs under mono on Linux. Don't know about Mac.

    3. Re:C++ with Java for networking by Zumbs · · Score: 1

      JNI is the absolute most awful native interface system I have ever seen.

      In my experience, JNI is not significantly worse than similar wrappers, but the approach certainly would not be my first choice. I used JNI for an embedded Android app, where the performance of raw C and C++ was needed to do the heavy lifting. Good points with SWIG and the JVM overhead, though.

      --
      The truth may be out there, but lies are inside your head
    4. Re:C++ with Java for networking by Kagetsuki · · Score: 1

      What I don't like about JNI is how it approaches wrapper generation - essentially assuming you are writing your C/C++ code *specifically* to be used in Java. Case in point being the fact you basically have to directly modify your header files. This can of course be avoided by writing code/headers that include JNI and your native headers - but then on top of that you need to write wrapper headers and wrapper code. Most other wrapper systems don't make this assumption and just let you write an interface or some wrapper code and be done with it.

      On top of that actual generation of the wrapped binaries isn't nearly as smooth and integrated as say Ruby native gems. Maybe it can be set up to be cleanly automated so everything will be generated for your build target at compile time but in my currently limited time dealing with Java I've yet to see such a setup.

      I would like to point out I'm no expert on JNI and have only used it twice before going all SWIG. Actually if you know of a good example or guide for JNI that could set me straight I'd love to see it.

  12. Wrong setup by bytesex · · Score: 1

    'Cross platform' and 'manage memory usage and disk access at a very granular level' do not readily go together. And not in Java either. Abstract your 'granular access' away in a C (I said 'C', not 'C++') library of your own. Use a lot of #ifdefs. On top of that, build in whatever you want.

    --
    Religion is what happens when nature strikes and groupthink goes wrong.
    1. Re:Wrong setup by sqlrob · · Score: 1

      Absolutely positively do not use a lot of #ifdefs, you're asking for a lot of hurt.

      Move the platform specific code into files, and then use abstractions in the main code, pull in the different implementations in the make file. You'll have just a few #ifdefs in the main code for the right header files.

      Do frequent compilation across the platforms, because you will screw it up. Make sure to have plenty of tests for the different behavior between platforms.

  13. I'd reccomend to use Qt as a base for your project For sure you can use boost and asio as well

  14. 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.

  15. There is no perfect lang by faway · · Score: 1

    C++ is often unreadable but e.g. Objective C is only usable on Apple computers.

    1. 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.
    2. Re:There is no perfect lang by frank_adrian314159 · · Score: 2

      No one denies that one can write bad code in any language, but the accusation still stands - languages can help or hinder understandability with their syntax. C++, and it's desire for backward compatibility with C, led to some really unfortunately syntactic decisions that make the code less legible. Operator overloading isn't very good for understanding of performance characteristics (Is this adding 2 ints or an array?). Memory management has provided code bulk (because not everything can be RAII) and the plethora of pointer idioms one must navigate if one has any sort of sizable codebase that has been maintained by many others over the years. Now add on features and libraries so broad and complex that organizations actually have their own dialects of C++ (or so I am told) that their employees are allowed to use. Need I go on?

      Frankly, C++ has advantages in some places, but aiding in making code legible and understandable is not one of C++'s strong suits. And I've worked on (and probably helped generate) enough crappy C++ codebases to know of which I speak.

      --
      That is all.
    3. Re:There is no perfect lang by DrVxD · · Score: 1

      Yes. And it turns out that it *is* possible to write readable Perl. It's just that if you do so, all the Perlista look at you as if you were something they'd trodden in.

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    4. Re:There is no perfect lang by Grishnakh · · Score: 1

      Yes, I used to do a lot of OO Perl programming. It's entirely possible to write clean-looking Perl that looks pretty much just like C.

      Unfortunately, a lot of Perl programmers don't.

  16. Why not? by Anonymous Coward · · Score: 1

    Why not give it a try with FreePascal/Lazarus. Ease of development, lots of core libraries, lots of controle, cross platform..

    1. Re:Why not? by jfbilodeau · · Score: 1

      I second that!

      --
      Goodbye Slashdot. You've changed.
    2. Re:Why not? by orient · · Score: 1

      As my CS professor always said: there is nothing C++ can do and Pascal cannot.

      --
      Laudele lor desigur m-ar mahni peste masura.
    3. Re:Why not? by Grishnakh · · Score: 1

      Qt works great for C++ GUIs.

  17. Re:I'd suggest C by faway · · Score: 1

    Objective C is more readable and easier to debug than C++. However on Linux it is a mess. GNU's implementation is not good.

  18. Why not? by mrthoughtful · · Score: 3, Informative

    I love C++. It will take you a a couple of years to get good at it, but as you say - it's a personal project, and I am guessing you've had enough of Java.
    However, if you are doing any sort of front end GUI for it, then don't go there. Stay with Java. There is no unified FE GUI for C++ which I could recommend.
    Likewise, many of the suggestions above seem to have not read that you already know Java.

    --
    This comment was written with the intention to opt out of advertising.
  19. Not Yet by Sarusa · · Score: 1

    I don't think you know enough to know that yet. Or at least if you know enough you haven't told us enough to justify it. As cliche as it is, I'm going to quote Knuth: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%"

    I suggest you just do a prototype in whatever's easiest, fastest, and most flexible. Python, Ruby, C#, whatever you like. Get it working . Then see if it's slow as you think it is and go from there.

    I see lots of hostile responses here (either way) but as a practical person who has to use C++, Python, bash, C#, and (argh) dos batch every week I would start with C# or Java (since you know those) and once you get the logic working like you want, see where the bottlenecks are then replace critical sections with C++ as you need to. That's worked really well for us. To begin with, the parts that we thought would need to be low level rarely were. Smart algorithms are much more useful than brute force. Or using libraries that do the brute force for you smartly. After a while you get a feel for it - but you don't have that yet.

    The key bit is that you'll be 10x more productive in an expressive powerful language like C# or python than you will be in a restrictive fine detail language like C++, so it makes sense to bang out the framework in something flexible then only optimize the very smallest of key performance critical sections. Experience says that's less than 5%, usually 1%... so again, Knuth is right on the nose with his 3% estimate.

    1. Re:Not Yet by david_thornley · · Score: 1

      In many cases, that would be good advice. However, the OP said that his big problem with Java and/or C# was memory management. I really, really doubt that writing Java or C# code that tries to use C++ for memory management is going to be worth the effort.

      I wouldn't consider C++ a restrictive fine detail language. Nowadays, it has plenty of available abstractions and libraries.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  20. not quite by yalos · · Score: 1

    I use this language since more than 15 year. In time I augmented with stl/boost/asio /c++11. I never used the plain C. Based on this experience I would say: 1. If you are not already comfortable with the language don't use it. Use whatever you are best with at the moment. 2. Yes, you can do fine grained memory/disk/network management. However, this is a problem of how much time you invest. You are competing here with armies of developers that implemented this topics for you in "Java/C#". You are only one. I have doubts you will be more efficient. 3. The cross platform support is there but you must understand a few about each OS. At minimum you must understand something like CMake or the GNU build system. And, of course, the two mentioned above are not best suited for Windows. 4. If your project involves a UI don't code that in C++. To your questions: 1. Yes boost does a very good job in abstracting the OS. 2. Yes asio is excellent when programming I/O. 3. On paper, I don't think there is a better language for "granular memory and disk management". However, if I were you I would use Java/C#. If When you will be in charge of a large team with a serious budget, think about C++ again.

  21. Tools and architecture by jandersen · · Score: 1

    You mention 'C/C++', and I think you need to realize that the two don't really mix well; in my experience, you go with one or the other, simply. True, you can use C style practices in C++, but then what's the point of using a C++ compiler?

    I think there are many, excellent reasons to choose C++ for a project, but perhaps not the ones you list. Things like control over memory allocation, cross-platform and networking may not in theselves be compelling reasons for choosing C++, as they can be handled easily enough in C. Cross-platform and networking is all about following the POSIX standard, really, and getting away from the Windows toolkit. That and separating the presentation layer from the business layer(s). This is perfectly possible in pure C - I have done it many times.

    The real reason for using C++ is that it supports design patterns well, IMO. Templates and template libraries like Boost are really about that; and design patterns are about adopting an architecture that is well thought through - they are formalized best practices, in a way.

    1. Re:Tools and architecture by lano1106 · · Score: 2

      C and C++ mix very well. Being able to use C API straight from C++ code, was design goal #1 from day 0 when C++ got invented

      Using C++ from C, is a little less straightforward but quite doable. I wrote a small article years ago on how to do it easily. Check for yourself if you are curious

      Idioms for using C++ in C programs

      concerning OP question. Despite I'm a C++ person, I would recommand doing it in C first. Yes, there are C++ framework such as Boost but I have never liked these frameworks because it bloats your exec with a lot of code (mostly templates) and it adds a magical layer (things works magically) that has a mystical aura (I mean only few people knows how ASIO really works under the hood). Even if you become an ASIO expert after lot of time, the project will still have the potential to become bloated and inefficient as soon as a new contributor, less knowledgeable will jump in. Efficiency is the price to pay to use these type of framework.

      Do what successful projects do, start easy and simple. Use C. If down the road, this appears to not be enough for your needs, reevaluate. FFMPEG comes to mind when thinking about a project that has exactly the same requirement than your project and has been very successful with C

      Good luck and have fun with your project!

    2. Re:Tools and architecture by david_thornley · · Score: 1

      Do NOT start in C if you're thinking of maybe going to C++ later. If you start writing in C, turning it into good C++ is going to require partial or total redesign. Pick C or C++ (I strongly recommend C++) and go ahead.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  22. Re: C++ is never the right tool by Anonymous Coward · · Score: 1

    Actually C++ does have garbage collection. For example, you can collect garbage with something like this. But as loonycyborg says, the RAII pattern is how you collect garbage with C++.

  23. What you think? by antiperimetaparalogo · · Score: 1

    I have been working in the Java / C# world for the past decade [...] 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.

    What you think?

    --
    Antisthenes: "Wisdom begins by examining the words/names." - excuse my English, i am (slightly...) better with my Greek!
  24. Why? by DrVxD · · Score: 3, Insightful

    The main reasons I have for this are the needs to manage memory usage and disk access at a very granular level

    And why, exactly, do you imagine you need these things?
    (You may well do - but you don't give a reason for it, so it's entirely possible that you don't need to manage those things on a granular level)

    --
    Not everything that can be measured matters; Not everything that matters can be measured.
    1. Re:Why? by mangobrain · · Score: 1

      Because with a description of the problem he wants to solve, rather than his proposed solution, someone may be able to point out that there are better solutions which don't involve this kind of low-level coding.

      http://xyproblem.info/

  25. Rule of thumb by DrXym · · Score: 2
    Personally I wouldn't choose C++ or C unless there was very a strong justification. If your code spends more time waiting for something to happen than actually doing something, then you shouldn't be using a low level language. If reliability is more important than raw performance then you shouldn't be using a low level language. If portability is important then you shouldn't be using a low level language. Conversely if you need to do lots of IO and / or control the file format, or interact with system / kernel services, then perhaps a low level language is suitable.

    Boost is a very powerful addition to C++ but that doesn't mean it's as easy to write code as it is in a high level language. e.g. boost's asio is extremely complex and even doing something simple with it like setting a timer is far more pain than other languages. Boost doesn't implement stuff like web sockets or other things either so it's no good on its own without other libraries. If I had to write something in C++ which was performing in a role that would more naturally fall to something like C# or Java, I'd probably use the QT library instead but only after being certain that I needed C++ to begin with.

    1. Re:Rule of thumb by david_thornley · · Score: 1

      Why would portability suffer with C++ or C? There's C compilers for almost anything, and C++ compilers for most targets worth targeting. Java needs a JVM, and cross-platform C# is pretty well limited to Mono.

      You'll have to compile separately with C++ or C, but that's not a big problem.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    2. Re:Rule of thumb by DrXym · · Score: 1
      Porting a Java application from Windows to Linux is normally as simple as copying the compiled .jar / .war / .ear over and just running it. The only reason it might not be is it contained JNA or if someone had hardcoded an assumption about the OS into it. Ordinarily neither would be the case and it is not unusual for people to be developing software which ultimately runs on big iron Unix from PCs at their desk.

      Porting a C++ application from Windows to Linux means writing it with portability in mind from the very outset, sourcing which libraries you use, rebuilding the code from source and screwing around with the vagaries and differences of different compilers and toolchains. Even in the best of circumstances the code is likely to be plastered with #ifdefs and conditionally compiled code to deal with differences. The best bet would be something like QT which is fairly portable and has a large support library but it's still not as simple as Java.

    3. Re:Rule of thumb by david_thornley · · Score: 1

      It's not that hard. Write it in standard C++ (or else whatever subset Visual C++ is currently running) except where you get something implementation-specific. Abstract those things over. I'm not saying that it's as easy as with Java, but I think you're overstating the problem.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  26. Re:I'd suggest C by Viol8 · · Score: 1

    All true, except that C++ makes some things so much easier? Need a linked list of variable length strings that will be updated? vector in C++. In C you'll be rolling your own linked list and managing your own char* array memory using realloc(). Not hard for an experience C programming but still a lot messier than the C++ equivalent.

  27. Re:Yes. by Viol8 · · Score: 1

    "I just pointed out that dbus written in C++ would be much faster then the C version: simply by avoiding the cache hits."

    I read your comment and I see nothing to justify that position. Apparently you seem unaware of the existence of resizable arrays in C.

  28. No. by viperidaenz · · Score: 3, Interesting

    If you're better at Java or C#, use that.

    Sometimes the right tool for the job is the tool you know best.

    If you're not confident at what you know, perhaps the best tool is someone else.

  29. things like TCP and SSL by umghhh · · Score: 1

    are in this day and age done indeed by libraries. Chose one that fits and for each language usually there is more than one choice.
    What this means is that If you really have a choice of language for your project and want to see if certain tool is useful just make a prototype. There is no better way really.
    At the end it is like buying a house or getting married - you have good things and bad things in each choice but if your choice fits your and your teams profiles then with a bit of luck you will have success with some but not unreasonable amount of stress.

  30. Use one language by jones_supa · · Score: 4, Insightful

    I am about to start a personal project which I believe should be done in C/C++.

    I cringe when someone says "C/C++". Sort that out first by choosing one language for your project. Either write lean and clean pure C code, or fully use the proper abstractions of C++ to write memory-safe and easily-maintainable code, but don't make an unprofessional crusty mix of the languages.

  31. Re: C++ is never the right tool by Carewolf · · Score: 4, Informative

    That's because you have no clue. The problems of high-performance, incremental garbage collection was already solved in the 80s and it is ridiculous that there are still ignorants like you around who think that reference counting and incongruent OOP design patterns could replace GC.

    It has only been solved in theory, not in practice. In practice garbage collection is still garbage if you need high performance, usually because high performance usually implies low memory usage and consistent high performance.

  32. Cython by michal.slonina · · Score: 2

    Check out http://cython.org/. This project will enable you to write high level logic in python and drop to C in the performance critical sections of your code.

  33. Re:C++ is never the right tool by Anonymous Coward · · Score: 2, Insightful

    Nothing important in VS is written in C#. The compiler, linker and so on - you know the things that need to be tight with optimal performance, are all written in C++. The platform itself (WPF) is written in C++ (Visual Studio UI is WPF). .NET CLR is written in C++. Do you want me to continue or are you happy enough stewing in your own ignorance?

  34. Re: C++ is never the right tool by TheRaven64 · · Score: 2

    C++ is never the right tool for the job, but for a lot of jobs the right tool doesn't exist and C++ will work.

    --
    I am TheRaven on Soylent News
  35. Re: C++ is never the right tool by TheRaven64 · · Score: 3, Informative

    The C++11 specification was explicitly written to permit garbage collection and includes standard library functions for providing hints to a garbage collector.

    --
    I am TheRaven on Soylent News
  36. Re:C++ is never the right tool by bensch128 · · Score: 1

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

    Mod parent up!

  37. Re:Yes. by Viol8 · · Score: 1

    And? You can do that in C too - replace class with struct. However in both languages it might default to word size so better to use #pragma option to make sure it doesn't.

  38. Re:C++ is never the right tool by rippeltippel · · Score: 4, Insightful

    Could you describe a project for which the choice of c++ is a good one?

    Guess what, you can easily do that:

    • 1) List ALL the software you normally use (don't forget your OS and the browser you're using now)
    • 2) Cross out the software written in C++
    • 3) Cross out the software written in a language which is itself written in C++ (e.g. Python)
    • 4) Cross out the software that rely on another software/framework written in C++
    • 5) Feel free to use the remaining items on a daily basis, knowing that C++ is not undermining your life anymore

    Oh... good luck!

  39. Re:C++ is never the right tool by rippeltippel · · Score: 2

    Edit: My statement that Python in implemented in C++ may not be entirely correct (there are C implementations) but that's not the point and shouldn't prevent you from doing the exercise.

    By the way, you're welcome to copy your final list on Slashdot, I'd be curious to see it for my own education.

  40. Re:C++ is never the right tool by Anonymous Coward · · Score: 1

    Except the C++ source code navigation, which they destroyed in the C# version (after VS2008 ?). And except that the editor is no longer real-time on my machine. Which is a monster with 20GByte RAM.

    I need a plugin(!) to just get proper source code navigation back.

    In other words, Dumbing Down To C# has fucked up Visual Studio. I hope the Politically Correct Pussy In Charge will soon be booted into some harmless Government Chair. Get me the real C++ guys back, Microsoft. Visual Studio must be de-pussified !

  41. ASIO by Kagetsuki · · Score: 2

    ASIO is in fact part of Boost now and I personally like it. The thing you need to remember though is that ASIO is not an HTTP client or really any type of client at all - if you want to do HTTP you'll need to write the HTTP headers and handle chunking yourself. That's actually not so hard though. For cross platform SSL you just need to use Open SSL which is actually pretty simple in C++.

    Basically if you want really fine control of your network streams or are using things other than just HTTP then ASIO is going to be what you want. If you just want to have something handle HTTP for you then there's quite a few other libraries out there you can choose from.

    1. Re:ASIO by s_p_oneil · · Score: 1

      That is a very poor analogy. It's nothing like driving between two cities. Designing and writing software is more like designing/building a vehicle you want to sell to others. Choosing a language and libraries is like choosing factory machines and tools needed to manufacture the vehicle, deciding which parts you're going to buy elsewhere versus make in-house, and so on. These decisions can have major impacts on how quickly you can get the car to market, how hard it is to add certain features to the vehicle, how reliable it is, how fast it can go, how safe it is in a crash, etc. All of this can impact whether your company stays in business or goes under. Depending on the target market, you may need to build a sports car, an economy car, a tank, a boat, a plane, a helicopter. You may choose to buy a pre-made part elsewhere that works great in internal tests but breaks down under certain conditions in the real world. Sometimes decisions like this seem obvious, but not always. In many cases there is no "perfect" choice, and in some cases you may end up regretting any choice you make (the grass appearing greener on the other side because you can't see the bugs eating the roots on that side until you've paid the cost to move over to that side ;-).

    2. Re:ASIO by s_p_oneil · · Score: 1

      Oh, woops. This was supposed to be a reply to the post directly below yours. Sorry, my bad!

  42. Re: C++ is never the right tool by jblues · · Score: 2

    Doesn't Automatic Reference Counting at the compiler level give most of the benefits of Garbage Collection (except for manually breaking retain cycles with a 'weak' modifier) at the same time as offering benefits on resource-constrained devices? A garbage collector takes CPU clicks, and therefore reduces performance and battery life.

    Languages like Swift and Vala use reference counting and have a very modern, clean feel. Objective-C also does, if you don't mind an antiquated syntax.

    --
    If it acquires resources on instantiation like a duck, then its a shared_ptr<Duck>
  43. Bigger Question: Does Language Matter Anymore? by fygment · · Score: 1

    It seems like having to make a trip by car between two cities and trying to decide which type of car to use?

    So does it really matter if you choose a Ford, Hyundai, Tesla, Ferrari, Saab, Toyota, etc.? In the final analysis, wouldn\t any of those vehicles get you there just fine? Why not go with what you're comfortable with?

    --
    "Consensus" in science is _always_ a political construct.
    1. Re:Bigger Question: Does Language Matter Anymore? by david_thornley · · Score: 1

      OP tried using what he was familiar with, and found it inadequate. Even in motor vehicles, there's tasks that are better suited to different vehicles. If you need to haul a lot of stuff, you may want a pickup truck. If you don't have much money for gas, or don't want to spend it, a pickup may not be a good choice, and I assure you I can park my Civic in a smaller spot than a big pickup needs. If you're going somewhere there aren't good roads, you may want a good off-road vehicle.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  44. Re:Is You Father The Pope ? by Joey+Vegetables · · Score: 2

    Here is Stroustrup's take on learning C++, which includes some examples of why you might not want to start with C first.

  45. No mention of COBOL? by SargentDU · · Score: 1

    I am getting up in years, but find it interesting that no one mentioned COBOL but me. :)

  46. Re:C++ is never the right tool by Anonymous Coward · · Score: 2, Insightful

    So true!

    Personally I don't like to hire people that don't understand low level programming, unless it's for mundane / cheap stuff; no matter what the argument is, the guys that know C / ASM always seem to have a better understanding of problems in general.

  47. Re:I'd suggest C by jfbilodeau · · Score: 1

    std::vector is an array--not a linked list. For list, use std::list, or even better: boost::instrusive::list.

    --
    Goodbye Slashdot. You've changed.
  48. Re: C++ is never the right tool by tlolczyk · · Score: 1

    C++ is the best language for garbage collection because C++ makes so little garbage.

  49. Re:I'd suggest LISP by pigiron · · Score: 1

    For a list use LISP.

  50. Re: C++ is never the right tool by beelsebob · · Score: 4, Insightful

    Lack of garbage collection is one of many reasons why C++ produces fast code. The entire point of using C++ is that you want to have control over how, when and where things are allocated and deallocated.

  51. Re: C++ is never the right tool by beelsebob · · Score: 4, Insightful

    In practice, single desktop class machines with 6000+ concurrent users are not typical use cases. Instead, high performance applications are likely to look more like 3D rendering engines.

    In practice, when you have 16ms to produce a frame, it really matters that the garbage collector doesn't kick in for 2ms once every second, because that'll push you past your frame window and lead to stuttering and dropped frames.

    In practice, it really matters that you can structure your code to make sure no allocations are happening during certain critical operations, because an allocation will potentially need a new page, and the kernel barrier and/or hit locks resulting again, in 1-2ms of unexpected delay, and a dropped frame.

    In practice, it really matters too that you have enough control over memory layout to guarantee that certain structures are all going to end up in cache at the same time, and that you're not going to be doing a bunch of pointer indirection fetching memory during time critical rendering code.

    In practice, modern garbage collection doesn't allow you to solve any of these problems. That is why real time rendering engines are still written in C++, and will continue to be, and why everyone writing them will continue to be glad that C++ is not garbage collected.

  52. Re: C++ is never the right tool by Anonymous Coward · · Score: 1

    Thank you. Couldn't agree more. I operate in a world where we have to guarantee 60 Hz deterministic real time performance, even in the worst case, while rendering a full screen HD image to the display using a SOC with a single core 800 MHZ processor. There are no extra cycles for software architecture that does nothing.

    We manage memory the old fashioned way: quality built software. Do we manually call new() and delete()? yep. Do we leak memory? Nope. Can I prove it? You can bet you life on it. Literally. We have proven our software will never leak memory--proven it to the point that engineers have signed off on our software certifying it for use in life critical systems. A car you drive, an airplane you fly in or a medical device used by your doctor may have our code in it.

    Now please *PROVE* to me that a garbage collection based system will never fail. *PROVE* you will never fragment memory so badly that new allocations fail even though memory is available. *PROVE* that a call to new() won't suddenly take 1 millisecond or 10 milliseconds instead of 10 microseconds.

    Now finally, after proving that it is safe enough, *PROVE* that your system is as fast as mine and I'll switch.

    I will be long retired before that comes to pass.

  53. Re:C++ is never the right tool by ComputerGeek01 · · Score: 1

    C is not C++. Since the release of C99 you haven't been able to treat C++ as a superset of it's predecessor. Now with the push to rapidly update C++ every other year or so, the differences between them are going to become drastically noticeable even to the most novice user pretty soon.

  54. Re:C++ is never the right tool by tompaulco · · Score: 1

    Except the C++ source code navigation, which they destroyed in the C# version (after VS2008 ?). And except that the editor is no longer real-time on my machine. Which is a monster with 20GByte RAM.

    I need a plugin(!) to just get proper source code navigation back.

    In other words, Dumbing Down To C# has fucked up Visual Studio. I hope the Politically Correct Pussy In Charge will soon be booted into some harmless Government Chair. Get me the real C++ guys back, Microsoft. Visual Studio must be de-pussified !

    I code in C++ and Java and I have noticed as well that the supposedly low-level fast code in VS is much slower than the interpreted code in Eclipse. Incredibly slow on VS is the context sensitive help. I have trouble understanding why VS is so slow. The feature set seems to be much more limited than Eclipse, so I can't imagine what it is spending all it's time doing. Heck VS doesn't even have Variable name refactoring out of the box, yet it is slow, slow, slow.

    --
    If you are not allowed to question your government then the government has answered your question.
  55. Re: C++ is never the right tool by tompaulco · · Score: 1

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

    I agree. If I am done with a reference, I am done with it right now. If I want to delete() my reference right now, then I want to delete it right now. If I am worried about CPU cycles over memory at the moment, then I can make it put off deleting in my code. I really like Java and do most of my coding in Java, but the two things I wish were in Java is a deconstructor and the ability to recover memory for a particular object at my discretion.

    --
    If you are not allowed to question your government then the government has answered your question.
  56. Re:Use ADA by darkwing_bmf · · Score: 1

    ADA is the Americans with Disabilities Act or the American Dental Association. The programming language is called Ada.

  57. Re:C++ is never the right tool by rockmuelle · · Score: 4, Interesting

    Python is written in C. Linux is written in C. OS X is written in C (with libraries in Objective C). Most low level software is written in C, not C++. It's very important for this exercise to differentiate C from C++. They are not the same language and haven't been since C++ stopped being implemented using macros and the preprocessor and got its first compiler.

    C is a much simpler language to learn and maintain, especially if you're doing low level code. C++ has a lot of very nice features, but it's benefits really only come into play if you're willing to put the time and effort into properly learning generic programming (the foundation Boost and the STL).

    But, as most people have already pointed out, starting with Python and then migrating portions over to C or C++ as needed for performance is a much better approach. You can manage IO just as effectively from Python as you can from C or C++ and your development time will be much much shorter.

    -Chris

  58. C++, cross-platform on what planet? by Mocko · · Score: 1

    Qt is cross platform, but non of the "granular memory stuff" will be. C++: write once, compile everywhere, with conditions Java: write once, debug everywhere Python (w/ Qt or wx): write it and get on with life

  59. It's not the worst. And: It depends. by Qbertino · · Score: 1

    Since you're not saying what kind of tool/programm you're trying to build I presume it's some kind of performance critical focused but non-trivial application. So a compiled language probably is the best choice - you won't be dependant on some VM stuff or an interpreter.
    The real C family of languages (I'm excluding C# with the 'real') isn't the worst choice for this sort of thing. In fact, it's just about the only choice. With C, C++ and Objective-C left to choose from, C++ comes to mind as a tried and true systems language.

    Long story short: You can't go wrong with picking C++ - just don't expect your code to be the cats meow from the get-go. Once you're finished you'll know enough to rewrite the entire app again. But we all know that's how it goes with new PLs.

    I still do have to important pieces of advice for you:
    Did you check the existance of FOSS Unix tools? It could be that your problem can be solved by doing some tricky CLI and scripting stuff with a set of specialized *nix tools - perhaps just compiling them into a single binary. ... Check that to save yourself tons of work.

    Something else: If you're in it for the learning experience consider those new hip system PLs Go and Rust. They look promising ... or at least interesting.

    Good luck.

    --
    We suffer more in our imagination than in reality. - Seneca
  60. C++ is great if you don't abuse it. by Codeyman · · Score: 2

    As a systems programmer, I have used both C and C++. When using C, I (and my team) needs to expressly have the discipline to embrace the tenets of C++ vis-a-vis encapsulation, maybe some facade dp thrown in. Most of the rookie mistakes are easier to spot in C, but there is a lot more code to be written in C to achieve the same effect (writing & using an object agnostic linked list for example).
    When using C++, things are hidden in plain sight, and rookie mistakes are easily overlooked, because someone found a "smarter" way to use the language. I've pulled my hair out in cases when people had overloaded operators in nonsensical ways. People would just compare a string with constant, without knowing that it is invoking a copy constructor and equals operator, which in turn is doing some form of strcmp to get the job done. C++ is great for system software if people know the ins and out of it and performance isn't of a great concern. It will give you the same performance as C if you know how to use it well.
    Also if performance is important, you'd probably need to use DPDK on intel boxes for networking, squirrel away huge pages for your memory allocator or do something like jemalloc etc, so your choices might be limited.
    If performance is not THAT important, then most of the modern libraries build on top of any high level language will give you all the tools that you need to build your project. Personally I'd try to look at Go. I don't know much about it, but it seems to have taken care of a lot of pain points in systems design (specially queuing, async processing, threads etc).

    1. Re:C++ is great if you don't abuse it. by david_thornley · · Score: 1

      If you've got a good optimizer, it's likely to sidestep making copies in a comparison like that. If you don't have a good optimizer, you've got much bigger performance problems to worry about.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  61. Have you actually demonstrated you need C++ yet? by jeff4747 · · Score: 1

    Have you actually demonstrated that the higher-level languages you are more familiar with just can not possibly do the job? And keep in mind both RAM and disk are cheap, so "just add more" may work if saving space is your motivation for "granular control".

    Whip up a testbed in the higher-level languages you are more familiar with to simulate a load test, and see what sort of performance you get. Zero bells/whistles, just "how much of data that vaguely resembles what I'll be seeing can I shove through the pipe.

    If that shows you don't get good enough performance, then try one of the tools that will generate a native binary from the higher-level language, and see if that is good enough.

    Often our intuition of what can be done with these systems is off by several orders of magnitude. So make sure you really need it before you go all-native, especially because you're less familiar with all-native. For example, latency over a typical Internet connection means you'll be network-bound no matter what language you write it in, so write it in whatever you're most comfortable with.

    Also, if there's particular operations that are really the bottleneck, consider writing the rest of the program in a higher level language, and writing the bottleneck in C or C++. All the high-level languages have some sort of native interface.

  62. Re:Wrong questions by darkwing_bmf · · Score: 1

    The primary requirement for a program is correctness.

    Not necessarily. For many programs "good enough now" beats "completely correct when I no longer care about the result". For instance, many games cut corners when rendering graphics in order to increase speed. Does it really matter that a shadow is off by a couple of pixels if the alternative means the game will not run on a laptop at playable speeds?

  63. Observer effect at work by slashdice · · Score: 1

    If you have to ask the question, it changes the answer.

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  64. Re:C++/CLI + C# by TemporalBeing · · Score: 1

    C++ can be used in Managed Mode, if you're working with Microsoft Tools. You can write your critical code in C++/CLI that also gives you access to low level stuff for the parts that you need, compile as a static library, then use C# for everything else.

    No, just NO.

    From a performance perspective, you immediately run across thunking between C# and C++/CLI, not to mention the API idiocies like not being able to sent a buffer from C++ to the network directly (you have to write a loop and send integer sized chunks at a time, then at the end send the final few bytes).

    So unless you want to screw yourself well, just avoid C++/CLI. You'll thank me later.

    --
    Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
  65. You say you have to manage the memory, Yes? Maybe? by bigsexyjoe · · Score: 1

    You say you need to manage the memory yourself, so I'm going to believe you. I believe this completely eliminates garbage collected languages from consideration*, and that's most languages these days. Aside from C/C++, I think you still have Rust, D, and assembly as contenders. You might be able to use Java with with sun.misc.Unsafe, but that is not really recommended.

    Not knowing too much about these languages, I would tend to think Rust might be a good choice. People seem to like it. I believe legacy code bases are frequently a big consideration in the decision to use C++.

    And as others have said, you might be able to write libraries in C++ and include them in a code base that uses a higher level language, like Python.

    *Are there languages that allow garbage collection and manual memory management? Not sure. I believe the answer is no.

  66. Re: C++ is never the right tool by Grishnakh · · Score: 1

    We manage memory the old fashioned way: quality built software. Do we manually call new() and delete()? yep. Do we leak memory? Nope. Can I prove it? You can bet you life on it. Literally. We have proven our software will never leak memory--proven it to the point that engineers have signed off on our software certifying it for use in life critical systems. A car you drive, an airplane you fly in or a medical device used by your doctor may have our code in it.

    Please tell me which airplanes have this shoddy code so I can avoid them. I've worked on avionics systems, and they do NOT use delete(), ever. That's completely against coding standards. Once memory is allocated in an embedded system, it cannot be de-allocated.

  67. Re:Use ADA by Grishnakh · · Score: 1

    That's because Ada was named after a person, a woman known generally as "Ada Lovelace" (she was a noble in the early 1800s, her full name is really long). Java was named after either an island or a type of coffee or both. Python was named after a snake. PHP is an acronym, which originally stood for "Personal Home Page". Acronyms are generally written in all-caps; that's why it's written that way.

  68. Re: C++ is never the right tool by Altus · · Score: 1

    Just an infinite tape then?

    --

    "In America, first you get the sugar, then you get the power, then you get the women..." -H. Simpson

  69. Re:C++ two big driving use cases by Grishnakh · · Score: 1

    The thing you're missing here is library support. Modern programming makes use of lots of libraries (esp. for things like GUIs), and really new languages may not have the library support that a mature language enjoys.

  70. C++ and Qt is cross-platform, high function by sdw · · Score: 1

    My preferred general purpose C++ solution would be to use Qt when possible. It already has virtually everything you would use in an operating system with baseline networking, GUI, etc. already wrapped for cross-platform use in a clean, powerful way.

    If you are writing a utility or a service, there are other choices. If you think you need the widest range of features, you might need a native GUI, GPU access, etc., Qt is the only real choice.

    Depending on what you are trying to accomplish, Node with C++ modules provides a nice base. It is even used as the basis for desktop apps with web-based GUIs (see Atom editor https://atom.io/ .) You get Javascript scripting, full web server capability, WebSockets for bidirectional communication, etc. Nginx is another possibility for something like that.

    You could use Java or C# for portable-ish apps. In some ways, Qt seems even more portable now, especially for GUI and OS-specific features. Java and C# also don't make for great UI without a lot of work, and then it tends to be sluggish. For UIs, you want either a modern web UI, or a well-designed Qt UI. Interestingly, Qt includes a modern web capability embedded. Even the native Qt GUI is styled using CSS.

    For a pure server app, Java, Node (Javascript), Python (according to many), and C++ are good. PHP, because Facebook has improved it, may be OK. Perl, Ruby/Rails, Drupal, WordPress, etc. all seem to be fading for app framework use because of developments in Javascript libraries. WebComponents / Polymer SPAs are very interesting.

    --
    Stephen D. Williams
  71. Re: C++ is never the right tool by Grishnakh · · Score: 1

    The system allocates all the memory it needs at start-up. The tasks it's assigned fit into the available system memory. Since there's no such thing as processes which are started and stopped and restarted, you have no need of deallocating memory.

  72. Re: C++ is never the right tool by TsuruchiBrian · · Score: 1

    Can I prove it? You can bet you life on it. Literally.

    You solved the halting problem? Awesome. Now make a bug free static analysis tool that finds all the bugs in everyone else's code, and we will live in a world where every piece software is perfect and you are the greatest computer scientist who ever lived after proving Turing wrong.

  73. Re: C++ is never the right tool by TsuruchiBrian · · Score: 1

    You aren't supposed to allocate and deallocate memory because it is usually not time-deterministic. But there are memory allocators that are time deterministic, but you lose some other nice features that general purpose memory allocators have.

  74. Re:Wrong questions by twisp42 · · Score: 1

    So I agree with your point but I think you missed the point of the previous point. However, correctness isn't limited to: "Did I adhere exactly to the mathematical definition of what I am trying to implement?"(in your case a shadow). But did my code match my intention or specification. No one will write a game, see it chug along at 2 frames and say "Well, at least that shadows nice..." Part of the spec, whether it is written or not, is the expectation that a game will run at a playable frame rate. Therefore, the slow implementation does not conform to a programmer's definition of correctness.
    Instead, I think the previous poster was implying that some tools and languages have subtle behavior that make it easy to make mistakes.
    E.g. If my language allows things like (where = is assignment):
    if (debug = true) { //do some expensive computation, or some other thing that was not intended }
    Then it might lead to fewer correct programs.

  75. Re: C++ is never the right tool by tepples · · Score: 1

    I heard it from the article "Why JavaScript On Mobile Is Slow". What about tracing garbage collection has changed in the two years since that article was published?

  76. Non-memory resources by tepples · · Score: 1

    OTOH with a generational collector, multi-cpu/multi-thread/shared memory system, the concurrency issues rear themselves in much fewer places, and the extra CPU's can be leveraged to provide nearly pauseless GC.

    When an object owns an unmanaged non-memory resource, such as a file handle, network connection, database connection, or graphics context, how are these resources destroyed? In my experience, the answer has been the dispose pattern, but it has as much conceptual overhead for the programmer as manual new and delete in C++. For example, any object that holds a reference to a disposable object after a method finishes must itself be disposable.

  77. Halting on LBAs is decidable by tepples · · Score: 1

    You solved the halting problem?

    The halting problem is undecidable in Turing machines. It is not undecidable in machines less powerful than a Turing machine. I imagine that coding standards restrict programs to a model that is less powerful than a Turing machine while still powerful enough for useful work. A physical computer, for example, is closer to a linear bounded automaton (LBA) than to a Turing machine. Halting on LBAs is decidable, yet an LBA can decide any context-sensitive language.

    1. Re:Halting on LBAs is decidable by TsuruchiBrian · · Score: 1

      The fact that he is calling new and delete gives us a hint that he is not using something less than a Turing complete language. I do still remember my automata theory pretty well, and actually work on safety critical code that is supposed to be "deterministic". In that world when people "prove" things, it simply means that they have restricted the use of confusing/error prone software constructs, and do lots of testing.

      They do not usually use a language that is reduced to the point of no longer being turing complete as this typically restricts their ability to do what is required.

      Of course, if they could *actually* prove the software was free of defects, they wouldn't need to test it.

      Furthermore, I've found, that removing these hard to analyze software constructs like (exceptions, inheritance, rtti, dynamic memory, etc), often leads to code, which while easy to analyze at a low level (e.g. no buffer overflows), is utterly unmaintainable at the architecture/design level (lots of duplicate code, non scalable, semantically ambiguous, etc).

  78. Reference count synchronization across threads by tepples · · Score: 1

    The developers of the Python programming language tried smart pointers. But the need for reference count changes to be atomic between threads resulted in a Global Interpreter Lock, in which only one core is allowed to run Python code at once unless the task is split up into multiple processes that share nothing. And even then it's tricky to keep a forked process's copy-on-write memory from decaying to copy-on-read when a reference count in the same 4K virtual memory page gets changed.

    1. Re:Reference count synchronization across threads by spitzak · · Score: 1

      Actually the reason for the Global Interpreter Lock is because cPython decided that had less overhead than making the reference counters atomic variables (plus you would still need some kind of locking when modifying any object with a reference count greater than one, though this is such a tiny amount of what a typical Python program does that it is probably irrelevant).

      I personally have doubts this is true, but the argument is not impossible. I am wondering if their measurements were on older systems, modern ones are better at atomic operations.

  79. No. Use optimal language(s). Write less code. by GodWasAnAlien · · Score: 1

    A few suggestions:

    1. If possible, do not write new code.
    If there is open source that does something close use that, and update for your needs.

    2. Use a language that fits the problem.
    It could be nodejs for certain complex http state machines. It could be python for high level applications. It could be C or assembly for low level performance requirements.

    3. Don't limit to one language. Sufficiently large applications are usually implemented in several languages. Not purely for programer preference. But because it fits. If you write 1000 lines of C++ for a task that could be done in 20 lines of python or nodejs, then you are doing something wrong.
    Solving the same problem twice (in multiple languages), will often help in design but also in revealing the optimal choice.

    4. Keep code modular, so you can easily replace an implementation( with a new language or new design). Modular, meaning split at a library/executable/networking boundary, not "Object oriented", which does not necessarily aide with any software engineering principal.

  80. Re: C++ is never the right tool by david_thornley · · Score: 1

    I disagree. In some respects, it's better. For example, it isn't just a memory management system, but a general resource management system. It's also more predictable.

    However, it requires more attention, and it's easier to have memory leaks. If you have a reference-counted system with blocks of memory pointing to each other in a circle, and you lose the address, in C++ you've just leaked that memory. In a language with modern garbage collection, the collector will find nothing pointing to that memory, and collect it. Also, reference-counted pointers require an extra memory access when created or deleted.

    In general, I prefer the C++ approach, but if the program isn't dealing with many resources besides memory the GC approach is usually better.

    While there's some support in C++ for GC, I haven't heard of any good GC implementations.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  81. Re:I'd suggest LISP by david_thornley · · Score: 1

    Strange; I use arrays and structs a lot in Common Lisp. Lists are a wonderful structure for code, but in my experience most data is best handled in other ways.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  82. Re: C++ is never the right tool by loonycyborg · · Score: 1

    Yeah, it might seem to be true, but automatic variables are simple to use and things like shared_ptr offer most of functionality of garbage collector when you actually need it. So I don't see much point in garbage collector. Other people too it seems given that there aren't any popular C++ gcs.

  83. Re:Wrong questions by darkwing_bmf · · Score: 1

    I agree with you. Tools should facilitate correctness.

  84. Consider Go by snadrus · · Score: 1

    It's GC'ed, but you can monitor memory & run GC any time you want. You're also much safer and have coroutines and a compiler which helps reduce dev-test cycles for interesting pointer things you may be doing (vs C/C++).

    --
    Science & open-source build trust from peer review. Learn systems you can trust.
  85. Re:Betteridge's Law says No, and I agree by norpy · · Score: 1

    You can also do this in C#, although to make it cross platform compatible you'll have to write a PCL to implement the memory management on each platform as the P/Invoke code won't be portable.

  86. Networking critical, cross platform = Erlang by ZeroWaiteState · · Score: 1

    The Erlang portion will be faster than anything in Python, and will be competitive with C++ you write yourself unless you are doing heavy string parsing, which Erlang does more slowly due to lack of multiple assignment. Like Python, you can code the performance related bits in C, but unlike Python, the C bits run in a supervised external process so they don't crash your program if you have a segfault in the C due to bad pointer assignment (you can actually integrate any language this way, not just C). The networking bit is all done for you and the sockets show up like little mini-processes you can monitor and send messages to/from. Because of the process model that Erlang uses, you don't have to deal with thread pooling and can handle a large number of concurrent clients in a straightforward way. There is also a cross platform gui in Erlang based on wxwidgets, but it isn't the fastest. Once I got used to it I found I could get stuff done pretty quickly.

  87. Re: C++ is never the right tool by tepples · · Score: 1

    The article explains how being garbage-collected makes V8 slow. Like V8, Dalvik is garbage-collected. What's the key difference between the two environments?

  88. Absolutely not, especially for a personal project by iamacat · · Score: 1

    Your first priority is to finish it, and make it useful to others. Start with the language you are familiar with, and that facilitates maximum portability and compile time error detection. Once you are done, there is always an option to rewrite performance critical parts in native code. With C/C++, there is always a chance of memory corruption in your own code or libraries you are using. It may never manifest on your development system, but affect other users and other platforms.

    Unless of course your primary motivation is to learn another language. Then go right ahead, but don't expect maximum productivity.

  89. Re: C++ is never the right tool by Kagetsuki · · Score: 1

    You're talking about what we would call "managed blocks" in the systems we used. We didn't have malloc even, we literally just had a block and a pointer to the head and we'd write our own new and delete functions that would just mark or unmark sections of a map.

    There are however plenty of systems that do have native new and delete that are specifically written as RTOS embedded systems. EG: ITRON which is found in a lot of automotive [sub]systems.

    Generally though most embedded systems set up their memory statically, like you pointed out. Parent poster here however is referring to a media system where some blocks (like display buffers) would be static there are probably many different modes so not a single function application and not something where one globally static map would fit all cases.

  90. Re: C++ is never the right tool by Ihlosi · · Score: 1
    Once memory is allocated in an embedded system, it cannot be de-allocated.

    Wait, you're not using the stack? ;)

    Ok, back to serious mode - I'm working on small embedded stuff, and memory is either allocated statically or it's on the stack in the form of local variables. new/delete/malloc/free don't appear in my code, either.

  91. Re:C++ is never the right tool by ImprovOmega · · Score: 1

    Java/C# = Automatic Transmission
    C/C++ = Manual Transmission
    Assembly = smelting and casting metals to create your own custom designed gearbox

    For many applications Automatic is fine. You just care about making it work and performance is "good enough" that you don't sweat it. For performance sensitive applications you need finer tuned control and yeah, the safeties are off, but they're not slowing you down either.

  92. Re:C++ is never the right tool by petermgreen · · Score: 1

    A few years ago, when I was compiling all software for my personal workstation myself (LFS) as a learning experience, I actually did that. C++ was too big a hassle for too litle gain.
    After a while during a reinstall I disabled g++ and only installed programs written in C or other languages. It was no big deal actually, opensource C++ projects feel huge and sloppy compared to the rest.

    Was it really only "a few years" or are you forgetting how long it has been (easy to do)? was this machine a fully functional workstation (including stuff like web browsers and if so which web browser)? or was it just a toy/special purpose box?

    A few years ago gcc itself switched from C to C++ https://lwn.net/Articles/54245... . Both of the two main web rendering engines (geko and webkit) are C++. One of the two main desktop widget sets is C++.

    I agree C++ has it's problems, templates look good in microbenchmarks but can easilly blow up code size. Memory requirements for linking large C++ projects can be horrific but the fact remains C++ is far more widely used and supported than any other object-orientated native-compiled language. It's position may not be quite as important as C but it's not far off.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register