创建域的多语言版本的最佳方法是什么?
我想创建一组多种语言的域对象,以便我可以针对不同的平台。我一直在将外部 DSL 视为一种为我的领域定义语言的方法,然后可能编写适配器来为我感兴趣的目标语言生成代码。这是解决这个问题的最好方法吗?或者维护项目的多个版本是否更简单?
I would like to create a set of domain objects in multiple languages, so that I can target different platforms. I have been looking at external DSLs as a way to define a language for my domain, and then potentially writing adapters that generate code for the languages I'm interested in targeting. Is this the best way to solve this problem? Or is it just simpler to maintain multiple versions of the project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为 Apache Thrift 可以满足您的要求。
I think that Apache Thrift delivers what you are asking for.
很抱歉回答晚了,但正如您提到 C# 是您的主要语言一样,这种几乎完全支持基于 Visual Studio 的技术正是您所寻找的。
您必须了解您想要用 DSL 抽象什么,但除此之外,多平台支持是微不足道的。
免责声明:这是我们的技术,但它是公开开放的,并且它完全解决了问题中提出的问题。
http://abstraction.codeplex.com/
注意!请注意当前下载的“alpha”阶段,我建议您跳过压缩下载并获取最新的源代码。我将在不久的将来更新更好的构造。查看“Production/Dev/AbstractionTemplate”解决方案中的“Context”实现。
Sorry for late answer, but as you mention C# being your main language, this practically fully supported Visual Studio based technology is exactly what you are looking for.
You have to understand what you want to abstract with your DSLs, but the multiple-platform support is trivial on top of that.
Disclaimer: This is our technology, but it's publicly open and it solves exactly the problem presented in the question.
http://abstraction.codeplex.com/
Note! Mind the very "alpha" stage of the current download, I suggest you skip the zipped download and grab the latest source. I am updating better construct in relatively near future. Check out the "Context" implementation in "Production/Dev/AbstractionTemplate" solution.
如果不了解您打算使用 DSL 做什么,就很难提供帮助。
可移植性是您的主要问题吗?
为了成功地针对这些不同的平台,您可能必须无论如何维护特定于平台的层(无论是否生成)。
如果您计划在 DSL 中编写整个应用程序,然后使用您自己的编译器将其转换为每个平台的可运行代码,那么这很可能是一个坏主意,因为太复杂且过度设计。
然而,如果您有一个定义良好的独立于平台的逻辑块,那么 DSL 是一个不错的选择。只需在每个目标平台上为其编写一个解释器即可(假设性能并不关键,这也比生成代码更简单、更容易)。
It is difficult to be helpful without understanding what you are planning to use your DSL for.
Is portability your main problem here?
To succesfully target these different platforms, you will probably have to maintain plaftorm-specific layers anyway (generated or not).
If you plan to write your whole application in your DSL, then use your own compiler to transform it into runnable code for each platform, well it is most probably a bad idea, too complex and overengineered.
However, if you have a well-defined chunk of platform-independent logic, then a DSL is a good choice. Just write an interpreter for it on each target platform (provided that performance is not critical, this is also simpler and easier than generating code).
这就是(曾经是?)模型驱动架构 (MDA) 的想法。引用维基百科的模型驱动架构:
根据您的域的复杂性和 MDA 工具的可用性,这可能是一个选项(实施成本较低)。
另请参阅
This is (was?) somehow the idea of Model Driven Architecture (MDA). Quoting Model-driven architecture from Wikipedia:
Depending on the complexity of your domain and the availability of a MDA Tool, this might be an option (with a lower implementation cost).
See also