Question

I have one large project with components in multiple languages that each depend on some of the same enum values. What solutions have you come up with to unify enums across multiple arbitrary languages? I can think of a few, but I'm looking for the best solution.

(In my implementation, I'm using Php, Java, Javascript, and SQL.)

Was it helpful?

Solution

You can put all of the enums in a text file, then use a code generator to write out the appropriate syntax for each language from that common file so that each component has the enums. Make that text file the authoritative source of information.

You can express the text file in XML but I'd think a tab-delimited flat file would work just fine.

OTHER TIPS

Make them in a format that every language can understand or has a library for. I am using JSON for this at the moment.

Then you can include it with two ways:

  • For development: Load it from a file/URL at runtime
    • good for small changes you want too see immediately
    • slow
  • For productive usage: Include it in the files
    • using a build script
    • fast
    • no instant feedback

I would apply the dry principle and using code generator as such you could add anew language easely even if it has not enum natively existing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top