编程与软件工程viewsourcecode.org编辑精选
从零构建一个文本编辑器
Build Your Own Text Editor
2017 — 2022,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一个逐步教学式的教程:带你用 C 语言从零构建一个终端文本编辑器(基于 antirez 的 kilo),从读取按键、处理原始终端模式,到语法高亮、搜索等功能,一步步把代码写出来。教程刻意控制规模,只讲清核心组件,跳过大量繁琐的边界情况,让人能完整跟下来。
为什么经久不衰:它把一个"中等规模"的完整程序拆成可消化的步骤,既不是玩具片段也不是读不动的大型开源项目,是少有的能真正写完并读懂的学习范本,所以多年来反复被推荐。
HN 评论精选
规模适中、敢于省略边界情况的参考实现最适合用来学习。
中等规模应用的参考实现对程序员进阶非常有用。虽然有很多大型且成功的开源应用,但其中许多读起来让人不堪重负、难以从中学习。有一个能勾勒出关键特性和组件、并忽略那些重要但复杂的边界情况的示例,有助于保持注意力集中。如果源码里还带注释,那就真的太棒了。
Dangeranger查看英文原文
Reference implementations of medium sized applications are incredibly useful for leveling up as a programmer. While there are many large successful open source applications, many are overwhelming to read and learn from. Having something that outlines the key features and components and which ignores the important but complicated edge cases assists in keeping the attention focused. Now if there are annotation within the source code, that would be truely incredible.
推荐 Freyja 源码和 Finseth 的著作作为进一步学习的资源。
我认为 Kilo 是个很棒的小项目,结构良好、很有教育意义。另一个我过去依赖过的有用资源可以追溯到 1990 年代:Freyja,是 Craig Finseth 用 C 写的类 Emacs 编辑器……它的架构非常清晰,Finseth 的经典著作《The Craft of Text Editing》里解释得很好,即使你从不碰代码,这本书也值得一读。
mistermumble查看英文原文
I think Kilo is a great little project, well-structured and very educational. Another useful resource I've relied upon in the past, dates back to the 1990s: Freyja, which is Craig Finseth's emacs-like editor written in C. Here is a list of features: * deletions are automatically saved into a "kill buffer" * ability to edit up to 11 files at once * ability to view two independent windows at once * integrated help facility * integrated menu facility, with help on all commands * can record and play back keyboard macros * supports file completion and limited directory operations * includes a fully-integrated RPN type calculator It was designed for MS-DOS with the Cygwin terminal library. I found the architecture to be very clean, and it is well explained in Finseth's classic book ("The Craft of Text Editing"). The book is worth reading even if you never touch the code: http://www.finseth.com/craft/ It uses a multi-buffer architecture roughly similar to Walter Bright's text editor (see sibling posting). (I knew about Finseth's editor years ago, but was not aware of Bright's work until now, thanks Walter!) The Freyja source can be downloaded from: http://www.finseth.com/parts/freyja.php Look for the link to "freyja30.exe" which turns out to be freyja30.zip (not an executable).
一段轶事:写编辑器几乎是程序员的成人礼,Pike 却调侃这算不上有用的事。
记得 Rob Pike 在他写 sam 编辑器几年前说过(大意):"每个人都会写一个屏幕编辑器。这很容易,还能让他们自觉重要。告诉他们去做点有用的事。"这话是他离开 Caltech 去贝尔实验室后不久说的……有天晚上我和 Karl Heuer 都在吹嘘自己的屏幕编辑器会有多棒,结果变成了一场写编辑器的对决,我们各自占着房间两头的终端开始敲代码,通宵达旦,偶尔互相炫耀一句"我搜索功能做好了!"……后来 Norman Wilson 看到我们干了一整夜,就给 Pike 发了邮件,上面那句话就是 Pike 的回复。
tzs查看英文原文
Quote (from memory) from Rob Pike, a few years before he wrote the editor "sam": "Everybody writes a screen editor. It's easy to do and makes them feel important. Tell them to work on something useful". This was not long after he had left Caltech, where he had been a system admin/system programmer for CITHEP (Caltech High Energy Physics), for Bell Labs. CITHEP hired a few undergraduates as the new admins and system programmers. I was one of those undergraduates. Most of us used the line-oriented editor QED, but as programmers were wont to do in the early '80s, said that someday we were going to write ourselves awesome screen editors. One evening, Karl Heuer and I were both boasting about how great our screen editors would be, and it somehow turned into an editor writing throw down. We took terminals at opposite sides of the room, and both started hacking away, designing as we coded. This continued all night, mostly in silence, with the occasional boast ("I've got text search working!") and counter-boast ("I had that an hour ago--I'm doing regular expressions now!"), and frequent trips downstairs to the vending machines for soda and snacks. Another of the undergraduate system admin/programmers, Norman Wilson, then arrived, and saw what Karl and I had been doing all night. He sent an email to Pike about it, and the quote at the start was Pike's reply.
rrb-tree 是无锁、支持大文档和撤销的理想编辑器数据结构。
万一有人还没看过:这个 CppCon 演讲(链接)讲了 rrb-tree,以及它为什么是写文本编辑器的绝佳数据结构——能处理任意大小的文档而不会卡死,允许在保存和打开文件的同时继续编辑,还能轻松支持撤销。今天大多数文本编辑器并不支持这些功能,而用 rrb-tree 这类无锁数据结构就变得很容易。
proverbialbunny查看英文原文
In case anyone hasn't seen it this CppCon talk https://youtu.be/sPhpelUfu8Q talks about rrb-trees and how they're a great data structure for writing a text editor that can handle unlimited sized documents without locking up, and allows for editing while saving and opening, and an easy way to support an undo command. Most text editors today do not support such functionality. With lockless data structures like an rrb-tree it becomes easy. It really is an ideal way to do write a text editor.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选