Medium reading 9.22 Lambdas are not functional programming

  1. Word
  2. Knowledge

https://medium.com/@johnmcclean/lambdas-are-not-functional-programming-63533ce2eb74

Word

verbose 冗长的 详细的

slightly 轻微地 稍微地

constrained 被迫的 勉强的

outcome 后果 结果 结局

adopting 采纳 吸收 收养

gnarly 粗糙的

twisted 古怪的 疯狂的 滑稽的

obfuscated 使迷糊

imperative 命令式 命令的

concise 简洁的 简明的

Lambda expressions in Java are simply a less verbose way of creating (slightly constrained) Objects and as such the most likely outcome of adopting Lambda’s without a good understanding of core functional concepts is gnarly, twisted, hard to follow, obfuscated imperative Object Oriented code with a nice concise syntax.

Java中的Lambda表达式只是创建(稍微受约束的)对象的一种较不冗长的方式,因此,在没有很好地理解核心功能概念的情况下采用Lambda的最可能的结果是粗糙,扭曲,难以遵循,混淆了带有命令性的面向对象的代码,简洁的语法

dodgy 狡猾的 逃避的

individual 个别的

Conversely 相反地

Seek 探索 寻找

passionately 热情的

sentence 句子

strangely 不可思议的

rants 咆哮

varying 不同的

discipline 学科 纪律 课程

tenet 信条 原理

debatable 可争论的

manner 样子 风格

evaluate 评估 赋值

suspension 悬挂 暂停

leverage 杠杆

traits 特性

composition 成分 作品

mentioned 提及

by extension 通过拓展

theory 理论 学说

mutating 变化 使变异

immutability 不变的

aforementioned 上述的

encourage 鼓励 支持

eschew 避开

ecosystem 生态系统

mimic 模仿 模仿者

wasps 黃蜂

ward 守卫

predators 掠夺者

masquerading 冒充 伪装

conciseness 简明 切除

alternatives 二选一的 选择

Grappling 抓住 解决

enforces 强迫 坚持 执行

perhaps 也许 大概

hurdles 障碍

strictness 严格

intolerant 无法容忍的

mutate 变化 使变化

external 外部 表面的

hierarchies 等级 阶层

closures 关闭 结束

machinations 机密 阴谋 策划

particular 特别的 个别项目 详细书名

entirely 完全的 彻底地

hacks 黑客 技巧

eliminate 除去 剔除

Knowledge

  • No-one in Java-land is doing functional programming, and that is a good thing.

    Just because you are using Lambda expressions, does not mean you are doing functional programming.

  • If Javac won’t help us, what can we do?

    If you are looking to truly adopt the advantages of functional programming in Java and not just create mind bendingly gnarly imperative code with Lambda’s then I believe we need to work with the Java Compiler to help it help us.

    Rather than spend our time trying to trick it, we should :-

  1. Make good use of Generic Types. Generics in Java can trace their orgins to Generic Java created by Philip Wadler (Haskell legend), Martin Odersky (creator of Scala), Gilad Bracha, Dave Stoutamire. Don’t ignore type parameters, declare them and enforce them everywhere. Minimize casting and if instanceOfing. Where you do use them (it is still Java after all — they are likely impossible to fully eliminate), centralize each type of cast within a resuable method, use proper type parameters on the inputs and outputs and write good tests!

  2. Make illegal states unrepresentable in our code. The Haskell and Idris compilers will enforce this for you, just pretend Javac is as strict. Avoid nulls, don’t throw Exceptions, avoid locking and synchronization and you will take giant leaps towards this.

  3. Make our own data classes immutable and final where possible, use immutable collections (proper ones). Avoid instanceof checks where possible, and where you use them make sure the types are not extensible.

  4. Use libraries that avoid runtime magic and reflection where pragmatically possible.

  • There is no conflict between OO and FP.

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 wshten@gmail.com

文章标题:Medium reading 9.22 Lambdas are not functional programming

本文作者:KevinTen

发布时间:2019-09-22, 10:00:00

最后更新:2019-09-22, 20:31:34

原始链接:http://github.com/kevinten10/2019/09/22/Medium/Medium-9-22-3/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏

csdn zhihu github