Koin中的DSL有什么用?
What is the use of DSL in Koin?
在 dagger 2 中,我们在编译时生成了代码。
根据 Koin library website,Koin 不进行任何代码生成并且是 "DSL, a lightweight container and a pragmatic API".
After reading Martin Fowlers Blog regarding DSL,
在我看来,DSL 可以生成代码,或者在 运行 时间进行解释。
来自马丁斯的文章:
DSLs can be implemented either by interpretation or code generation. Interpretation (reading in the DSL script and executing it at run time) is usually easiest, but code-generation is sometimes essential. Usually the generated code is itself a high level language, such as Java or C.
但是如果 Koin 没有生成任何代码,Koin 是否在 运行 时被解释?
这是否意味着 Koin 带有某种解析器?正如我所看到的,没有解析器,那么是否意味着 Kotlin 本身就是解析器?
谢谢
有内部和外部 DSL。引用 Fowler:
DSLs come in two main forms: external and internal. An external DSL is a language that's parsed independently of the host general purpose language: good examples include regular expressions and CSS. External DSLs have a strong tradition in the Unix community. Internal DSLs are a particular form of API in a host general purpose language, often referred to as a fluent interface. The way mocking libraries, such as JMock, define expectations for tests are good examples of this, as are many of the mechanisms used by Ruby on Rails. Internal DSLs also have a long tradition of usage, particularly in the Lisp community.
外部 DSL(有时,并非总是)涉及代码生成; Koin 是一种内部 DSL,但它不是。
Following Martin Fowler's blog https://martinfowler.com/bliki/DomainSpecificLanguage.html He says that DSL's can either be converted to code(code generation). Or it can be interpreted at run time.
这是外部 DSL 的两个选项。
If I understand you right, it means Koin DSL is simply Kotlin
是的。
written differently, interpreted at runtime.
没有。它只是 Kotlin,使用 Kotlin 编译器编译。内部 DSL 和库之间没有主要区别;如果它使您的代码具有足够的可读性,则可以将其视为 DSL。
在 dagger 2 中,我们在编译时生成了代码。 根据 Koin library website,Koin 不进行任何代码生成并且是 "DSL, a lightweight container and a pragmatic API".
After reading Martin Fowlers Blog regarding DSL, 在我看来,DSL 可以生成代码,或者在 运行 时间进行解释。
来自马丁斯的文章:
DSLs can be implemented either by interpretation or code generation. Interpretation (reading in the DSL script and executing it at run time) is usually easiest, but code-generation is sometimes essential. Usually the generated code is itself a high level language, such as Java or C.
但是如果 Koin 没有生成任何代码,Koin 是否在 运行 时被解释? 这是否意味着 Koin 带有某种解析器?正如我所看到的,没有解析器,那么是否意味着 Kotlin 本身就是解析器?
谢谢
有内部和外部 DSL。引用 Fowler:
DSLs come in two main forms: external and internal. An external DSL is a language that's parsed independently of the host general purpose language: good examples include regular expressions and CSS. External DSLs have a strong tradition in the Unix community. Internal DSLs are a particular form of API in a host general purpose language, often referred to as a fluent interface. The way mocking libraries, such as JMock, define expectations for tests are good examples of this, as are many of the mechanisms used by Ruby on Rails. Internal DSLs also have a long tradition of usage, particularly in the Lisp community.
外部 DSL(有时,并非总是)涉及代码生成; Koin 是一种内部 DSL,但它不是。
Following Martin Fowler's blog https://martinfowler.com/bliki/DomainSpecificLanguage.html He says that DSL's can either be converted to code(code generation). Or it can be interpreted at run time.
这是外部 DSL 的两个选项。
If I understand you right, it means Koin DSL is simply Kotlin
是的。
written differently, interpreted at runtime.
没有。它只是 Kotlin,使用 Kotlin 编译器编译。内部 DSL 和库之间没有主要区别;如果它使您的代码具有足够的可读性,则可以将其视为 DSL。