As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I've started programming C++ and I want to start programming useful stuff.
I know that for strings, one can use std::string or char-arrays. One can also use std::vectors as well, instead of arrays.
What should one do? Reinvent the wheel, or use the built in utilities?
The point of the question is to find out what people actually do. Do people use the STL a lot or do people use char[] instead of std::string?
Reinventing the wheel can be good as a training assignment, but If you want to write useful stuff - of course use the standard library ("the built in utilities").
The standard library (as well as boost, and other libraries) is validated and optimized, and it will let you write the useful stuff much easier, so you can focus on your logic instead of reinventing the wheel.
Always use standard libraries (STLs, Boost, etc) unless there is a reason for doing otherwise (e.g STL not available on platform). These libraries are time tested for both correctness and performance
If your goal is to program useful and stable software, use the standard libraries.
If your goal is to explore a specific topic, such as strings, then reinvent the string class and learn from your mistakes.
Usse the built in utilities. They are optimized and will ensure that your code is fully portable!
Note that you should use them skillfully: vectors can be rendered WAY faster if you reserve space before using them, etc.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Say I have minimal headers like <new>, <initializer_list>, and maybe some other stuff, is it possible to use Boost to function as a std C++ library, or is there a lot of code missing?
I'm assuming a C standard library, which might have sucky versions of things like printf (think Windows), will Boost provide better implementations in <boost/cstddef> (or something)?
No. Boost is not designed to replace the C++ standard library; it is designed to complement and extend the C++ standard library. Also, Boost depends heavily on the C++ standard library.
Well, no. For example, Boost doesn't define a stream encapsulating standard out. Sure, you can use STDOUT itself with some lower-level functions, but by that logic you can do pretty much everything without using the standard library at all.
I would recommend using Boost or any other truly cross platform libraries for anything that is even remotely likely to be platform dependent. Networking / locking etc.
For everything else, I would stick to the standard libraries - they're well documented, they're often optimized for the OS and with the exception of a few ifdefs you may need to endure here and there, they'll compile and run fine on most platforms.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I know this could be seen as subjective off-the-cuff (thus a poor question), but bear with me.
Boost has recently become available on the project on which I'm working, and I don't have much experience with it. Boost has so many parts and features that it's hard to know where to get started in learning it - especially since I'll be trying to learn it while making production code.
So, I would greatly appreciate it if someone could list around 3 to 5 features which are very useful in general, every-day programming and state why they're useful. I'm not asking you which is best, or trying to get a debate - I just want to know some good features to start learning and using immediately. I don't need code samples either, I'll be more than happy to research how to use the features myself after I know which ones are sensible to start learning now.
I'll accept any answer with a concise list of features that are sensible :)
format and lexical_cast are great for string manipulation, I find them invaluable. I use them every day.
bind is great for ad hoc functors, you'll find it is reused throughout many of the boost libraries.
multi_index fills the gap of when you need the same data in two search structures at once, it is very handy at times. Keep it out of your headers though.
type_traits defines useful traits for template specializations.
signals is a signal/slot mechanism implementation, great for event driven designs.
shared_pointer is critical. It lets you automatically handle memory usage.
http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/shared_ptr.htm
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Hi I am currently working on an open source project and want to use STL in it. But I am confused that is correct to depend on STL only or it will be good to use Qt like libraries. Because I want to make it cross platform supported. Please suggest.
STL: Standard Template Library for C++
That is some confusion in this question.
STL is a part of Standard Library of C++; specifically covering containers and algorithms (and iterators, as a glue between the two).
Qt is cross-platform application framework which purpose is, first and foremost, to provide facilities for abstracting you from platform. It also covers some of functionality provided by STL (i.e. it provides its own containers: as I understand, mostly for historical reasons).
You can freely mix'n'match both libraries. AFAIK you can even use STL algorithms on Qt containers (meaning that Qt containers are STL compliant).
So, answering your question, it is of course good to use STL for new software: provided it is properly supported by your compiler, and you know how to use it.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
c or c++??
if i want to make a project on pattern recognition( artificial computing)
using c or c++
which one should i choose??
Object Oriented Programming can probably be of some help if you start programming something complex. That is possible with C but will probably be easier using C++. That said there is a risk to get lost on the multitude of features of the language if you are just learning it, and it's probably less so with C. But it's not so hard to use only a subset of C++, so definitely C++.
The most important point is that you should first focus on the problem(s) to solve before focusing on the tools you are using.
I would use something high level so you could learn about your own algorithms and not how to implement your algorithms. If you can write pattern recognition single handedly in C I applaud you. It is beyond my skill.
Perhaps Ruby or Python then implementing the computationally expensive parts in native C?
Since C++ is effectively a superset of C, there is no good reason not to use C++.
I think that is the least of your worries. C is available on more platforms, C++ has more features.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
since last four years i had been coding in c/c++, but those lenthy programs made me sick of them.
then i got to know about python, and i have learned the basics.
python seams to be more flexible and powerful than c++...
But i want to know is python realy better than c++?
if yes/no in what ways , please explain.
since i am a student , practicing which language would fetch me better job?
Python is completely different than C/C++, so it's hard to compare. Python lets you write clear, concise programs and very quickly develop software at the price of performance. It lets you be very productive and in many cases program performance is less concern, than programmer performance.
There are many existing programs for python 2.*, so it's better to stick for now with it. It would be fairly easy to move to 3.* later on.
It all depends on your needs, Python isn't replacing C/C++ in the embedded space anytime soon, and not too many web frameworks are going to be based on C/C++.
Python is neither better nor worse, or neither more or less flexible or powerful than C++. it's just aimed at a different set of problems.
I would rather students start at something like C++ so they have a better understanding of things like pointers & memory management. It's not really objects all the way down.