Take the 2-minute tour ×

I'm working on several distinct but related projects in different programming languages. Some of these projects need to parse filenames written by other projects, and expect a certain filename pattern.

This pattern is now hardcoded in several places and in several languages, making it a maintenance bomb. It is fairly easy to define this pattern exactly once in a given project, but what are the techniques for defining it once and for all for all projects and for all languages in use?

share|improve this question

5 Answers 5

up vote 1 down vote accepted

Creating a Domain Specific Language, then compile that into the code for each of the target languages that you are using would be the best solution (and most elegant).

Its not difficult to make a DSL - wither embed it in something (like inside Ruby since its the 'in' thing right now, or another language like LISP/Haskell...), or create a grammar from scratch (use Antlr?). It seems like the project is large, then this path is worth your while.

share|improve this answer

I'd store the pattern in a simple text file and, depending on a particular project:

  • Embed it in the source at build time (preprocessing)
  • If the above is not an option, treat it as a config file read at runtime

Edit: I assume the pattern is something no more complicated than a regex, otherwise I'd go with the DSL solution from another answer.

share|improve this answer

You could use a common script, process or web service for generating the file names (depending on your set-up).

share|improve this answer

I don't know which languages you are speaking about but most of languages can use external dynamic libraries dlls/shared objects and export common functionality from this library. For example you implement function get file name in simple c lib and use acrros rest of languages.
Another option will be to create common code dynamically as part of the build process for each language this should not be to complex.
I will suggest using dynamic link approach if feasible (you did not give enough information to determine this),since maintaining this solution will be much easier then maintaining code generation for different languages.

share|improve this answer

Put the pattern in a database - the easiest and comfortable way could be using XML database. This database will be accessible by all the projects and they will read the pattern from there

share|improve this answer

Your Answer


