Ask Slashdot: Is C++ the Right Tool For This Project? 296
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.
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.
python with psutil (Score:3, Interesting)
Re:python with psutil (Score:5, 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.
Re:python with psutil (Score:4, Insightful)
http://www.numpy.org/ [numpy.org] can give you compact arrays of unboxed types and fast operations over them.
http://cython.org/ [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.
If you do go with C++ (Score:5, Informative)
Re:If you do go with C++ (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.
Re: (Score:3)
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.
Re:If you do go with C++ (Score:5, Insightful)
it would seem to match his requirements nicely.
We don't even know what his requirements are!
Re:If you do go with C++ (Score:5, Interesting)
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... [open-std.org]
Re:If you do go with C++ (Score:5, Informative)
Re: (Score:2)
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).
Re: (Score:3)
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 z
Re: (Score:3)
Re: (Score:2)
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.
Re:If you do go with C++ (Score:5, 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.
Re: (Score:2)
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
Re: (Score:2)
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
Re: (Score:2)
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
Not enough information. (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.
Re: (Score:2)
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
Re: (Score:2)
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...
C or C++ (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.
Re: (Score:3)
If you cannot answer your own question.. (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.
Re: (Score:3)
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 b
Re:If you cannot answer your own question.. (Score:5, 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?
Re: (Score:3)
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.
Re:If you cannot answer your own question.. (Score:5, 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).
Re: (Score:2)
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 th
Re: (Score:2)
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
Re: (Score:2)
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
Re: (Score:2)
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.
What else do you need? (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/ [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.
Re: (Score:3)
Re: (Score:3)
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 hi
Contradiction ... (Score:2)
You can pick one of the two and make no promises about the other.
Or does "cross-platform" in this context mean "Linux+Windows"?
Re: (Score:2)
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.
Perl, bootstrap C++ (Score:2, 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.
Re: (Score:3)
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 headac
Plain ol' C might a better option (Score:2, 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.
Re: (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.
Re: (Score:3)
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?
Re: (Score:2)
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.
Re: (Score:2)
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.
Re: (Score:2)
Objects are very useful, but I'd say the main benefit is the template system which underlies the STL.
Re: (Score:3)
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. Th
C++ with Java for networking (Score:4, 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.
Re:C++ with Java for networking (Score:5, 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++.
Wrong setup (Score:2)
'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.
Re: (Score:2)
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.
Why not? (Score:4, 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.
Re: (Score:2)
Qt works great for C++ GUIs.
Not Yet (Score:2)
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 a
Tools and architecture (Score:2)
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 en
Re: (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 [olivierlanglois.net]
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 bloat
Re: (Score:2)
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.
Why? (Score:4, 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)
Re: (Score:2)
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/ [xyproblem.info]
Rule of thumb (Score:3)
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.
No. (Score:4, 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.
Use one language (Score:5, 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.
Cython (Score:2)
ASIO (Score:3)
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.
Re: (Score:2)
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,
Re: (Score:2)
Oh, woops. This was supposed to be a reply to the post directly below yours. Sorry, my bad!
Bigger Question: Does Language Matter Anymore? (Score:2)
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?
No mention of COBOL? (Score:2)
It's not the worst. And: It depends. (Score:2)
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
C++ is great if you don't abuse it. (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 fo
Have you actually demonstrated you need C++ yet? (Score:2)
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 p
You say you have to manage the memory, Yes? Maybe? (Score:2)
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
Re:C++ is never the right tool (Score:5, Funny)
Can you hear it, my son? This is the voice of ignorance.
Re:C++ is never the right tool (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:
Oh... good luck!
Re: (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.
Re:C++ is never the right tool (Score:5, 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
Re: (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.
Re: (Score:2)
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.
Re: (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?
Re: (Score:2)
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.
Re: C++ is never the right tool (Score:5, Insightful)
Re: (Score:2)
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.
Re: C++ is never the right tool (Score:5, 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.
Re: C++ is never the right tool (Score:5, 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.
Re: (Score:3)
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.
Re: (Score:2)
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 c
Re: (Score:2)
Just an infinite tape then?
Re: (Score:3)
Re: C++ is never the right tool (Score:5, 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.
Re: C++ is never the right tool (Score:4, Informative)
Re:There is no perfect lang (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.
Re: (Score:3)
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 p
Re: (Score:2)
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.
Re: (Score:2)
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.
Re: (Score:2)
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.
Re: (Score:2)
Re: (Score:2)
"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.
Re: (Score:2)
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.
Re: (Score:2)
Re: (Score:2)
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.
Re: (Score:2)
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.
Re: (Score:2)
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.