语言的口味(taste)
2015-12-01 11:05
204 查看
这里的
almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram what’s actually being fed into that function before I understand what the reduce() is supposed to do.
taste有两层意思,第一层表示语言本身的偏好(preference,倾向性)、特征、特色;第二层表示本人对这些编程语言的偏爱。
C-Style vs Python-Style
所谓风格,就是语言的推荐做法,也即该做法能充分调用语言的优势。Python自然是强大的list comprehension,如下所示当对tuple(或者list)的索引同步时,自然可以使用zip对象,统一索引。
# Python Style out_shape=[ (ishp+tsp)*tshp-tsp for ishp, tshp, tsp in zip(image_shape, tile_shape, tile_spacing) ]
# C Style out_shape = [0, 0] out_shape[0] = (image_shape[0]+tile_spacing[0])*tile_shape[0]-tile_spacing[0] out_shape[1] = (image_shape[1]+tile_spacing[1])*tile_shape[1]-tile_spacing[1]
python
prefer“clear and obvious” to “compactness of expression”:清楚的表达的重要性甚于紧凑的表达(除非效率有显著的提升)。正是基于此,Guido(python语言的设计者)把
reduce这一和
map平行的经常成对出现的内置函数,放到了
functionals模块中。对此,他的解释是这样的:
almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram what’s actually being fed into that function before I understand what the reduce() is supposed to do.
相关文章推荐
- spring mvc 事务配置,spring 事务配置说明
- MySql实现动态分页
- bgp配置文件出错调试
- 解决端口占用问题
- union和union all的区别(转)
- 每天一个linux命令(20):linux chmod命令
- 图片裁剪问题
- Derby-10.11学习笔记汇总
- RAID详解[RAID0/RAID1/RAID10/RAID5]
- Spring事务管理的三种方式
- leetcode 第三题Longest Substring Without Repeating Characters
- Couldn't find platform family in Info.plist CFBundleSupportedPlatforms or Mach-O LC_VERSION_MIN
- DTCoretext的导入和简单使用------ 国外大牛的图文混排
- Js获取当前日期时间及其它操作
- 自己修改linux系统启动画面
- Hadoop的本地库(Native Libraries)介绍
- 天猫双11前端分享系列(四):大规模 Node.js 应用
- Java基础01 从HelloWorld到面向对象
- 前端开发学习笔记(三)HeadFirst HTML 与 CSS (第二版)
- CSS 文档流