Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unifying enums across multiple languages

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.)

like image 492
Jonathan Swinney Avatar asked Dec 17 '10 17:12

Jonathan Swinney


2 Answers

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.

like image 84
John Avatar answered Sep 28 '22 07:09

John


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
like image 37
thejh Avatar answered Sep 28 '22 07:09

thejh