SFig语言语法高效,清晰(并且优于Spring-Framework的XML DSL)吗? [英] is SFig language syntax efficient and clear (and better than Spring-Framework's XML DSL)?

查看:135
本文介绍了SFig语言语法高效,清晰(并且优于Spring-Framework的XML DSL)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附录

尚未接受对此的回答,因为 尚未收到任何反馈 经验丰富的Spring框架 开发人员.

我一直在研究替代DSL,以用于Spring-Framework applicationContext.xml文件(其中描述了bean初始化和依赖关系,以将其加载到Spring bean工厂中).

我的动机是,我完全不喜欢Spring为此目的使用XML,也不喜欢到目前为止已经设计出的任何替代方案.由于各种原因,我不想继续使用,我希望保留声明性语言,而不要使用某些命令性脚本语言,例如Groovy.

因此,我抓住了ANTLR解析器工具,并一直在设计一个我称为SFig的新bean工厂DSL.这是一个更多讨论此问题的链接:

SFig™-替代元数据配置语言用于弹簧框架

这是源代码存储库站点:

http://code.google.com/p/sfig/

我很想知道到目前为止我在语言语法上的表现.您是否认为SFig既高效又易于理解? (我现在特别关注多行文本字符串):

properties_include "classpath:application.properties";


org.apache.commons.dbcp.BasicDataSource dataSource {
    @scope = singleton;
    @destroy-method = close;
    driverClassName = "${jdbc.driverClassName}";
    url = "${jdbc.url}";
    username = "${jdbc.username}";
    password = "${jdbc.password}";
    defaultAutoCommit = true;
}


org.springframework.orm.ibatis.SqlMapClientFactoryBean sqlMapClient {
    @scope = singleton;
    @init-method = afterPropertiesSet;
    @factory-method = getObject;
    configLocation = "classpath:sqlmap-config.xml";
    dataSource = $dataSource;
}


/* this string will have Java unescape encoding applied */
STRING str = "\tA test\u0020string with \\ escaped character encodings\r\n";


/* this string will remain literal - with escape characters remaining in place */
STRING regexp = @"(\$\{([a-zA-Z][a-zA-Z0-9._]*)\})";


/* multi-line text block - equates to a java.lang.String instance */
TEXT my_multi_line_text = ///
Here is a line of text.
This is yet another. Here is a blank line:

Now picks up again.
///;


/* forward use of 'props' bean */
java.util.HashMap map {
    this( $props );
}


/* equates to a java.util.Propertis instance */
PROPERTIES props {
    "James Ward" = "Adobe Flex evangelist";
    "Stu Stern" = "Gorilla Logic - Flex Monkey test automation";
    Dilbert = "character in popular comic strip of same title";
    "App Title Display" = "Application: ${app.name}";
    "${app.desc}" = "JFig processes text-format Java configuration data";
}


/* equates to a java.util.ArrayList instance */
LIST list {
    this( ["dusty", "moldy", "${app.version}", $str] );
    [234, 9798.76, -98, .05, "numbers", $props, ["red", "green", "blue"]];
}

解决方案

我对您所引用的Spring XML并没有太多的经验,因此您应该花点儿力气听取以下反馈.

作为第二点和第三点警告:

  • 提供一段代码将对语言及其语义有何帮助.很难完全理解您已经做出的一些选择(并且有充分的理由),因此,鉴于这些选择,此处的任何反馈可能是完全矛盾或不可能的.
  • 语言设计既是一门艺术,也是一门科学,因此,在此阶段,您可能获得的任何反馈都可能是相当主观的.

一个更大的元问题:作为DSL,您正在尝试配置Spring,还是作为更通用的框架类?

那里:警告购买者.现在我的主观反馈和不完整反馈;)

  • 我不确定我理解为什么您为scopedestroy-method而不是driverClassName使用 @前缀的原因.同样, xml-case和camelCase 的混合并不是一开始就很明显. @前缀是类型修饰符,还是这些关键字在语言中?

  • 我不确定您对块头格式的意图.您有一个类名,然后是该类的一个函数;是否打算指定要用于特定功能的类?

例如

sqlMapClient: org.springframework.orm.ibatis.SqlMapClientFactoryBean {
    # body.
}

甚至:

sqlMapClient {
    @class = org.springframework.orm.ibatis.SqlMapClientFactoryBean;
    # is there a sensible (perhaps built-in) default if this is missing?
}

  • 我喜欢变量替换;我认为这些值将来自系统属性?

  • 我喜欢能够指定字符串文字(不转义),尤其是对于您显示的正则表达式.但是,具有多字符的quote或quote修饰符似乎有点陌生.我猜您考虑过单引号(shell和Perl对文字字符串使用单引号).

  • 另一方面,我认为多行TEXT 的三倍正斜杠是正确的方法,但有两个让人想起C风格语言的注释. Python为此使用了一个三元组".某些shell习惯用法有多行文本约定,我不会复制.

  • 我非常喜欢属性和配置位置的外观,使用的是 URI寻址概念.如果这是URI,则classpath://file.xml可能更清晰.但是,我在这里可能遇到了错误的情况.

  • 我也非常喜欢您拥有的列表和地图文字的概念,尽管我不确定在哪里:

    • this进入其中(我想是对Java构造函数的调用)
    • 为什么某些类型大写,而另一些则不大写.我是否认为有一个默认的MAP类型,如果您愿意,可以指定更具体的类型?
    • Dilbert是未引用的字符串文字吗?

