编程语言与软件工程2020inf.ed.ac.uk编辑精选
Statecharts:面向复杂系统的可视化形式化方法
Statecharts: A Visual Formalism for Complex Systems (1987)
进阶 · 约 60 分钟读完前置知识:有限状态机基础、反应式系统概念、形式化建模基础
导读
这是 David Harel 1987 年提出的 Statecharts(状态图)形式化方法的经典论文,用层级化、并发和广播通信等机制扩展传统有限状态机,以便描述复杂反应式系统的行为。它后来影响了 UML 状态图等建模语言,并在前端状态管理等领域被重新关注。
HN 关注点:的焦点是:这套 30 多年前的形式化方法如今仍能显著改善复杂 UI 与控制系统中的状态管理,如减少散落各处的状态标志、提升可测试性与可验证性。
后来怎么样
Statecharts 成为 UML 状态图的重要理论基础,并被广泛用于反应式系统、嵌入式系统和 UI 状态建模;其后继思想也影响了 XState 等现代状态图实现。
HN 评论精选
这几条评论里:支持 2 补充 2
支持推荐用 XState 以状态图替代散乱的状态标志和 Redux。
这种方法对开发复杂 UI 大有裨益。如果你厌倦了在 React/Angular/Vue 代码里到处散布 isLoading、isError 之类的状态标志,可以看看 JavaScript 事实上的标准状态图实现 XState。我用得很愉快,它可以替代 redux 等其他状态管理方式,同时把 UI 的行为约束到可预测的状态与交互上。
adamkl查看英文原文
This approach is a big boon to the development of complex UIs. If you are tired of littering your React/Angular/Vue/etc code with a litany of state flags (“isLoading”, “isError”, etc)[0] take a look at the de facto canonical state chart implementation for JavaScript, XState: https://xstate.js.org/docs/ It’s been a joy to work with and can replace other methods of managing state (i.e. redux) while constraining the behaviour of your UI to predictable states and interactions. [0] https://dev.to/davidkpiano/no-disabling-a-button-is-not-app-logic-598i
支持主张把控制逻辑全部抽入状态图形式化模型,收益巨大。
忽视这套方法的人要自担风险。它适用的场景非常非常多,哪怕一开始看不出来。把复杂的控制系统逻辑抽出来、用这类(及相关)形式化方法表达,能极大提升可测试性、显著减少代码量、消除大量潜在缺陷,还大大有利于形式验证和模型检查。应用里的“代码”部分基本只该做数据管道,所有决策与控制逻辑都应抽到这类形式化模型里。感谢分享!
vbtemp查看英文原文
People who gloss over this do so at your own risk. This technique is applicable for so, so many applications - even when it doesn't appear obvious at first. Factoring out complex control system logic into these (and related) formalisms dramatically enhances testability, substantially reduces code volume, and eliminates huge swaths of possible defects (not to mention seriously enhances formal verification and model checking). The "code" part for applications should basically be for data plumbing, and all decision-making and control logic should be factored into these. Thanks for posting this!!
补充推荐 Harel 本人参与的 edX 可视化编程课程。
本文作者 David Harel 和 Michal Gordon 在 edX 上有一门课《Programming for Everyone – An Introduction to Visual Programming Languages》。无论你是程序员、设计师、工程师还是管理者,只要要处理状态问题,我都强烈推荐这门课。
bmitc查看英文原文
There is an edX course by David Harel (the author of this paper) and Michal Gordon called Programming for Everyone – An Introduction to Visual Programming Languages. I highly recommend it for anyone dealing with state, whether you’re a programmer, designer, engineer, or manager. https://www.edx.org/course/programming-for-everyone-an-introduction-to-visual
补充补充 Harel 后续的基于场景编程方向及资料链接。
Harel 近期从 Statecharts 演化出的工作叫 Scenario-based programming(基于场景的编程)。我很关注他的研究,并在这篇关于 bthreads 的文章里展示了相关技术。
sktrdie查看英文原文
Harel's recent work (which evolve from Statecharts) is so called Scenario-based programming. If interested I follow his work very closely and showcase his techniques in this article about bthreads: https://lmatteis.github.io/react-behavioral/
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2020Hacker News 讨论帖142 分 · 64 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选