文号
t48589
阅读
4753
回复
11
收藏
4
【分享】Ruby元编程资料
2012/07/28
IP:山东
里边全是英文版,英文不好的童鞋请使用金山词霸(Windows)或StarDict星际译王(Linux)或直接搜索中文版pdf,仅供学习用途

Ruby入门:Beginning Ruby: From Novice to Professional  中文名:Ruby从入门到精通

attachment icon Beginning Ruby.pdf 7.75MB PDF 147次下载 预览

书中全部源代码:

attachment icon ruby-sources-Begining_Ruby.zip 191.58KB ZIP 38次下载

中文版传不上来,请直接搜索“Ruby从入门到精通 pdf”

Ruby元编程:Metaprogramming Ruby 中文名:Ruby元编程

attachment icon Metaprogramming Ruby.pdf 5.69MB PDF 147次下载 预览
+10
科创币
jrcsh
2012/07/28
高质量发帖
+20
科创币
.........
2012/07/28
高质量发帖
+100
科创币
phpskycn
2012/07/29
据说大神不太缺KCB。。。
acmilan作者
14年5个月前IP:未同步
428609
1楼
【转】元编程简介

元编程是指某类计算机程序的编写,这类计算机程序编写或者操纵其它程序(或者自身)作为它们的数据,或者在运行时完成部分本应在编译时完成的工作。多数情况下,与手工编写全部代码相比,程序员可以获得更高的工作效率, 或者给与程序更大的灵活度去处理新的情形而无需重新编译。

编写元程序的语言称之为元语言。被操纵的程序的语言称之为目标语言。一门编程语言同时也是自身的元语言的能力称之为反射或者自反。

反射是促进元编程的一种很有价值的语言特性。把编程语言自身作为一级数据类型(如LISP,Forth或Rebol)也很有用。支持泛型编程的语言也使用元编程能力。

元编程通常通过两种方式实现。一种是通过应用程序编程接口(APIs)将运行时引擎的内部信息暴露于编程代码。另一种是动态执行包含编程命令的字符串表达式。因此,“程序能够编写程序”。虽然两种方式都能用于同一种语言,但大多数语言趋向于偏向其中一种。
引用
评论
14年5个月前IP:未同步
428610
2楼
回 楼主(acmilan) 的帖子
这意思大概就是用程序去生成程序吧
+1
科创币
acmilan
2012/07/28
第三种才是,第12种都是反射
引用
评论
acmilan作者
14年5个月前IP:未同步
428611
3楼
英文对照:
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime. In some cases, this allows programmers to minimize the number of lines of code to express a solution (hence reducing development time), or it gives programs greater flexibility to efficiently handle new situations without recompilation.
The language in which the metaprogram is written is called the metalanguage. The language of the programs that are manipulated is called the object language. The ability of a programming language to be its own metalanguage is called reflection or reflexivity.
Reflection is a valuable language feature to facilitate metaprogramming. Having the programming language itself as a first-class data type (as in Lisp, Forth or Rebol) is also very useful. Generic programming invokes a metaprogramming facility within a language, in those languages supporting it.
Metaprogramming usually works in one of three ways. The first way is to expose the internals of the run-time engine to the programming code through application programming inter*aces (APIs). The second approach is dynamic execution of expressions that contain programming commands, often composed from strings, but can also be from other methods using arguments and/or context. Thus, "programs can write programs." Although both approaches can be used in the same language, most languages tend to lean toward one or the other.

第三种没有中文翻译,有谁翻译下:
The third way is to step outside the language entirely. General purpose program transformation systems, which accept language descriptions and can carry out arbitrary transformations on those languages, are direct implementations of general metaprogramming. This allows metaprogramming to be applied to virtually any target language without regard to whether that target language has any metaprogramming abilities of its own.
引用
评论
acmilan作者
14年5个月前IP:未同步
428616
4楼
第三种就是真正的用程序生成程序。[s:274]
其实在一般语言中调用system("dir/s/b");等,还有调用SQL语句都是元编程,重要的是语言的反射特性。
引用
评论
14年5个月前IP:未同步
428688
5楼
搞半天没搞懂啥叫反射.好像有点自适应的感觉.对于一个C程序员来说这个是有点挑战啊
引用
评论
acmilan作者
14年5个月前IP:未同步
429236
6楼
反射就是程序设计语言的自我反应自我操作,以区别于SQL之类的互操作。
引用
评论
14年5个月前IP:未同步
429341
7楼
这个和俺经常搞的自修改代码有何区别……
+1
科创币
acmilan
2012/07/29
请问其目
引用
评论
acmilan作者
14年5个月前IP:未同步
429370
8楼
回 7楼(phpskycn) 的帖子
这个是常规技术,而自修改代码是黑客技术,而且这个简单明了用途广。 [s:275]
而且这个是与程序设计语言相关的。。。
引用
评论
14年5个月前IP:未同步
429576
9楼
回 8楼(acmilan) 的帖子
前辈告诉俺:运行时修改自身的指令是一个非常不好的编程实践。。。。
引用
评论
acmilan作者
14年5个月前IP:未同步
429836
10楼
回 9楼(phpskycn) 的帖子
认真你就输了
前辈还告诉俺:没有运行时修改指令的基础,就没有运行时不能修改指令的语言[s:274]
POSIX的exec就是在运行时修改自身指令的哦。。。
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的