最后,我将为您指出另一个配置DSL,尽管可能更多用于系统管理员使用: Puppet

a>.

进展顺利.

ADDENDUM EDIT:

Have not accepted an answer to this as there has not been any feedback from experienced Spring Framework developers.

I've been working on a replacement DSL to use for Spring-Framework applicationContext.xml files (where bean initialization and dependency relationships are described for loading up into the Spring bean factory).

My motivation is that I just flat out don't like Spring's use of XML for this purpose nor do I really like any of the alternatives that have been devised so far. For various reasons that I won't go into, I want to stay with a declarative language and not some imperative scripting language such as Groovy.

So I grabbed the ANTLR parser tool and have been devising a new bean factory DSL that I've dubbed SFig. Here's a link that talks more about that:

SFig™ - alternative metadata config language for Spring-Framework

And here is the source code repository site:

http://code.google.com/p/sfig/

I'm interested to know how I'm doing on the language syntax so far. Do you think SFig is both efficient and clear to understand? (I'm particularly concerned right now with the mulit-line text string):

properties_include "classpath:application.properties";


org.apache.commons.dbcp.BasicDataSource dataSource {
    @scope = singleton;
    @destroy-method = close;
    driverClassName = "${jdbc.driverClassName}";
    url = "${jdbc.url}";
    username = "${jdbc.username}";
    password = "${jdbc.password}";
    defaultAutoCommit = true;
}


org.springframework.orm.ibatis.SqlMapClientFactoryBean sqlMapClient {
    @scope = singleton;
    @init-method = afterPropertiesSet;
    @factory-method = getObject;
    configLocation = "classpath:sqlmap-config.xml";
    dataSource = $dataSource;
}


/* this string will have Java unescape encoding applied */
STRING str = "\tA test\u0020string with \\ escaped character encodings\r\n";


/* this string will remain literal - with escape characters remaining in place */
STRING regexp = @"(\$\{([a-zA-Z][a-zA-Z0-9._]*)\})";


/* multi-line text block - equates to a java.lang.String instance */
TEXT my_multi_line_text = ///
Here is a line of text.
This is yet another. Here is a blank line:

Now picks up again.
///;


/* forward use of 'props' bean */
java.util.HashMap map {
    this( $props );
}


/* equates to a java.util.Propertis instance */
PROPERTIES props {
    "James Ward" = "Adobe Flex evangelist";
    "Stu Stern" = "Gorilla Logic - Flex Monkey test automation";
    Dilbert = "character in popular comic strip of same title";
    "App Title Display" = "Application: ${app.name}";
    "${app.desc}" = "JFig processes text-format Java configuration data";
}


/* equates to a java.util.ArrayList instance */
LIST list {
    this( ["dusty", "moldy", "${app.version}", $str] );
    [234, 9798.76, -98, .05, "numbers", $props, ["red", "green", "blue"]];
}

解决方案

I haven't much experience with the Spring XML you refer, so you should take the following feedback with a pinch of salt.

As a second and third caveat:

  • providing a snippet of code will give a flavour of what the language and its semantics are. It is difficult to completely understand some of the choices you have already made (and with good reason), so any feedback here may be completely contradictory or impossible in the light of those choices.
  • language design is as much an art as a science, and so at this stage, any feedback you may get is likely to be quite subjective.

A larger, meta-, question: as a DSL are you trying to do configuration of Spring, or as a more general class of frameworks?

There: caveat emptor. Now my subjective and incomplete feedback ;)

  • I'm not sure I understand the reason why you have the @ prefix for scope and destroy-method, but not driverClassName. Also the mix of both xml-case and camelCase isn't completely apparent to start with. Is the @ prefix a type modifier, or are these keywords in the language?

  • I'm not completely sure of your intentions about the block header format. You have class name, then a function of that class; is the intention to specify what class your are going to use for a particular function?

e.g.

sqlMapClient: org.springframework.orm.ibatis.SqlMapClientFactoryBean {
    # body.
}

or even:

sqlMapClient {
    @class = org.springframework.orm.ibatis.SqlMapClientFactoryBean;
    # is there a sensible (perhaps built-in) default if this is missing?
}

  • I like the variable substitution; I presume the values will come from System properties?

  • I like being able to specify string literals (without escaping), especially for the regular expressions you've shown. However, having multi-character quote or quote modifier seems a little alien. I guess you considered the single-quote (shell and Perl use single-quotes for literal strings).

  • On the other hand, I think the triple forward slash for multi-line TEXT is the right approach, but two reminiscent of comments in C-style languages. Python uses a triple " for this purpose. Some shell idioms have a multi-line text convention I would not copy.

  • I very much like the look of properties and config location, using what looks like a URI notion of addressing. If this is a URI, classpath://file.xml may be clearer. I may have the wrong end of the stick here, however.

  • I also very much like the notion of list and map literals you have, though I'm not sure where:

    • this comes into it (I guess a call to a Java constructor)
    • why some types are capitalized, and others are not. Do I take it that there is a default MAP type, which you can be more specific type if you wish to?
    • is Dilbert an unquoted string literal?

Finally, I'd point you to another configuration DSL, though perhaps more for sysadmin usage: Puppet.

Go well.

这篇关于SFig语言语法高效,清晰(并且优于Spring-Framework的XML DSL)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