当前位置:网站首页>《微型Lisp解释器的构造与解释》的写作风格
《微型Lisp解释器的构造与解释》的写作风格
2022-06-21 05:23:00 【ccat】
今天看到有读者抱怨我那本书是把源代码打印出来卖。这个感受我能理解,但是其实这个写作风格是反复尝试的结果,而不是偷懒。书里附带的源码,有很多是用 Scala 来注解 Java 。例如昨天我的好友问我Java版 Env 类型的 get 方法为何用了一个 try catch,
public Object get(String name) throws ParserException {
try {
return findIn(name);
} catch (ParserException notfound) {
return findOut(name);
}
}
这个其实在下一页的 Scala 版本中就是非常干净的
def get(name: String): Try[Any] = {
findIn(name).orElse(findUp(name))
}。Java 的实现,只是为了尽可能接近 Scala 的 Try[T] ,这里更接近是一个getOrElse而不是错误处理。这种不同语言的对比,在我开发和写作的过程中,带来了很多启发和乐趣,也是我想向读者分享的体验。
我个人读书,有时候不够耐心,会经常跳过文字啃代码,这也影响了写作。未来也是一个要改进的地方。
整理这些代码的时候,我的想法更像是在编写数学题的解题过程。文字说明、图解肯定可以帮助理解,未来的版本我也会尽量添加,但是最终,编程的问题,还是要通过编写代码解决。这些代码是反复修改成为现在这个状态的,比 github 中的更便于阅读。我也尽可能去掉了一些工程代码。当然,一般来说,同一个功能,Java 的实现通常总是比 Scala 更冗长一些。但是也有一些有意思的细节值得展现。而 Scala 的代码,如果去掉变量和函数的显式类型定义,肯定可以漂亮的多,但是如果读者照着那样的代码去练习,会遇到很多编译器警告甚至类型推导错误。这一点上,我其实希望未来 scala 能够像 haskell 那样标注类型,毕竟 scala 3 连缩进语法都能实现,开发者的态度还是很开放的。Haskell 风格的标注类型,组合缩进语法,会非常利于排版打印和阅读。
书中还有一些实现,同时给出了 Scala 2 和 Scala 3 的版本,这是因为 Scala 3 的FP语法有了非常大的改变,更接近 Haskell 的体系。通过展示 Scala 3 的版本,能更好的说明这些设计为何如此。
另外就是如果读者能够直接阅读github中 JISP和 SISP 的代码,当然对我来说也是很开心的。不过那些代码其实缺失了一些信息,主要是 Commit 记录不一定代表了正确、清晰的构建过程,这中间有大量的 debug、parsec升级和思考、试验、试错以及书写修正。未来我会尽量构建一个流程清晰的,带章节划分的教学库。目前没有,是因为这三年来 Jaskell 库还在快速的发展,我这几年基本上都是每个月都有一些修订。而教学演示和文档,只能依靠投入大量的工作量去解决,没有捷径。
最后,还是要感谢每一位读者的意见和建议,你们是我前进的动力。
边栏推荐
- 如何保证数据库和缓存双写一致性?
- House sales and leasing system based on ssh+mysql
- Z-shaped deformation [one of the forms of the law - > periodic investigation]
- renren-fast启动提示 process.env.NODE_ENV
- Seata四大模式之AT模式详解及代码实现
- 高通骁龙处理器DSP
- Improve the efficiency of software R & D team
- 根据类中某个属性去重
- Comprehensive arrangement of character recognition methods
- [reading papers] sorting out the learning methods of trans series knowledge representation
猜你喜欢

常見的存儲類型

Public transport information management system based on ssm+mysql+layui+jsp

LaTeX给表格的一整行加删除线(横线)

工厂方法模式(Factory Pattern)

mac os MAMP 安装redis 报错问题 ./common.h:12:10: fatal error: ‘zend_smart_str.h‘ file not found

AI OPEN DAY---如何通过采用开源技术来优化产品和业务收益

基于JSP+Servlet+MySQL的鲜花销售系统

Unscrambling the education mode of compound new engineering robot

Use of TestNG framework (I): idea installation TestNG environment
![Z-shaped deformation [one of the forms of the law - > periodic investigation]](/img/84/0f128a4f8e25a0f8bdcd042625a67e.png)
Z-shaped deformation [one of the forms of the law - > periodic investigation]
随机推荐
Yyds dry goods inventory solution Huawei machine test: conversion between integer and IP address
518. change II
Kotlin technology - the most complete lambda writing form in the whole network in history
La relation entre la fréquence de l'horloge Clk et la résolution d'affichage et le taux de trame du LCD mipi
基于SSH+MySQL的房屋销售租赁系统
C语言:随机输入每位同学中每门学科的成绩,要求每位同学的所有学科平均分从低到高排序求出每位同学的平均成绩后,再进行判断该同学的平均成绩是否达到及格。
IDEA Debug出现:Skipped breakpoint at because it happened inside debugger evaluation
Abbexa GM130 抗体解决方案
College student information management system based on ssm+hui+mysql
Randomly create circular, triangular or rectangular objects, store them in the array, and calculate the area and perimeter of each shape
How to remove the prohibition of copying and pasting set by teachers
Flower sales system based on jsp+servlet+mysql
Launcher page cutting animation
常見的存儲類型
C language: randomly input the scores of each subject in each student, and require each student to rank the average scores of all subjects from low to high to find out the average scores of each stude
基于SSM+MySQL+Bootstrap+JSP的服装销售商城系统
83. (cesium chapter) how to run the cesium example
软件研发团队效能提升从点滴做起
Usage of JSON extractor and debugger in JMeter
Idea debug occurs: skipped breakpoint at because it happened inside debugger evaluation