最近自己在写一个AJAX+WebService的个人Portal,设计的功能比较多但都很简单,无非是对N个表的CRUD操作,一些Join和一些存储过程。但写到WebService和JavaScript这块觉得有许多代码都是重复的,比如:
业务逻辑层有个AddUser方法:
UserAccess.AddUser,而这个方法实际是调用了一个更底层的DatabaseProxy.Insert<>。
然后是WebService里的方法,姑且可以把它认为是“用户接口层”,某个Service的class里又是几乎相同的方法:
UserService.AddUser,显然这个方法调用了UserAccess里的AddUser。
好,终于从Service side上浮到了浏览器里,又是JavaScript的编码,直接和用户接触的“表现层”:
function AddUser() { ....UserService.AddUser(....);... }
。。。
这些代码中除了业务逻辑层的必要的,其他的代码都是直接调用更底层的代码,一个方法往往就是2-3行,但如果继续这样写下去,数量却是很大的。于是我想可以用代码生成来生成Service和JavaScript的代码啊。。可生成代码。。。总让人觉得没有安全感。。我不想看到冗余的东西。
想到几个月前在Channel 9看的一段介绍“Codename Volta”的视频,Volta的目标似乎就是消灭这中在N层代码中的冗余:
From Web "Meijer doesn't envisage having to distribute a runtime engine such as .NET, the JVM (Java Virtual Machine) or Flash. Rather, he wants to use what is already available. Therefore he envisages .NET IL (intermediate language) binaries becoming a universally executable format. The runtime could be the CLR (Common Language Runtime), or the JVM, or the Flash player, or the browser. This would be transparent to the developer, because some intermediate piece would translate the .NET IL to JavaScript, or Java, or a Flash SWF. or somehing else." 

"You can write code that targets Silverlight, as an example, and if the target browser doesn’t support Silverlight, the code will be “converted” to a DHTML / CSS / Javascript implementation on the fly. In fact, that implementation can be tailored to the unique requirements of the browser, and functionality can be boosted or reduced depending on what that browser can handle."

原来Volta就是一个帮你生成那些客户端代码的东西,可惜它还没有一个preview版本提供试用。
觉得现在的软件开发还是有许多的不理想的地方,有许多的无用功,幸好已经有很多技术和工具已经在慢慢改变那些不足了。但愿10年后,Software Engineer已经完全是另外一个意义的工作,“代码工人”这个称呼将不复存在。。。

PS:发现Channel 9页面上的播放器改成Silverlight的了~,在我的Firefox上运行良好。~
Posted on 2007-10-02 23:22  Adrian H.  阅读(682)  评论(3编辑  收藏  举报