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 9 years ago.
It's a simple task, let me briefly describe it!
I'm supposed to code a command-line tool that takes a file-name as an argument, the file
that I'm gonna read consists of lines, each line supposed to be a command to execute, the command is followed by it's appropriate arguments to apply on, to make it clear:
FILE
sum; 1, 2, 3, 4
Output
10
The command-line tool should satisfy those requirements:
1- Easily maintained, developed (more commands might be added in the future) and user-friendly.
2- Command line arguments might be modified and new could be added.
3- Can live as an open-source project, an organised source-tree.
I'm expecting developers to deal with the source-code and fairly understand it.
I'm a newbie in those stuff, I'm kinda new to design patterns so I don't know much, I wanna follow the best practices in developing this program, I really wanna use design patterns if applicable and make my code better and cleaner, so please advise and guide me to write this tool in the best possible way, I don't wanna write dirty code, I wanna write a high-quality code that does what it's intended to and could be easily developed further.
Please advise and feel free to criticize what I've just said.
One last thing, I'll be using C++!
Thanks!
1- Boost.Program_options is your friend when it comes to parsing command line options.
2- Take a look at the command pattern. Although it is easier to implement in language that has reflection facilities, it is still possible to have a map of "command strings" mapped to function. Please use C++11 facilities for this. i.e. std::function.
3- There is no standard structure for C++ projects. Personally, I use Boost's recommended structure.
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 9 years ago.
Does embedding c++ code in python using ctypes, boost.python, etc make your python application faster?
Suppose I am making an application in pygtk and I need some functions which need to be fast. So if I use c++ for certain tasks in my application will it be beneficial?
And what are other options to make python code faster?
Rewriting performance-critical parts of your code in C++ could be one option. To do this effectively, you first need to understand where the bottlenecks are. The best way to do this is probably to write everything in pure Python first, and then profile.
Another option might be to use PyPy.
Finally, if you find that the bottleneck is numerical computations, then NumPy is worth a look.
It is worth noting that if, for example, it turns out that your code is I/O-bound, then none of the above options are going to be of much help.
It depends, there's not a definitive answer. If you write bad code in C++ it could be even slower than well written Python code.
Assuming that you can write good quality C++ code, you can expect speedups up to 20x in the performance critical parts.
As the other answer says, NumPy is a good option for numerical bottlenecks (if you think in matrix operations rather than loops!); and SciPy comes with weaver, that allows you to embed inline C++ and other goodies.
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.
I'm doing a software to generate animations for algorithms. These algorithms are written in an interpreted language, near to C (more or less a C-oriented pseudocode). Thus, my program must interprets algorithms written in these language. Also, this language will be incremented all the time to support more and more features. The key issue here is to search an library allowing increase the language easily and making easy integrate different parsers in the same program. The app is written in C++ licensed under GPL.
A object-oriented parser is my target solution indeed. I need help to choose a good library with this purposes. Also it's desirable the library is multiplataform and available in official repositories of commons distributions: Ubuntu, Suse and so on.
Actually, I know more or less well the next two libraries/tools:
Flex/Bison++: Both are Flex/Bison wrappers that allow generate C++ code instead of C code, and choose a name for your class. Problems: if you install Flex/Bison++, Flex/Bison are overwritten. I don't want to complicate users if they want compile my code. Moreover, CMake fails search the version number of the library. This can be solved manually, but isn't elegant.
Boost.Spirit: It doesn't have the previous problems and match with all desirable features I described above. But, I've read it isn't fine to parse big languages and to solve grammar ambiguities. Moreover, the compilation times are enormous. But, I love it can compose grammars in a constructive manner. This is very important to make the code/language/programm extensible.
What is your recommendation?
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.
I have some XML files that contain different function information. I am trying to create a tool that may extract that information from these files once they are created (function name, arguments number, type, returned values, etc.)
Later i will be manipulating these extracted information to create a new XML file. I have limited programming experience and it's all in C++. Any hint for the start would be appreciated.
If you just want to be able to read and write XML files, its probably just best to use an XML library rather than reinventing the wheel.
Since its not completely clear what you're trying to do, a good place to start would be this thread: What is the best open XML parser for C++? [Stack Overflow]
It's currently closed but it has a couple good answers that will help you figure out the best library to use for your situation.
If you need more help using it, feel free to edit your question, comment, or post a more specific question on the topic.
Happy coding and good luck!
I would suggest TinyXML, it's small, light-weight and suitable in many cases, it also has a non-viral license.
I used it a lot and it was very useful and ... just in case, there's also TinyXPath.
Unless you are doing this as a project to improve your C++ ability and understanding of XML, I would advise against trying to write the parsing code yourself. You will get much faster results using something out there that is already written and well established and there are a number of choices that are open to you. I personally like RapidXML. It is very simple to add to your code (you just need to #include one or two .hpp files - no libraries are needed) and it does everything that I have needed so far which is mainly parsing data from SOAP responses. The site also provides a comprehensive tutorial which enables you to get up and running very quickly.
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.
This question may seem to be naive.
But I think it'll be much worse if I don't ask it at all.
When a discussion begins about the features of Python that the developers love the most, they usually mention list comprehension, syntax relying on indentation (thus avoiding brackets, etc.) and some other.
At such moments I ask myself a question why there can't be made a language based on C++ but having a syntax like in Python and having all the features like list comprehensions, generators.
I understand that such a language won't have all the features that Python has, e.g. eval or exac statements (because they rely on Python being an interpreting language), may be some others that I don't know of.
But I also know that there is a project called Shedskin which makes a C code of a Python code (with some restrictions on what can be used in Python code).
So, are there some real reasons why it's impossible to create such a language that will combine all the best features of Python and a very fast code that produces C++? Or it's just the turn of events that Python for some reasons became very popular and it turned out to be interpreted, so a lot of people use it for its greatest features still discontent at the speed of the code, and some of them struggle to create something (like Shedskin or Psyco) to speed it up?
Google as created a language called Golang ( or Go). It is a compiled language with python like syntaxe. There are alot of video and documenttation that will answer your question there.
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