Frage

Ich habe ein großes Projekt mit Komponenten in mehreren Sprachen, dass jeder davon abhängen, einige der gleichen Enum-Werte. Welche Lösungen haben Sie kommen sich mit Unify Aufzählungen über mehrere beliebige Sprachen? Ich kann mich ein paar, aber ich bin auf der Suche nach der besten Lösung.

(In meiner Implementierung, ich bin mit PHP, Java, Javascript und SQL.)

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top