Any suggestion for template base code generator for C / C++ specifically to generate repetitive code generation? (Not UML / MATLAB model based or other advanced stuff). For a newbie in this field any good generic tutorial (not tool based)?
I came across GNU Autogen looks good but looks like it needs a steep learning curve. I would prefer some plug-in for eclipse like IDE, easy to use and most importantly good tutorials.
The basic concept of code generation is simple enough - and people's needs are varied enough - that there are quite a few options out there.
Boost.Preprocessor is a library of functions built on top of the standard C / C++ preprocessor that makes it much easier to use the preprocessor to do code generation. It's not as flexible as other options, and figuring out preprocessor errors can be tricky, but the fact that it uses only standard language features greatly simplifies using it and integrating it into your builds.
If you know Python, there's Cog.
Some of Google's projects use Pump.
There are many general-purpose templating solutions (Python's Genshi, eRuby, etc.). These are often designed for generating HTML and XML but also work for code.
It's also easy enough to hack something together in the scripting language of your choice.
Without knowing more about what your needs are and what tools you're comfortable with, I can't give a more specific recommendation.
I'm not familiar with anything that provides an Eclipse plugin.
If you know Python, then Cog could be considered as light-weight solution: http://www.python.org/about/success/cog/
Look at my answer for a similar question for Java classes using M2T-JET, an eclipse based, lightweight templating generator. JET is language agnostic and you can see from the example that it's fairly easy to use.
I appreciate using Lua for this task, with something like Templet or one of another myriad of Lua-based preprocessors. The benefit of using Lua over something like Python is that you can, if necessary, include the source code to your template processor and a basic Lua installation along with whatever it is you are shipping. You may then add the compilation of Lua and subsequent template files to the build process as usual.
I would advise not using Python-based solutions for one reason: juggling various pythons to satisfy every developer's use of a completely different yet incompatible version is annoying. If you choose to use a language which you can't embed in your trees, you'll want to make sure pre-computed versions are available.
Late to the party but I would recommend Codeworker Its the only tool I found that does everything the above tools do and more. It has the Python Cog like functionality for embedded generation, it has the template based generation like Templet or Pump. And it has the rather useful feature of protected areas so you can customise your code as needed and re-generate.
I have used it for generating all the boiler plate c++ code as well as configuration for projects like SQL, config, javascript etc.
Related
So I'm currently working with a proprietary programming language that is C-like. So while this question wasn't directly inspired by a C program, I think those of you who are familiar with C may be able to offer some good insight.
I'm currently working on a library. This library encompasses some basic features as well as features that require other libraries. I'm running into the problem of 'where do I draw the line for how many dependencies are included in this library?'.
So this seems like it could be a fairly common problem. What methods exist for addressing this issue?
Something I've had in mind. Implement #defines and #ifdefs that allow users to compile the library with only the features they want. So essentially, all of the library functions that require additional libraries would be wrapped in #ifdef guards. The user would be responsible for #define'ing the features they want. Essentially, this method would allow a user to still use parts of the library without needing to have other dependent libraries.
Your thoughts? Again, this is for a C-like language. Thus tools like CMake, etc. aren't available.
Yes. If you take a look at the Linux kernel for instance, it's done the exact same way.
Yes you can and You Should.
I use them whenever i feel the necessity. Also, i have been working on freeRTOS and that's how things are being done over there.
Is there any recommendations for how to show what your code is doing (C or MATLAB)? Imagine if your code is really long and you have a lot of functions in your program, what is the best way to document the program? I know Java IDEs have a way to ingest comments and spit them back out into a document that shows all the functions, and their inputs and outputs. I don't think C or MATLAB has this feature. At this point, I am thinking comments are the only way to show what is going on in the code, but it may confuse the reader if they have to look through the raw code along side the comments. The second option would be to write out the algorithm in a text editor such as Microsoft Word. Is there an industry standard for doing this?
Thanks!
What Java uses is JavaDoc.
For C, you can use Doxygen.
I also saw this which suggests you can use Doxygen with matlab too!
The mother of all literate programming is http://www-cs-faculty.stanford.edu/~uno/cweb.html
cweb. The father is Knuth.
Recent versions of MATLAB actually do have some features very similar to this. If you implement your MATLAB code in object-oriented classes, MATLAB will auto-generate documentation for you by just typing doc myClassName - it's really quite similar to Doxygen. If you're not using object-oriented code, you can use MATLAB publishing to generate a document from your scripts and functions.
Doxygen's C support is quite good. It supports JavaDoc style and Qt style markup comments, as well as some additional features. See the manual for examples of what the markup looks like. I don't have an example of the output ready to hand, but it's quite customizable.
The Octave project, which implements a language and environment that's effectively a superset Matlab's, uses texinfo to document its functions. You can see an example of the markup in the Documentation Tips section of the manual. I recommend scrolling to the bottom of the page to view a complete markup example rather than reading the lengthy explanation that precedes it. I have little experience with texinfo beyond using help from within Octave, but I believe the online manual was generated from texinfo sources, so it seems sufficiently capable.
The software's algorithms are all written in C.(gcc compiler). And I need some beautiful and friendly UI for this small software...But I have no idea what language and what library and what tool I should use.
I need some idea from you guys. thanks indeed!
If you can say it more specific, I will thank you more!
It would be better if you are more specific with your question and give more details about your software. Because designing a UI interface depends on a lot of factors.
I am listing some below for your reference:
On what system are people going to use it? (Windows, Linux etc)
Users are novice users or advanced users (You can decide on a CLI for advanced users and more detailed colourful GUI for novice users who need a lot of help)
Do you have any specific requirements like the GUI should be light weight?
So, please determine the requirements first before deciding what language and what library you must use.
For starters, you can look at ncurses library in linux, MFC in Windows. I don't know much about Java, someone else must be able to help you on that.
All the best for your work!
Commonly used libraries for GUIs:
Tk which was written in Tcl and has bindings for Python, Perl, Ruby, Lisp and a few others
GTK, which is written in C (so you could write your GUI in C) and has bindings for most languages under the sun
Qt, which is written in C++ and also has a number of bindings
These are the "big three" for cross-platform toolkits (I know some will disagree). They have their advantages and disadvantages: Tk looks good on some platforms but not others, and there aren't too many bindings for it, GTK looks great on Gnome desktops but so-so elsewhere, and Qt looks good in KDE but okay elsewhere.
You have to ask yourself a few questions: what platform will you be deploying to? What kind of functionality do you need? What languages are you most comfortable writing the interface with?
I'd recommend that whatever language you choose, choose a scripting language of some sort. It's far easier to create interfaces using scripting languages IMO (though Qt makes C++ interface design fairly painless). I'd also recommend you pick a language that will be available on your platform with as few dependencies as possible (so for Linux, Python or Perl would be a good choice).
Having just found out that you can use Ruby or Python inside a SilverLight application..
link here
..I wonder if its possible to bypass some of the SilverLight limitations with use of these languages instead of C#.
I know that the Ruby Engine inside the SilverLight application is trimmed down, just as the .NET CLR is, so I would like to know that even without all the functionality of a full Ruby or Python Engine:
Can I still be able to do something
with the use of these dynamic
languages that I wouldn't be able to do
in C# SilverLight?
.
If we need to download something built
by the community to extend the cut
down Ruby implementation (to support
Interop calls for instance?), what's
the impact on deployment?
.
If not, if you cannot do anything
you wouldn't be able to with c#, with these engines, besides
the typical benefit of a dynamic
language, and not really circumventing
some of the restrictions of the
SilverLight's CLR, why would one
choose to use Ruby in a SilverLight
application?
One of my interest points is use of sockets, socket usage in SilverLight is improving in each version, but it can still be troublesome because of the xml authorization file required on the server side..would ruby be able to make this unnecessary?
Thanks,
Ric
I suspect you won't be able to work around that. Keep in mind that it's not the language imposing the limitations here but the runtime. TO be precise, it's Silverlight itself. Since both C# and Ruby are compiled to CIL in this case you're left with more or less the exact same capabilities (except some differences in the typing system).
I'm not sure what you're getting at. Regardless of language you are still running inside the same "sandbox", security model and limited with the same cutdown libraries in Silverlight. You can extend the bits that you feel are "limited", assuming your code doesn't violate the security model, with any language.
You might be able to do things differently using another language, but the same basic constraints still apply.
You need to make sure the files are included in the xap or use the silverlight 3 slvx system to stream the assemblies defined in C# or VB etc.
The ruby language should be a complete ruby implementation so you can use all the language features ruby offers like metaprogramming etc.
All source files need to be included in the xap to work.
If you're using ruby then you get gestalt too and you can include ruby source files in the same way as you include javascript files in an html page today.
One of the best scenario for the usage of dynamic languages in .NET is to let the users extend the application with their own code, so that's the main reason I use IronPython in my Silverlight application. It's so nice to have that available in the limited .NET runtime of Silverlight. It's really easy to integrate (although I had a hard time making C# extension methods visible to Python) and it can be very powerful for the users.
I have a library written in C that I would like to use in an Objective-C app, either on the Mac or the iPhone.
Unfortunately, since this library is being written by individuals in the open source space, the documentation is quite sparse and incomplete. While I can figure out how to use the stuff in the library, I don't really have an overview of the entire code base.
What I would like to do is wrap the library up into some easily usable and transferrable classes in Objective-C.
Does anyone have any tips on how to approach this?
Any advice on the best way to get a visual hierarchy of how the library is structured?
How would I go about deciding how to best structure the wrapper for reusability and ease of use?
Any and all help will be greatly appreciated, thanks!
I've done this a few times myself. This can be fun -- it's your chance to fix (or at least hide) bad code!
You can use Doxygen to get a visual hierarchy of the code (although I've only used it for C++ libraries, it also works with C), or any of the other free tools out there.
Don't structure your wrapper class like the underlying library if the library isn't designed or documented well. This is your chance to consider the point of view of the user and how they are going to be using the code. Write your test cases first to figure that out, and/or talk to some people who use the library already.
Two nice design patterns that match up with what you're doing are Adapter and Facade.
First, remember: a C library is an Objective-C library. You don't actually need to do any wrapping at all, although you may want to if the library interface is especially cumbersome.
Second, if you decide that you want to write a library wrapper, keep it simple. Identify the core functions of the library that you actually plan to use, and think about how best to provide an interface to those functions and those functions only, with your intended usage in mind. Design an interface that you want to work with, then implement it over the library.
Since ARC (Automatic Reference Counting) was added to the Apple compilers and libraries, Objective-C and C are no longer so freely interchangeable. (Here's a list of ARC documentation and tutorials.) You need to consider the memory allocation issues much more thoroughly, and you might just want to "bridge" the libraries. See this SO question and some of the links from there, about how Apple bridges between Obj-C and C libraries.