Unifying enums across multiple languages
Asked Answered
C

3

7

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

Carhart answered 17/12, 2010 at 17:6 Comment(0)
B
5

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.

Byzantium answered 17/12, 2010 at 17:11 Comment(0)
A
3

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
Atelectasis answered 17/12, 2010 at 17:11 Comment(0)
E
1

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.

External answered 17/12, 2010 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.