我正在浏览 mochiweb 源代码,并看到一些我以前从未使用过的东西。模块声明,特别是在 mochiweb http 库中找到的 mochiweb_request
和 mochiweb_response
模块中。以下是该模块的开始方式:
-module(mochiweb_request,[Socket, Method, RawPath, Version, Headers]).
-author(...).
然后在模块中您会看到 get(socket) -> Socket;get(方法)->方法; ....
这让我很困惑。当我尝试获取其中一个此类模块的模块信息时,编译器在返回中添加了一些内容:{abstract,true}
:
mochiweb_request:module_info()。
。事实上,他们的文档将这些模块称为“抽象模块”。
我搜索了谷歌,发现了一篇关于参数化模块的论文:链接太大了,但我相信如果你按照 这里
这些模块不能直接调用而是调用通过他们自己的实例。它使模块的行为就像它们很有趣一样。我开始意识到这是运行时系统中的一个非官方功能。让我困惑的是 mochiweb 的人用得很好!在 mochiweb 模块中,您会发现自己编写:
loop(Req,_DocRoot)->
"/" ++ Path = Req:get_path(),
Body = Req:recv_body(),
Method = Req:get(method),
...,
....,
Response = Req:ok({"text.html;charset=utf-8",[],chunked}),
Response:write_chunk("Some text here....."),
...
尝试 io:format("\n\t Req = ~p~n",[Req])
揭示了一个复杂的数据结构(一个元组) ),其中 element(1,Req) == mochiweb_request
。很有趣!?!!!?
问题 1 是:目前在生产中使用是否稳定,或者我可以等到它正式发布吗?
问题 2 是:如果尚未正式发布,mochiweb 人员如何获得使用它的信心?
问题3:为什么还没有正式发布? (因为,对我来说,它带来了一些面向对象的功能)
问题4:请问有人用过吗?他/她在哪些情况下使用了这些参数化模块?为什么?您能否指出我们在那里查看或发布一些源代码的链接,以便我们可以了解有关此功能的更多信息?
最后一个问题:我在 Erlang 文档中没有找到任何谈到此功能的地方。没有教科书,甚至没有家。那么那些已经使用过它的人是如何知道如何以及为什么使用它的呢?它是否已包含在 此处 的 Erlang 运行时系统的商业版本中?
I was going through mochiweb source code and got to see something i never used before. The module declaration especially in mochiweb_request
and mochiweb_response
modules found in the mochiweb http library. Here is how the module begins:
-module(mochiweb_request,[Socket, Method, RawPath, Version, Headers]).
-author(...).
Then in the module you see get(socket) -> Socket;get(method)-> Method; ....
This has confused me. When i tried getting the module info of one of these such module, the compiler had added something: {abstract,true}
in the return to:
mochiweb_request:module_info().
. Infact, their documentation refers to these modules as abstract modules
.
I have searched google and found a paper on parameterised modules: the link is so big but am sure you will get the paper if u follow on here
These modules cannot be called directly but are called through instances of them selves. It makes modules behave as though they were funs. I have come to realise that its an unofficial feature in the runtime system. What confuses me is that the mochiweb guys are using it well!. In a mochiweb module, you will find your self writing:
loop(Req,_DocRoot)->
"/" ++ Path = Req:get_path(),
Body = Req:recv_body(),
Method = Req:get(method),
...,
....,
Response = Req:ok({"text.html;charset=utf-8",[],chunked}),
Response:write_chunk("Some text here....."),
...
Trying to io:format("\n\t Req = ~p~n",[Req])
reveales a complex data structure (a tuple) whose element(1,Req) == mochiweb_request
. It is interesting!?!!!?
Question 1 is: Is it stable to use in production for now or i can wait till it is made official?
Question 2 is: How did the mochiweb guys get the confidence of using it, if it is not yet official?
Question 3: Why is it not yet official? (because, to me, it brings some Object Oriented features in)
Question 4: Is there anyone out there who has used it also? In which cases has he/she used these parameterised modules? Why? Can you point us there to see or post a link to some source code so we can find out more on this feature?
Last Question: No where in the Erlang Docs have i found this feature talked about. No text book, Not even home. So how did those who have used it already find out how and why to use it? Has it already been included in the commercial version of the Erlang Run time system found here?
发布评论
评论(2)
问题1是:目前在生产中使用是否稳定,或者我可以等到它正式发布吗?
它在 R16B 中被删除。来自自述文件:
问题 2 是:mochiweb 人员是如何获得如果尚未正式发布,您是否有信心使用它?
不过,从 2.4.0 版本开始,参数化模块的使用已从 Mochiweb 中删除对以前的参数化模块的调用看起来仍然相同,
因为保留参数化模块(元组模块)的实现机制是为了向后兼容。即使在 Erlang/OTP 21.0:Mochiweb 现在对此类类型使用
tuple_calls
编译器选项代码以继续工作。问题3:为什么还没有正式发布? (因为,对我来说,它带来了一些面向对象的功能)
来自 技术委员会决定宣布参数化模块结束,日期为 2012 年 10 月 16 日:
Question 1 is: Is it stable to use in production for now or i can wait till it is made official?
It was removed in R16B. From the README:
Question 2 is: How did the mochiweb guys get the confidence of using it, if it is not yet official?
Use of parameterised modules has been removed from Mochiweb, starting from release 2.4.0, though calls to formerly parameterised modules still look the same,
as the implementation mechanism for parameterised modules (tuple modules) is kept for backwards compatibility.even though support for tuple calls were removed from the compiler in Erlang/OTP 21.0:Mochiweb now uses the
tuple_calls
compiler option for this type of code to keep working.Question 3: Why is it not yet official? (because, to me, it brings some Object Oriented features in)
From the Technical Board decision announcing the end of parameterised modules dated 16 Oct 2012:
问题1是:目前在生产中使用是否稳定,或者我可以等到它正式发布吗?
它对于生产使用非常稳定,并且已经存在了一段时间了。它不是官方标准的一部分。
问题 2 是:如果尚未正式发布,mochiweb 人员如何获得使用它的信心?
你必须向 mochiweb 的人询问这个问题。也许他们相信,如果它被拉动,他们可以很快改变它。
问题3:为什么还没有正式发布? (因为,对我来说,它带来了一些面向对象的功能)
因为它充满了争议。目前还不清楚它给语言带来了什么好处以及它如何使事情变得更容易,因此 P.Modules 有它的支持者和反对者。因此,目前的观点是它是实现的一部分,因此人们可以使用它,看看他们是否觉得它使他们的代码更易于阅读和编写。非官方性意味着它可以在不被弃用的情况下被拉动,而且似乎 Erlang 人保留了这一权利。
个人偏见:我有点喜欢它,但我永远不会使用它来将 OOP 功能引入 Erlang。 OOP 是一个丑陋的垃圾庞然大物,在编程中永远没有地位。只是痛苦会困扰你的程序,直到它们彻底腐烂,像僵尸一样走来走去,发疯。此时唯一的解决办法就是霰弹枪。相反,我想将它用作 ML 风格的函子——它更加静态,因为我觉得它更符合 Erlang 的习惯用法。
最后一个问题:我在 Erlang 文档中没有找到任何谈到此功能的地方。没有课本,甚至没有家。那么那些已经使用过它的人是如何知道如何以及为什么使用它的呢?它是否已包含在此处找到的 Erlang 运行时系统的商业版本中?
作者在几年前的 Erlang 会议上介绍了这个东西。此后一直是口碑相传等相结合的方式。
Question 1 is: Is it stable to use in production for now or i can wait till it is made official?
It is very stable for production use and has been for some time now. It is not part of the official standard.
Question 2 is: How did the mochiweb guys get the confidence of using it, if it is not yet official?
You will have to ask the mochiweb guys for this. Perhaps they believe they can quickly change it if it was pulled.
Question 3: Why is it not yet official? (because, to me, it brings some Object Oriented features in)
Because it is littered with controversy. It is not clear what benefits it bring to the language and how it makes stuff easier to do, so P. Modules have its proponents and opponents. Hence, the current standpoint is that it is part of the implementation, so people can play with it and see if they feel it makes their code easier to read and write. The non-officiality means it can be pulled without deprecation though, and it seems as if the Erlang guys reserve that right.
personal bias: I kind-of like it, but I won't ever be using it for getting OOP-features into Erlang. OOP is an ugly behemoth of utter crap that has no place in programming ever. It is just misery that will haunt your programs until they are rotten to the core, walking around like zombies and being mad. The only solution at that point is the shotgun. Rather, I'd like to use it as ML-style functors - which is more static in I feel it matches the idioms of Erlang better.
Last Question: No where in the Erlang Docs have i found this feature talked about. No text book, Not even home. So how did those who have used it already find out how and why to use it? Has it already been included in the commercial version of the Erlang Run time system found here?
The author presented the thing at an Erlang conference some years ago. Since then it has been a combination of word-of-mouth and so on.