mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
commit
fab1f84d05
@ -1,30 +1,28 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (stevending1st)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-13594-1.html)
|
||||
[#]: subject: (9 open source JavaScript frameworks for front-end web development)
|
||||
[#]: via: (https://opensource.com/article/20/5/open-source-javascript-frameworks)
|
||||
[#]: author: (Bryant Son https://opensource.com/users/brson)
|
||||
|
||||
9 个用于 web 前端开发的 JavaScript 开源框架
|
||||
用于 Web 前端开发的 9 个 JavaScript 开源框架
|
||||
======
|
||||
|
||||
根据 JavaScript 框架的优点和功能的分类。
|
||||
> 根据 JavaScript 框架的优点和主要特点对许多 JavaScript 框架进行细分。
|
||||
|
||||
![Computer screen with files or windows open][1]
|
||||
![](https://img.linux.net.cn/data/attachment/album/202107/18/205233kz0sqwdwwvrwp2ss.jpg)
|
||||
|
||||
大约十年前,JavaScript 社区开始见证一场 JavaScript 框架的激战。在本文中我将介绍其中最著名的一些框架。值得注意的是,这些都是开源的 JavaScript 项目,这意味着你可以在 [开源许可证][2] 下自由地使用它们,甚至为它们的源代码和社区做出贡献。
|
||||
|
||||
你如果喜欢和我一起探索框架,可以看我的视频。
|
||||
大约十年前,JavaScript 社区开始见证一场 JavaScript 框架的激战。在本文中,我将介绍其中最著名的一些框架。值得注意的是,这些都是开源的 JavaScript 项目,这意味着你可以在 [开源许可证][2] 下自由地使用它们,甚至为它们的源代码和社区做出贡献。
|
||||
|
||||
不过,在开始之前,了解一些 JavaScript 开发者谈论框架时常用的术语,将对后续的内容大有裨益。
|
||||
|
||||
术语 | 释义
|
||||
---|---
|
||||
[文档对象模型(DOM)][3] | 网站用树结构表示,每一个节点都是代表网页一部分的对象。万维网联盟(W3C),是万维网的国际标准组织,维护着 DOM 的定义。
|
||||
[文档对象模型(DOM)][3] | 网站的树形结构表示,每一个节点都是代表网页一部分的对象。万维网联盟(W3C),是万维网的国际标准组织,维护着 DOM 的定义。
|
||||
[虚拟 DOM][4] | 用户界面(UI)以“虚拟”或“理想”的方式保存在内存中,并通过 [ReactDOM][5] 等一些库与“真实” DOM 同步。要进一步探索,请阅读 ReactJS 的虚拟 DOM 和内部文档。
|
||||
[数据绑定][6] | 一个编程概念,为访问网站上的数据提供一致的接口。Web 元素与 DOM 维护的元素的 property 或 attribute 相关联(译者注:根据 MDN 的解释,Javascript 的 property 是对象的特征,通常描述与数据结构相关的特征;attribute 是指元素所有属性节点的一个实时集合)。例如,当需要在网页表单中填写密码时,数据绑定机制可以用密码验证逻辑检验,确保密码格式有效。
|
||||
[数据绑定][6] | 一个编程概念,为访问网站上的数据提供一致的接口。Web 元素与 DOM 维护的元素的<ruby>属性<rt>property</rt></ruby> 或 <ruby>特性<rt>attribute</rt></ruby> 相关联(LCTT 译注:根据 MDN 的解释,Javascript 的<ruby>属性<rt>property</rt></ruby>是对象的特征,通常描述与数据结构相关的特征;<ruby>特性<rt>attribute</rt></ruby> 是指元素所有属性节点的一个实时集合)。例如,当需要在网页表单中填写密码时,数据绑定机制可以用密码验证逻辑检验,确保密码格式有效。
|
||||
|
||||
我们已经清楚了常用的术语,下面我们来探索一下开源的 JavaScript 框架有哪些。
|
||||
|
||||
@ -33,10 +31,10 @@
|
||||
[ReactJS][7] | 目前最流行的 JavaScript 框架,由 Facebook 创建 | MIT 许可证 | 2013-5-24
|
||||
[Angular][8] | Google 创建的流行的 JavaScript 框架 | MIT 许可证 | 2010-1-5
|
||||
[VueJS][9] | 快速增长的 JavaScript 框架 | MIT 许可证 | 2013-7-28
|
||||
[MeteorJS][10] | 比 JavaScript 框架更强大的框架 | MIT 许可证 | 2012-1-18
|
||||
[KnockoutJS][11] | 开源的 MVVM(Model-View-ViewModel,模型-视图-视图模型) 框架 | MIT 许可证 | 2010-7-5
|
||||
[MeteorJS][10] | 超乎于 JavaScript 框架的强大框架 | MIT 许可证 | 2012-1-18
|
||||
[KnockoutJS][11] | 开源的 MVVM(<ruby>模型-视图-视图模型<rt>Model-View-ViewModel</rt></ruby>) 框架 | MIT 许可证 | 2010-7-5
|
||||
[EmberJS][12] | 另一个开源的 MVVM 框架 | MIT 许可证 | 2011-12-8
|
||||
[BackboneJS][13] | 带有 RESTful JSON 和 Model-View-Presenter 模式的 JavaScript 框架 | MIT 许可证 | 2010-9-30
|
||||
[BackboneJS][13] | 带有 RESTful JSON 和<ruby>模型-视图-主持人<rt>Model-View-Presenter</rt></ruby>模式的 JavaScript 框架 | MIT 许可证 | 2010-9-30
|
||||
[Svelte][14] | 不使用虚拟 DOM 的 JavaScript 开源框架 | MIT 许可证 | 2016-11-20
|
||||
[AureliaJS][15] | 现代 JavaScript 模块的集合 | MIT 许可证 | 2018-2-14
|
||||
|
||||
@ -50,18 +48,18 @@
|
||||
|
||||
[ReactJS][19] 是由 Facebook 研发的,它虽然在 Angular 之后发布,但明显是当今 JavaScript 框架的领导者。React 引入了一个虚拟 DOM 的概念,这是一个抽象副本,开发者能在框架内仅使用他们想要的 ReactJS 功能,而无需重写整个项目。此外,React 项目活跃的开源社区无疑成为增长背后的主力军。下面是一些 React 的主要优势:
|
||||
|
||||
* 合理的学习曲线——React 开发者可以轻松地创建 React 组件,而不需要重写整个 JavaScript 的代码。在 ReactJS 的 [首页][20] 查看它的好处以及它如何使编程更容易。
|
||||
* 高度优化的性能——React 的虚拟 DOM 的实现和其他功能提升了应用程序的渲染性能。请查看 ReactJS 的关于如何对其性能进行基准测试,并对应用性能进行衡量的相关 [描述][21]。
|
||||
* 优秀的支持工具——[Redux][22]、[Thunk][23] 和 [Reselect][24] 是构建良好、可调式代码的最佳工具。
|
||||
* 单项数据绑定——模型使用 Reach 流,只从所有者流向子模块,这使得在代码中追踪因果关系更加简单。请在 ReactJS 的 [数据绑定页][25] 阅读更多相关资料。
|
||||
* 合理的学习曲线 —— React 开发者可以轻松地创建 React 组件,而不需要重写整个 JavaScript 的代码。在 ReactJS 的 [首页][20] 查看它的优点以及它如何使编程更容易。
|
||||
* 高度优化的性能 —— React 的虚拟 DOM 的实现和其他功能提升了应用程序的渲染性能。请查看 ReactJS 的关于如何对其性能进行基准测试,并对应用性能进行衡量的相关 [描述][21]。
|
||||
* 优秀的支持工具 —— [Redux][22]、[Thunk][23] 和 [Reselect][24] 是构建良好、可调式代码的最佳工具。
|
||||
* 单向数据绑定 —— 模型使用 Reach 流,只从所有者流向子模块,这使得在代码中追踪因果关系更加简单。请在 ReactJS 的 [数据绑定页][25] 阅读更多相关资料。
|
||||
|
||||
谁在使用 ReactJS?Facebook 自从发明它,就大量使用 React 构建公司首页,据说 [Instagram][26] 完全基于 ReactJS 库。你可能会惊讶地发现,其他知名公司如 [New York Times][27]、[Netflix][28] 和 [Khan Academy][29] 也在他们的技术栈中使用了 ReactJS。
|
||||
谁在使用 ReactJS?Facebook 自从发明它,就大量使用 React 构建公司首页,据说 [Instagram][26] 完全基于 ReactJS 库。你可能会惊讶地发现,其他知名公司如 [纽约时报][27]、[Netflix][28] 和 [可汗学院][29] 也在他们的技术栈中使用了 ReactJS。
|
||||
|
||||
更令人惊讶的是 ReactJS 开发者的工作可用性,正如在下面 Stackoverflow 所做的研究中看到的,嘿,可以从事开源项目并获得报酬。这很酷!
|
||||
更令人惊讶的是 ReactJS 开发者的工作机会,正如在下面 Stackoverflow 所做的研究中看到的,嘿,你可以从事开源项目并获得报酬。这很酷!
|
||||
|
||||
![React jobs page][30]
|
||||
|
||||
Stackoverflow 的研究显示了对 ReactJS 开发者的巨大需求——[来源:2017年开发者招聘趋势——Stackoverflow 博客][31]
|
||||
*Stackoverflow 的研究显示了对 ReactJS 开发者的巨大需求——[来源:2017 年开发者招聘趋势——Stackoverflow 博客][31]*
|
||||
|
||||
[ReactJS 的 GitHub][7] 目前显示超过 13,000 次提交和 1,377 位贡献者。它是一个在 MIT 许可证下的开源项目。
|
||||
|
||||
@ -71,13 +69,13 @@ Stackoverflow 的研究显示了对 ReactJS 开发者的巨大需求——[来
|
||||
|
||||
![Angular homepage][33]
|
||||
|
||||
对于大多数开发者来说,也许现在 React 是领先的 JavaScript 框架,但是 [Angular][34] 紧随其后。事实上,开源开发者和初创公司更乐于选择 React,而较大的公司往往更喜欢 Angular(下面列出了一些例子)。主要原因是,虽然 Angular 可能更复杂,但它的统一性和一致性适用于大型项目。例如,在我整个职业生涯中一直研究 Angular 和 React,我观察到大公司通常认为 Angular 严格的结构是一种优势。下面是 Angular 的另外一些关键优势:
|
||||
就开发者数量来说,也许 React 是现在最领先的 JavaScript 框架,但是 [Angular][34] 紧随其后。事实上,开源开发者和初创公司更乐于选择 React,而较大的公司往往更喜欢 Angular(下面列出了一些例子)。主要原因是,虽然 Angular 可能更复杂,但它的统一性和一致性适用于大型项目。例如,在我整个职业生涯中一直研究 Angular 和 React,我观察到大公司通常认为 Angular 严格的结构是一种优势。下面是 Angular 的另外一些关键优势:
|
||||
|
||||
* 精心设计的命令行工具——Angular 有一个优秀的命令行工具(CLI),可以轻松引导和使用 Angular 进行开发。ReactJS 提供命令行工具和其他工具,同时 Angular 有广泛的支持和出色的文档,你可以参见 [这个页面][35]。
|
||||
* 单项数据绑定——和 React 类似,单向数据绑定模型使框架受更少的不必要的副作用的影响。
|
||||
* 更好的 TypeScript 支持——Angular 与 [TypeScript][36] 有很好的一致性,它其实是 JavaScript 强制类型的拓展。它还可以转译为 JavaScript,强制类型是减少错误代码的绝佳选择。
|
||||
* 精心设计的命令行工具 —— Angular 有一个优秀的命令行工具(CLI),可以轻松起步和使用 Angular 进行开发。ReactJS 提供命令行工具和其他工具,同时 Angular 有广泛的支持和出色的文档,你可以参见 [这个页面][35]。
|
||||
* 单向数据绑定 —— 和 React 类似,单向数据绑定模型使框架受更少的不必要的副作用的影响。
|
||||
* 更好的 TypeScript 支持 —— Angular 与 [TypeScript][36] 有很好的一致性,它其实是 JavaScript 强制类型的拓展。它还可以转译为 JavaScript,强制类型是减少错误代码的绝佳选择。
|
||||
|
||||
像 YouTube、[Netflix][37]、[IBM][38] 和 [Walmart][39] 等知名网站,都已在其应用程序中采用了 Angular。我通过自学使用 Angular 来开始学习前端 JavaScript 开发。我参与了许多涉及 Angular 的个人和专业项目,但那是当时被称为 AngularJS 的 Angular 1.x。当 Google 决定将版本升级到 2.0 时,他们对框架进行了彻底的改造,然后成了 Angular。新的 Angular 是对之前的 AngularJS 的彻底改造,这一举动带来了一部分新开发者也驱逐了一部分原有的开发者。
|
||||
像 YouTube、[Netflix][37]、[IBM][38] 和 [Walmart][39] 等知名网站,都已在其应用程序中采用了 Angular。我通过自学使用 Angular 来开始学习前端 JavaScript 开发。我参与了许多涉及 Angular 的个人和专业项目,但那是当时被称为 AngularJS 的 Angular 1.x。当 Google 决定将版本升级到 2.0 时,他们对框架进行了彻底的改造,然后变成了 Angular。新的 Angular 是对之前的 AngularJS 的彻底改造,这一举动带来了一部分新开发者也驱逐了一部分原有的开发者。
|
||||
|
||||
截止到撰写本文,[Angular 的 GitHub][8] 页面显示 17,781 次提交和 1,133 位贡献者。它也是一个遵循 MIT 许可证的开源项目,因此你可以自由地在你的项目或贡献中使用。
|
||||
|
||||
@ -93,9 +91,9 @@ Stackoverflow 的研究显示了对 ReactJS 开发者的巨大需求——[来
|
||||
|
||||
这里有一些 VueJS 的主要优点:
|
||||
|
||||
* 更容易地学习曲线——与 Angular 或 React 相比,许多前端开发者都认为 VueJS 有更平滑的学习曲线。
|
||||
* 小体积——与 Angular 或 React 相比,VueJS 相对轻巧。在 [官方文档][45] 中,它的大小据说只有约 30 KB;而 Angular 生成的项目超过 65 KB。
|
||||
* 简明的文档——VueJS 有全面清晰的文档。请自行查看它的 [官方文档][46]。
|
||||
* 更容易地学习曲线 —— 与 Angular 或 React 相比,许多前端开发者都认为 VueJS 有更平滑的学习曲线。
|
||||
* 小体积 —— 与 Angular 或 React 相比,VueJS 相对轻巧。在 [官方文档][45] 中,它的大小据说只有约 30 KB;而 Angular 生成的项目超过 65 KB。
|
||||
* 简明的文档 —— VueJS 有全面清晰的文档。请自行查看它的 [官方文档][46]。
|
||||
|
||||
[VueJS 的 GitHub][9] 显示该项目有 3,099 次提交和 239 位贡献者。
|
||||
|
||||
@ -105,17 +103,17 @@ Stackoverflow 的研究显示了对 ReactJS 开发者的巨大需求——[来
|
||||
|
||||
![Meteor page][48]
|
||||
|
||||
[MeteorJS][49] 是一个免费开源的 [同构框架][50],这意味着它和 NodeJS 一样,同时运行客户端和服务器的 JavaScript。Meteor 能够和任何其他流行的前端框架一起使用,如 Angular、React、Vue、Svelte 等。
|
||||
[MeteorJS][49] 是一个自由开源的 [同构框架][50],这意味着它和 NodeJS 一样,同时运行客户端和服务器的 JavaScript。Meteor 能够和任何其他流行的前端框架一起使用,如 Angular、React、Vue、Svelte 等。
|
||||
|
||||
Meteor 被高通、Mazda 和宜家等多家公司以及如 Dispatch 和 Rocket.Chat 等多个应用程序使用。[您可以其在官方网站上查看更多案例][51]。
|
||||
Meteor 被高通、马自达和宜家等多家公司以及如 Dispatch 和 Rocket.Chat 等多个应用程序使用。[您可以其在官方网站上查看更多案例][51]。
|
||||
|
||||
![Meteor case study][52]
|
||||
|
||||
Meteor 的一些主要功能包括:
|
||||
|
||||
* 在线数据——服务器发送数据而不是 HTML,并由客户端渲染。在线数据主要是指 Meteor 在页面加载时通过一个 WebSocket 连接服务器,然后通过该链接传输所需要的数据。
|
||||
* 用 JavaScript 开发一切——客户端、应用服务、网页和移动界面都可以用 JavaScript 设计。
|
||||
* 支持大多数主流框架——Angular、React 和 Vue 都可以与 Meteor 结合。因此,你仍然可以使用最喜欢的框架如 React 或 Angular,这并不防碍 Meteor 为你提供一些优秀的功能。
|
||||
* 在线数据 —— 服务器发送数据而不是 HTML,并由客户端渲染。在线数据主要是指 Meteor 在页面加载时通过一个 WebSocket 连接服务器,然后通过该链接传输所需要的数据。
|
||||
* 用 JavaScript 开发一切 —— 客户端、应用服务、网页和移动界面都可以用 JavaScript 设计。
|
||||
* 支持大多数主流框架 —— Angular、React 和 Vue 都可以与 Meteor 结合。因此,你仍然可以使用最喜欢的框架如 React 或 Angular,这并不防碍 Meteor 为你提供一些优秀的功能。
|
||||
|
||||
截止到目前,[Meteor 的 GitHub][10] 显示 22,804 次提交和 428 位贡献者。这对于开源项目来说相当多了。
|
||||
|
||||
@ -129,8 +127,8 @@ Meteor 的一些主要功能包括:
|
||||
|
||||
Ember 虽然和我们讨论过的其他框架有类似的好处,但这里有些独特的区别:
|
||||
|
||||
* 约定优于配置——Ember 标准化命名约定并自动生成结果代码。这种方法学习曲线有些陡峭,但可以确保程序员遵循最佳实践。
|
||||
* 成熟的模板机制——Ember 依赖于直接文本操作,直接构建 HTML 文档,而并不关心 DOM。
|
||||
* 约定优于配置 —— Ember 将命名约定标准化并自动生成结果代码。这种方法学习曲线有些陡峭,但可以确保程序员遵循最佳实践。
|
||||
* 成熟的模板机制 —— Ember 依赖于直接文本操作,直接构建 HTML 文档,而并不关心 DOM。
|
||||
|
||||
正如所期待的那样,作为一个被许多应用程序使用的框架,[Ember 的 GitHub][58] 页面显示该项目拥有 19,808 次提交和 785 位贡献者。这是一个巨大的数字!
|
||||
|
||||
@ -142,7 +140,7 @@ Ember 虽然和我们讨论过的其他框架有类似的好处,但这里有
|
||||
|
||||
[KnockoutJS][61] 是一个独立开源的 JavaScript 框架,采用 [模板-视图-视图模型(MVVM)][56] 模式与模板。尽管与 Angular、React 或 Vue 相比,听说过这个框架的人可能比较少,这个项目在开发者社区仍然相当活跃,并且有以下功能:
|
||||
|
||||
* 声明式绑定——Knockout 的声明式绑定系统提供了一种简洁而强大的方式来将数据链接到 UI。绑定简单的数据属性或使用单向绑定很简单。请在 [KnockoutJS 的官方文档页面][62] 阅读更多相关信息。
|
||||
* 声明式绑定 —— Knockout 的声明式绑定系统提供了一种简洁而强大的方式来将数据链接到 UI。绑定简单的数据属性或使用单向绑定很简单。请在 [KnockoutJS 的官方文档页面][62] 阅读更多相关信息。
|
||||
* 自动 UI 刷新。
|
||||
* 依赖跟踪模板。
|
||||
|
||||
@ -154,7 +152,7 @@ Ember 虽然和我们讨论过的其他框架有类似的好处,但这里有
|
||||
|
||||
![BackboneJS page][64]
|
||||
|
||||
[BackboneJS][65] 是一个具有 RESTful JSON 接口,基于 Model-View-Presenter(MVP)设计范式的轻量级 JavaScript 框架。
|
||||
[BackboneJS][65] 是一个具有 RESTful JSON 接口,基于<ruby>模型-视图-主持人<rt>Model-View-Presenter</rt></ruby>(MVP)设计范式的轻量级 JavaScript 框架。
|
||||
|
||||
这个框架据说已经被 [Airbnb][66]、Hulu、SoundCloud 和 Trello 使用。你可以在 [Backbone 的页面][67] 找到上面所有这些案例来研究。
|
||||
|
||||
@ -178,9 +176,9 @@ Ember 虽然和我们讨论过的其他框架有类似的好处,但这里有
|
||||
|
||||
最后我们介绍一下 [Aurelia][73]。Aurelia 是一个前端 JavaScript 框架,是一个现代 JavaScript 模块的集合。Aurelia 有以下有趣的功能:
|
||||
|
||||
* 快速渲染——Aurelia 宣称比当今其他任何框架的渲染速度都快。
|
||||
* 单向数据流——Aurelia 使用一个基于观察的绑定系统,将数据从模型推送到视图。
|
||||
* 使用 vanilla JavaScript 架构——可以用 vanilla JavaScript 构建网站的所有组件。
|
||||
* 快速渲染 —— Aurelia 宣称比当今其他任何框架的渲染速度都快。
|
||||
* 单向数据流 —— Aurelia 使用一个基于观察的绑定系统,将数据从模型推送到视图。
|
||||
* 使用原生 JavaScript 架构 —— 可以用原生 JavaScript 构建网站的所有组件。
|
||||
|
||||
[Aurelia 的 GitHub][15] 页面显示,截止到撰写本文为止该项目有 788 次提交和 96 位贡献者。
|
||||
|
||||
@ -195,7 +193,7 @@ via: https://opensource.com/article/20/5/open-source-javascript-frameworks
|
||||
作者:[Bryant Son][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[stevending1st](https://github.com/stevending1st)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -4,12 +4,14 @@
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "zepoch"
|
||||
[#]: reviewer: "turbokernel"
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
[#]: publisher: "wxy"
|
||||
[#]: url: "https://linux.cn/article-13595-1.html"
|
||||
|
||||
从实际代码开始编写好的示例
|
||||
======
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202107/18/231616z1hhcerhrk3wzwkr.jpg)
|
||||
|
||||
当编写程序时,我花费了大量时间在编写好的示例上。我从未见过有人写过关于如何写出好的示例,所以我就写了一下如何写出一份好的示例。
|
||||
|
||||
基础思路就是从你写的真实代码开始,然后删除不相关的细节,使其成为一个独立的例子,而不是无中生有地想出一些例子。
|
||||
@ -27,7 +29,7 @@ squares = map(lambda x: x * x, numbers)
|
||||
|
||||
我觉得这个示例不是真实的,有如下两方面的原因:
|
||||
|
||||
* 将一组数字作平方运算不是在真实的程序中完成的事,除非是项目 Euler 或某种东西(更多的可能是针对列表的操作)
|
||||
* 将一组数字作平方运算不是在真实的程序中完成的事,除非是欧拉项目或某种东西(更多的可能是针对列表的操作)
|
||||
* `map` 在 Python 中并不常用,即便是做这个我也更愿意写 `[x*x for x in numbers]`
|
||||
|
||||
一个更加真实的 Python lambdas 的示例是使用 `sort` 函数,就像这样:
|
||||
@ -50,20 +52,19 @@ sorted_children = sorted(children, key=lambda x: x['age'])
|
||||
* `sorted_keysizes = sorted(scores.keys(), key=scores.get)`
|
||||
* `shows = sorted(dates[date], key=lambda x: x['time']['performanceTime'])`
|
||||
|
||||
在这里很容易看到一个规律——这些基本是按时间排序的!因此,您可以明白如何将按时间排序的某些对象(电子邮件、事件等)的简单实例轻松地放在一起。
|
||||
在这里很容易看到一个规律——这些基本是按时间排序的!因此,你可以明白如何将按时间排序的某些对象(电子邮件、事件等)的简单实例轻松地放在一起。
|
||||
|
||||
### 现实的例子有助于"布道"你试图解释的概念
|
||||
### 现实的例子有助于“布道”你试图解释的概念
|
||||
|
||||
当我试图去解释一个想法(就好比 Python Lambdas)的时候,我通常也会试图说服读者,说这是值得学习的想法。Python lambdas 是如此的有用!当我去试图说服某个人 lambdas 是很好用的时候,让他想象一下 lambdas 如何帮助他们完成一项他们将要去做的任务或是以及一项他们以前做过的任务,对说服他会很有帮助。
|
||||
|
||||
### 从真实代码中提炼出示例可能需要很长时间
|
||||
|
||||
|
||||
我给出如何使用 `lambda` 和 `sort` 函数的解释例子是十分简单的,它并不需要花费我很长时间来想出来,但是将真实的代码提炼出为一个独立的示例则是会需要花费很长的时间!
|
||||
|
||||
举个例子,我想在这篇文章中融入一些奇怪的 CSS 行为的例子来说明创造一个奇怪的案例是十分有趣的。我花费了两个小时来解决我这周遇到的一个实际的问题,确保我理解 CSS 的实际情况,并将其变成一个小示例。
|
||||
|
||||
最后,它“仅仅”用了[五行 HTML 和一点点的 CSS][1] 来说明了这个问题,看起来并不想是我花费了好多小时写出来的。但是最初它却是几百行的 JS/CSS/JavaScript,它需要花费很长时间来将所有的代码化为核心的很少的代码。
|
||||
最后,它“仅仅”用了 [五行 HTML 和一点点的 CSS][1] 来说明了这个问题,看起来并不想是我花费了好多小时写出来的。但是最初它却是几百行的 JS/CSS/JavaScript,它需要花费很长时间来将所有的代码化为核心的很少的代码。
|
||||
|
||||
但我认为花点时间把示例讲得非常简单明了是值得的——如果有成百上千的人在读你的示例,你就节省了他们这么多时间!
|
||||
|
||||
@ -74,8 +75,6 @@ sorted_children = sorted(children, key=lambda x: x['age'])
|
||||
* 可以更多的改变人的思维而不是直接提供使用的惊喜读者的示例代码
|
||||
* 易于复制粘贴以用作初始化的示例
|
||||
|
||||
|
||||
|
||||
也许有一天我还会再写一些呢? :)
|
||||
|
||||
--------------------------------------------------------------------------------
|
@ -2,7 +2,7 @@
|
||||
[#]: via: (https://news.itsfoss.com/version-control-writers/)
|
||||
[#]: author: (Theena https://news.itsfoss.com/author/theena/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (piaoshi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,3 +1,4 @@
|
||||
Wlzzzz-del is translating.
|
||||
What's the difference between a fork and a distribution?
|
||||
======
|
||||
|
||||
|
@ -0,0 +1,117 @@
|
||||
[#]: subject: (17 open source technologists share their work-from-home uniforms)
|
||||
[#]: via: (https://opensource.com/article/21/7/work-home-uniforms)
|
||||
[#]: author: (Jen Wike Huger https://opensource.com/users/jen-wike)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
17 open source technologists share their work-from-home uniforms
|
||||
======
|
||||
Nerdwear of the technically employed. What's your style?
|
||||
![Taking a walk outside][1]
|
||||
|
||||
As the world turns and some folks begin returning to the office, I feel it's a good time to ask our community of open source techies: _What's your work-from-home (WFH) uniform?_
|
||||
|
||||
Do you dress like you would if you were going into the office? Or are you more comfortable in workout clothes or even your PJs? Do you have a template you stick to most days?
|
||||
|
||||
I have a format that helps me feel both productive and comfortable, and if I need to run an errand in public, I don't have to change first: A clean, nice-fitting shirt (T-shirts are OK) on top of comfortable pants (yoga is OK but not pajama). I've leaned into my stash of T-shirts from fun conferences I've attended with people I miss seeing and locales in my home state that make me proud.
|
||||
|
||||
Some Opensource.com friends and contributors weigh in on their work-from-home uniforms below. What's yours?
|
||||
|
||||
* * *
|
||||
|
||||
Over the last eight years, I've learned that if I try to work in my PJs, I will get nothing done. In warm weather, I'm in shorts (cargo, of course) and a T-shirt. In cooler weather, it's jeans and a T-shirt with a sweater or hoodie. Never shoes, but I'll wear socks once my feet start getting cold. —[Ben Cotton][2]
|
||||
|
||||
Last winter, I un-ironically told two friends: "I miss my clothes." Most of my wardrobe went untouched for a year, not because I had outgrown or no longer liked my outfits, but because I had nowhere to wear them. Working from home means I'm exercising at least once before, during, or after work. Between walking a (very brisk-paced) dog and taking a class at the gym on my lunch break, I often work in sneakers complete with bike shorts and a tank top. But when the situation calls, I can pop a cardigan on to look more professional. —[Lauren Maffeo][3]
|
||||
|
||||
Before the pandemic, I tried dressing like I was going to do something that day. WFH was a privilege, and I really appreciated it, as it afforded me the ability to take care of my needs and work at the same time. Once the pandemic hit though, it became tiring to put on a front that I was going somewhere because, well, no one was. Most of the time, I'm wearing a Red Hat or Kubernetes/Cloud Native T-shirt and workout shorts. I live in Michigan, though, so those shorts get swapped out for joggers when it's cold. But that's pretty rare given my office is pretty warm thanks to all the computers. Oh, and slippers, like right now because my feet are cold for some reason. —[Chris Short][4]
|
||||
|
||||
My WFW (work from work) uniform was always conference T's, jeans/cargo pants, and sandals or sneakers. So, my wardrobe hasn't changed... Well, that's not exactly true: Having not replenished my supply of conference T's, some of them have become a bit ratty, but I'm not on camera. And my hair is a bit messier. Sidenote: The New York Times had a recent [article][5] on a slide in hygiene and grooming during COVID, and, according to the article, many are saying they're going to remain a bit sloppier post-COVID. —[Kevin Cole][6]
|
||||
|
||||
I used to wear suits and professional woman's wear for the office. Now I get to go back to the tech WFH uniform: nerd shirt, pants/skirt. Often I add a scarf to jazz it up for video. I wear shoes because my feet get cold. My colleagues mock me, but I do my hair and makeup every day. How I missed all my nerdware and hoodies due to "serious non-tech office jobs." —[Heather Leson][7]
|
||||
|
||||
I try to stay dressed at home like there could be a strong reason to go out at short notice with my shoes and go-bag near the door. Too many years living in earthquake country, I guess. —[Stefano Maffulli][8]
|
||||
|
||||
I wear pajamas most of the time, but I keep a "video shirt" ready in case I need to go on video for some reason. For a template, my day is driven by the calls and meetings on my calendar. During my breaks there, I'll run up and down the stairs a few times just to stretch my legs. —[Peter Gervase][9]
|
||||
|
||||
No video meetings for me, but shorts and T-shirts are the regular. Jeans when it's colder. —[Bob Murphy][10]
|
||||
|
||||
I love playing around with color, so I wear five different colored tops (mostly not ironed) for five days, paired with comfortable cotton pants. I love my earrings, so I match my tops and earrings. Every now and then, I do wear my jeans and other formal outfits to make sure that I fit into them. —[Nimisha Mukherjee][11]
|
||||
|
||||
I start my day in gym clothes because I squeeze in a morning workout before I hit the keyboard. My current WFH uniform is a T-shirt or polo and shorts. I try to wear shorts as much as I can when I WFH. In fall and winter, I stick to chamois shirts, fleeces, and jeans. I end my day back in gym clothes because I hit the gym four out of five nights during the week. —[Will Kelly][12]
|
||||
|
||||
My WFH outfit is the same as my office outfit: knit shirts and jeans. Unlike some of my colleagues, I have not grown a beard and let my hair get long and shaggy. A bike racer I knew once said, "You dress like a bum, you ride like a bum," and I feel the same is true for me: "You dress like a bum, you work like a bum." —[Gary Smith][13]
|
||||
|
||||
I learned long ago when I started full-time remote work, that I needed to do the whole "get up, get ready, get dressed like you were going into the office" thing, providing some structure to my day and to get my head in "the right place" for work. Jeans, T-shirt, socks, boots (or shoes, but mostly boots1), and my ever-present head wrap. I don't know about everyone else, but I have a space that is dedicated for work, and I have my EDC2 bag that I take to and from my home office with my personal belongings, the same as I would any other job. When it is time to stop working, I pick up my bag and take it with me as a signal to myself that I'm done for the day. —[Kevin Sonney][14]
|
||||
1 You keep livestock, you wear boots. I'm sure you can guess why.
|
||||
2 "Every-day carry"
|
||||
|
||||
I get up every morning at about the same time, around 7:30am, and get dressed in comfortable, casual clothes. I've been doing this for the last eight years since I retired. I have a light breakfast, and in the summer, I walk between four and five miles. Then I return home and begin my morning routine of juice or tea and toast, then checking email, attending meetings (more on Zoom or other virtual platforms this year). Keeping a routine is important to me, and dressing comfortably is, too. —[Don Watkins][15]
|
||||
|
||||
At one point in my life, I was a chef. So, I have a bunch of chef pants, which are really comfortable but not stylish. I've been wearing them over the winter combined with some of my "ugliest" conference T-shirts. A couple of years ago, a coworker visited Russia and was staying with a family that had a grandmother who loved knitting wool socks. So, he brought wool socks back for everyone. So, ugly chef pants, ugly conference T-shirt, and wool socks hand-knitted by a Russian grandma. —[Craig Sebenik][16]
|
||||
|
||||
My WFH uniform is not much different from my regular outfit. I like to be comfortable, no matter if I'm at home or talking in front of a thousand people at a conference. That means that I'm in T-shirts all around the year, no matter if it's WFH or a large IT event. It's one of the perks of being an engineer, not in sales or management. The only difference is that I wear jeans in public and something more comfortable, like sports pants, at home. —[Peter Czanik][17]
|
||||
|
||||
It has been at least 30 years since I wore suits, then (for a while) "business casual." Most days now, I start early in my jammies. Wednesdays, I start with my yoga pants and top because my online yoga class starts at 9:30. Other days I change into jeans or cargo shorts and a solid black, conference, or other geeky T-shirt after breakfast. I always shave because that is one thing that makes me feel civilized. I am "retired," so I don't feel any need at all to have a different video presence other than my "normal" mode of dress. Besides, the only video meetings I attend are the Opensource.com and Enable Sysadmin weekly writer calls. —[David Both][18]
|
||||
|
||||
The only rule is there are no rules! I wear whatever I want, mostly a Red Hat T-shirt and shorts or jogging pants. If I have an important meeting, I try to be more presentable. —[Kedar Vijay Kulkarni][19]
|
||||
|
||||
Before walking the dogs, I am in sleepwear and a dressing gown while eating toast and having that first coffee. After the dog walk, I'm in shorts/polo/T-shirt if it's warm enough, or jeans/cargo pants if it's colder. I tend towards classic Shadowman shirts if I'm not on customer calls or major internal briefings, and the newer Red Hat logo-based shirts if I need official branding. Sadly, we're heading into winter here in New Zealand, so hoodies and jeans are starting to become a bit more normal. For my 3am calls with the United States, I've got a snug dressing gown and a warm drink. —[Steven Ellis][20]
|
||||
|
||||
Thanks to the Opensource.com Correspondent program, here's my Spring, Summer, Fall, and Winter uniform. —[Chris Hermansen][21]
|
||||
|
||||
![Opensource.com swag, a spring outfit][22]
|
||||
|
||||
|
||||
|
||||
![Opensource.com swag, a winter outfit][23]
|
||||
|
||||
|
||||
|
||||
![Opensource.com swag, a summer outfit][24]
|
||||
|
||||
Summer
|
||||
|
||||
* * *
|
||||
|
||||
What's your WFH uniform? Are you in a T-shirt and pajama pants, or do you dress as if you're going into the office? Please share your remote work attire in the comments below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/7/work-home-uniforms
|
||||
|
||||
作者:[Jen Wike Huger][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jen-wike
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/walking_selfcare_wfh_outside_520.png?itok=64WmWspJ (Taking a walk outside)
|
||||
[2]: https://opensource.com/users/bcotton
|
||||
[3]: https://opensource.com/users/lmaffeo
|
||||
[4]: https://opensource.com/users/chrisshort
|
||||
[5]: https://www.nytimes.com/2021/05/06/health/shower-bathing-pandemic.html
|
||||
[6]: https://opensource.com/users/kjcole
|
||||
[7]: https://opensource.com/users/hleson
|
||||
[8]: https://opensource.com/users/reed
|
||||
[9]: https://opensource.com/users/pgervase
|
||||
[10]: https://opensource.com/users/murph
|
||||
[11]: https://opensource.com/users/nimisha
|
||||
[12]: https://opensource.com/users/willkelly
|
||||
[13]: https://opensource.com/users/greptile
|
||||
[14]: https://opensource.com/users/ksonney
|
||||
[15]: https://opensource.com/users/don-watkins
|
||||
[16]: https://opensource.com/users/craig5
|
||||
[17]: https://opensource.com/users/czanik
|
||||
[18]: https://opensource.com/users/dboth
|
||||
[19]: https://opensource.com/users/kkulkarn
|
||||
[20]: https://opensource.com/users/steven-ellis
|
||||
[21]: https://opensource.com/users/clhermansen
|
||||
[22]: https://opensource.com/sites/default/files/uploads/spring_2.jpg (Opensource.com swag, a spring outfit)
|
||||
[23]: https://opensource.com/sites/default/files/uploads/winter.jpg (Opensource.com swag, a winter outfit)
|
||||
[24]: https://opensource.com/sites/default/files/uploads/summer.jpg (Opensource.com swag, a summer outfit)
|
163
sources/talk/20210718 Is Open-Source Software Secure.md
Normal file
163
sources/talk/20210718 Is Open-Source Software Secure.md
Normal file
@ -0,0 +1,163 @@
|
||||
[#]: subject: (Is Open-Source Software Secure?)
|
||||
[#]: via: (https://news.itsfoss.com/open-source-software-security/)
|
||||
[#]: author: (Ankush Das https://news.itsfoss.com/author/ankush/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
Is Open-Source Software Secure?
|
||||
======
|
||||
|
||||
Being someone who prefers [Linux for desktop][1] and encourages using open-source software, you may expect the answer to the question raised in the headline with a big “**Yes**“.
|
||||
|
||||
But I am not going to limit discussing the benefits of open-source software. Let us explore more!
|
||||
|
||||
Here, I plan to share my thoughts on if open-source software is secure and what are the things involved in it that make secure or insecure.
|
||||
|
||||
### Why Should You Care if Open-Source Software is Secure?
|
||||
|
||||
No matter whether you use [Linux][2] or any other operating system, you will be surrounded with open-source software in some way (directly/indirectly).
|
||||
|
||||
To give you an example, most of the proprietary software tools depend on some form of open-source libraries to make things work.
|
||||
|
||||
Furthermore, there is a reason why companies of various scale (including Google, Microsoft, and Facebook) rely on open-source software or contribute their resources to the open-source community in one way or the other.
|
||||
|
||||
Hence, the security of open-source software is something essential to know about.
|
||||
|
||||
### Myths About Open-Source Software Security
|
||||
|
||||
![][3]
|
||||
|
||||
While there are several arguments to pitch the cons of open-source software in terms of security, some of them just do not make any sense.
|
||||
|
||||
#### Anyone Can See & Exploit the Code
|
||||
|
||||
The code is accessible to everyone, yes. But just because you can see the code—does that mean anyone can exploit it?
|
||||
|
||||
**Not really.**
|
||||
|
||||
Even though anyone can create a fork (or copy) of the software, the original software cannot be manipulated easily.
|
||||
|
||||
Usually, the project maintainer (or a group of them) manage the code repository and accept the commits from contributors. The code is reviewed before approval. And no one can hijack the code just like that.
|
||||
|
||||
**It takes effort for an attacker to exploit a vulnerability or add malicious code in a software, no matter if it is open-source or closed source.**
|
||||
|
||||
#### Without Dedicated Resources, Security Breaks down
|
||||
|
||||
Many believe that without dedicated employees or a team for an open-source software, it is difficult to maintain security.
|
||||
|
||||
In contrast, with several types of contributors joining and leaving, the software gets more attention from a wide range of developers.
|
||||
|
||||
And they may be able to spot security issues better than a few employees assigned for a proprietary software.
|
||||
|
||||
Some projects from the likes of Mozilla have a dedicated team to effectively iron out security issues. Similarly, most of the successful open source projects have plenty of resources to dedicate for security.
|
||||
|
||||
Hence, the open-source software ecosystem is a mixed bag for security. Even without dedicated resources, the projects get help from various contributors, and some are profitable to a great extent which helps them dedicate more resources.
|
||||
|
||||
### Open Source Software is Secure: Here’s How
|
||||
|
||||
![][3]
|
||||
|
||||
Now that we have tackled the myths, let me highlight how open-source software deals with security issues.
|
||||
|
||||
In other words, the benefits in security with open-source software.
|
||||
|
||||
Not to forget, the perks of open-source software translate to some of the reasons why [Linux is better than Windows][4].
|
||||
|
||||
#### More Eyes Looking at the Code
|
||||
|
||||
Unlike a proprietary software, access to code is not limited to a few developers.
|
||||
|
||||
Some projects may even have thousands of developers watching the code, reviewing them, and flagging or fixing security issues.
|
||||
|
||||
And this gives an edge over closed-source software by having **the ability to identify issues quickly and addressing them as soon as possible.**
|
||||
|
||||
Not just limited to more developers, often enterprises get involved with open-source projects that they utilize. And when they do, they will also go through the code and review it.
|
||||
|
||||
This gives another source of external audit that may help improve the security of the software.
|
||||
|
||||
In contrast, with a closed-source software, a limited number of developers may not be able to find all kinds of security issues. And it may take them longer to fix all the issues one by one.
|
||||
|
||||
#### Community Decision Making to Prioritize Security Issues
|
||||
|
||||
The developers of a closed-source software may have certain restrictions and priorities as what to work on and when to resolve an issue.
|
||||
|
||||
However, in case of an open-source project, the community of contributors can prioritize and assign themselves what they want to work on and when to fix an issue. You do not need to depend on a vendor or follow their instructions to address a security issue.
|
||||
|
||||
The decision making that goes into addressing and fixing the security issues is more transparent and flexible in case of an open-source software. Hence, it can prove to be more effective leaving you with three specific benefits:
|
||||
|
||||
* **Transparency**
|
||||
* **No dependency on the vendor**
|
||||
* **Faster security updates**
|
||||
|
||||
|
||||
|
||||
### Open Source Software is not Bulletproof: Here’s Why
|
||||
|
||||
![][3]
|
||||
|
||||
While there are cases where open-source software may get an edge for security, there could be instances or factors that affects it.
|
||||
|
||||
It is important to acknowledge that these problems exist, accordingly, an enterprise or an individual can make better decision about the state of security for an open-source software.
|
||||
|
||||
#### Not enough Eyes to Review Code and Uncertainty
|
||||
|
||||
Even if the code is accessible the world of developers, there are chances that a **project does not have enough contributors/developers to thoroughly review the code**.
|
||||
|
||||
In that case, we cannot have great confidence of an open-source software being peer-reviewed, because it lacks exactly that.
|
||||
|
||||
The open-source software may “claim” to have the best security just because its open-source, which is misleading when there are not enough developers working on it.
|
||||
|
||||
Also, we do not know how many developers are looking/reviewing the code and how exactly the code walkthrough is going on.
|
||||
|
||||
For instance, the Heartbleed bug was spotted after 2 years of its introduction in a project that was already popular i.e **OpenSSL**.
|
||||
|
||||
#### Software Responsibility or Accountability
|
||||
|
||||
This may not be important for individuals, but an **open-source software often comes with no warranties**.
|
||||
|
||||
So, if a business uses it, they must take the responsibility of any losses or damages caused by the use of that software.
|
||||
|
||||
This is something that tells you that nothing can be 100% secure and bug-free. No matter how many eyes you have on a code, or how skilled the contributors are, there will be risks in some form, be it security or data loss.
|
||||
|
||||
And this brings us to the fact that open-source software is not bulletproof.
|
||||
|
||||
### Open Source May Have its Edge for Better Security But…
|
||||
|
||||
Nothing is superior when it comes to security. No matter if it is closed-source or open-source, the same set of principles apply when it comes to security.
|
||||
|
||||
There are various external factors that can affect the security of a software, and **many of those are not source dependent**.
|
||||
|
||||
The code must be monitored in the same way to keep things secure.
|
||||
|
||||
Yes, the **open-source approach introduces benefits that closed-source software will never have**, but that does not mean that it is bulletproof.
|
||||
|
||||
_What do you think about the state of security when it comes to open-source software?_ _Do you think it is superior to proprietary solutions?_
|
||||
|
||||
I would appreciate your valuable thoughts in the comments down below.
|
||||
|
||||
#### Big Tech Websites Get Millions in Revenue, It's FOSS Got You!
|
||||
|
||||
If you like what we do here at It's FOSS, please consider making a donation to support our independent publication. Your support will help us keep publishing content focusing on desktop Linux and open source software.
|
||||
|
||||
I'm not interested
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://news.itsfoss.com/open-source-software-security/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://news.itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://news.itsfoss.com/linux-foundation-linux-desktop/
|
||||
[2]: https://itsfoss.com/what-is-linux-distribution/
|
||||
[3]: data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjQzOSIgd2lkdGg9Ijc4MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiLz4=
|
||||
[4]: https://itsfoss.com/linux-better-than-windows/
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (tanloong)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,134 +0,0 @@
|
||||
[#]: subject: (How to get KDE Plasma 5.22 in Kubuntu 21.04 Hirsute Hippo)
|
||||
[#]: via: (https://www.debugpoint.com/2021/06/plasma-5-22-kubuntu-21-04/)
|
||||
[#]: author: (Arindam https://www.debugpoint.com/author/admin1/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
How to get KDE Plasma 5.22 in Kubuntu 21.04 Hirsute Hippo
|
||||
======
|
||||
The KDE team enabled the backports PPA which you can use to install and
|
||||
upgrade to KDE Plasma 5.22 in Kubuntu 21.04 Hirsute Hippo._This guide
|
||||
outlines the following topics_ppa:kubuntu-ppa/backports
|
||||
![Kubnutu 21.04 running with KDE Plasma 5.22][1]
|
||||
|
||||
KDE team released the KDE Plasma 5.22 recently with a fair amount of enhancements, bug fixes along with updated KDE Framework and applications versions. This release brings several improvements such as Adaptive transparency in panels, user-friendly notification on file operation popups, package type display in Discover, various Wayland changes, and more. Check out more details about features [here][2].
|
||||
|
||||
If you are running Kubuntu 21.04 Hirsute Hippo Or, have a custom KDE Plasma installed in [Ubuntu 21.04 Hisrsute Hippo][3], you can upgrade to the latest version using the following steps. The current Hirsute Hippo series provides the prior versions of KDE Plasma 5.21.04 with KDE Framework 5.80.
|
||||
|
||||
:
|
||||
|
||||
1. [How to install KDE Plasma 5.22 in Kubuntu 21.04][4]
|
||||
2. [How to install KDE Plasma 5.22 in Ubuntu 21.04 alongside GNOME][5]
|
||||
3. [Can I install KDE Plasma 5.22 in Ubuntu 20.04 LTS?][6]
|
||||
4. [How to Uninstall][7]
|
||||
|
||||
|
||||
|
||||
### Install KDE Plasma 5.22 in Kubuntu 21.04 Hirsute Hippo – Steps
|
||||
|
||||
Follow the below steps.
|
||||
|
||||
If you want to use the graphical method, then add to the software sources in Discover and hit Update.
|
||||
|
||||
Or, use the following terminal method for faster installation.
|
||||
|
||||
* **Step 1**: Open a terminal and add below KDE Backports PPA.
|
||||
|
||||
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:kubuntu-ppa/backports
|
||||
```
|
||||
|
||||
* **Step 2**: Then run the following to initiate a system upgrade. This will install the latest KDE Plasma 5.22 in your Hirsute Hippo system.
|
||||
|
||||
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
sudo apt full-upgrade
|
||||
```
|
||||
|
||||
![Upgrade to Plasma 5.22][8]
|
||||
|
||||
* **Step 3**: Reboot after the update and you should be greeted with an updated KDE Plasma 5.22 desktop.
|
||||
|
||||
|
||||
|
||||
The installation may take some time considering a complete version upgrade of the entire desktop environment.
|
||||
|
||||
### Installing KDE Plasma 5.22 in Ubuntu 21.04
|
||||
|
||||
If you are running GNOME based default Ubuntu 21.04 Hirsute Hippo desktop, you can use this PPA to install the latest KDE Plasma. Here’s how.
|
||||
|
||||
[][9]
|
||||
|
||||
SEE ALSO: Lubuntu 21.04 Hirsute Hippo - Artwork Contest is Here
|
||||
|
||||
Open a terminal and add the PPA (like above steps).
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:kubuntu-ppa/backports
|
||||
```
|
||||
|
||||
Then, refresh the packages.
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
Then run the below to install the Kubuntu desktop.
|
||||
|
||||
```
|
||||
sudo apt install kubuntu-desktop
|
||||
```
|
||||
|
||||
This will install the KDE Plasma desktop alongside with GNOME in Ubuntu 21.04.
|
||||
|
||||
### KDE Plasma 5.22 in Ubuntu 20.04 LTS
|
||||
|
||||
Ubuntu 20.04 LTS edition has the earlier KDE Plasma 5.18, KDE Framework 5.68, KDE Applications 19.12.3. So, during its entire lifecycle, it would not receive the latest KDE Update. So, technically you can add the above PPA and install the KDE Plasma 5.22. But I would not recommend it due to incompatible packages, frameworks that may lead to an unstable system.
|
||||
|
||||
So, it is recommended that you use either Kubuntu 21.04 with the above backports PPA Or, use KDE neon to experience the latest Plasma desktop.
|
||||
|
||||
### Uninstallation of KDE Plasma 5.22
|
||||
|
||||
If you change your mind and want to go back to the stock version of the KDE Plasma, then install the ppa-purge and purge the PPA. This will downgrade packages and make the stock version available.
|
||||
|
||||
```
|
||||
sudo apt install ppa-purge
|
||||
sudo ppa-purge ppa:kubuntu-ppa/backports
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
### Closing Notes
|
||||
|
||||
I hope this quick guide helped you to install the latest KDE Plasma 5.22 in Kubuntu 21.04 Hirsute Hippo. This allows you experience the latest KDE technology coupled with KDE Framework and applications. However, you should be aware that not all the features should be made available in the backports PPA – only the selected features and bug fixes that pass regression and safe to use. That said, you can always install KDE Neon as a fresh system to enjoy the latest tech from KDE.
|
||||
|
||||
* * *
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/2021/06/plasma-5-22-kubuntu-21-04/
|
||||
|
||||
作者:[Arindam][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.debugpoint.com/author/admin1/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.debugpoint.com/blog/wp-content/uploads/2021/06/Kubutu-21.04-running-with-KDE-Plasma-5.22-1024x531.jpg
|
||||
[2]: https://www.debugpoint.com/2021/06/kde-plasma-5-22-release/
|
||||
[3]: https://www.debugpoint.com/2021/04/ubuntu-21-04-hirsute-hippo-release/
|
||||
[4]: tmp.wazjcS11If#plasma-kubuntu-2104
|
||||
[5]: tmp.wazjcS11If#plasma-ubuntu-2104
|
||||
[6]: tmp.wazjcS11If#plasma-ubuntu-2004
|
||||
[7]: tmp.wazjcS11If#uninstall-stock-version
|
||||
[8]: https://www.debugpoint.com/blog/wp-content/uploads/2021/06/Upgrade-to-Plasma-5.22.jpg
|
||||
[9]: https://www.debugpoint.com/2020/12/lubuntu-21-04-artwork/
|
@ -1,135 +0,0 @@
|
||||
[#]: subject: (Hash Linux: Arch Linux Preconfigured With Xmonad, Awesome, i3, and Bspwm Window Manager)
|
||||
[#]: via: (https://itsfoss.com/hash-linux-review/)
|
||||
[#]: author: (Sarvottam Kumar https://itsfoss.com/author/sarvottam/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (mcfd)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
Hash Linux: Arch Linux Preconfigured With Xmonad, Awesome, i3, and Bspwm Window Manager
|
||||
======
|
||||
|
||||
With some effort, [you can install Arch Linux][1]. You may also install a desktop environment or windows manager of your choice on your Arch system.
|
||||
|
||||
That takes some time and effort but it is surely achievable. However, there exists projects that try to ease the pain by providing you a system preconfigured with a desktop environment or window manager of your choice. [ArcoLinux][2] is one such example.
|
||||
|
||||
Recently, I came across another project that has its sole focus on providing choice of window managers on top of the wonderful Arch distribution.
|
||||
|
||||
[Hash Project][3] offers four preconfigured Arch variants with tiling window managers: Awesome, [Xmonad][4], i3, and Bspwm.
|
||||
|
||||
If you’re a beginner window manager hopper, the Hash project is what you should definitely try at once. Without investing time to configure it first, you can explore the potential of window managers and get used to keyboard-driven systems.
|
||||
|
||||
In this article, I’ll discuss my part of the experience with the **Hash Linux Xmonad edition** featuring Linux kernel 5.12.
|
||||
|
||||
### Installation Of Hash Linux
|
||||
|
||||
The ISO image of all four editions of Hash Linux is available to [download][5] for x86_64 system architecture.
|
||||
|
||||
To avoid any unexpected error while installing it on a bare system, I created a virtual machine of Hash Linux Xmonad version in GNOME Boxes.
|
||||
|
||||
As I booted into Hash Linux, I noticed two things. First, a panel providing important shortcuts for managing windows and commands. I’ll discuss it later after installation. Second, a beautiful and easy-to-use GUI installer.
|
||||
|
||||
![Hash Linux GUI Installer][6]
|
||||
|
||||
As usual, the graphical installer made the installation process very smooth by providing buttons to click on. Within a few steps of configuration, Hash Linux was installed and ready to reboot.
|
||||
|
||||
![Installer Welcome Page][7]
|
||||
|
||||
### First Impression
|
||||
|
||||
![Hash Linux][8]
|
||||
|
||||
If you’ve ever installed Xmonad window manager on your Linux system, what is the first thing you saw after reboot? Blank screen right.
|
||||
|
||||
And if you’re a beginner or you don’t know the default key binding, you get stuck on the same screen. Hence, you must have to read keyboard shortcuts first before using any window manager.
|
||||
|
||||
What if you get all the important shortcuts right on your window? A cheat sheet can save you a lot of time.
|
||||
|
||||
Therefore, for the sake of simplicity and beginner-friendly, Hash Linux has pinned important keys on the desktop window.
|
||||
|
||||
So, let’s try some of it first. Starting with one of the most important `[Super]+Enter`, it opens the default termite terminal emulator with Z shell (ZSH).
|
||||
|
||||
If you click it multiple times, you notice that by default Xmonad follows a dwindle layout where it first fixes one window on the right side and then arranges the rest of all on the left side in the same manner.
|
||||
|
||||
![Xmonad default layout][9]
|
||||
|
||||
Using `[Super]+[Space]`, you can also change the current layout to a tabbed one. Even you can use `[Super]+[left+click]` to move a window into a float mode.
|
||||
|
||||
![Moved to float][10]
|
||||
|
||||
To quit the currently focussed window, you can press `[Super]+Q`.
|
||||
|
||||
### Applications In Hash Linux
|
||||
|
||||
By default, Hash Linux contains several useful command-line tools such as NeoFetch, Htop, Vim, Pacman, Git, and Speedtest-cli.
|
||||
|
||||
![Htop][11]
|
||||
|
||||
It also has a good amount of graphical applications such as Firefox 89, Gparted, Nitrogen, Conky, Flameshot, Geany, and CPU-X.
|
||||
|
||||
`[Super]+D` is the default key in Hash Linux to open application search menu.
|
||||
|
||||
![Application search menu][12]
|
||||
|
||||
### Theming
|
||||
|
||||
Hash Cyan is the default theme in Hash Linux. Besides it, Hash Linux provides four more themes: Light Orange, Sweet Purple, Night Red, and Arch Dark.
|
||||
|
||||
Hash Theme Selector is a home-baked Hash Linux application that you can use to configure the theme for a window manager.
|
||||
|
||||
![Hash Theme Selector][13]
|
||||
|
||||
### Upgrading Hash Linux
|
||||
|
||||
Being a rolling release distribution, you don’t need to download a new ISO of Hash Linux to update the existing system. The only thing you need to upgrade your system is to run `upgrade` command in a terminal.
|
||||
|
||||
![upgrading hash linux][14]
|
||||
|
||||
### Closing Thought
|
||||
|
||||
If you want to use a window manager instead of the desktop environment but do not want to spend a lot of time configuring it, Hash project saves the day.
|
||||
|
||||
First, it will save you a lot of time and effort for configuration, and second, it will easily make you comfortable in using a keyboard-driven system. Later, you can definitely learn to configure according to your own needs.
|
||||
|
||||
As Hash Linux already provides four ISO with the different window managers, you can start using any version and find your favorite one. Overall, it is a [good Arch-based Linux distribution][15].
|
||||
|
||||
At last, I would also like to mention that the current official [site][3] of Hash Linux does not contain much information about it.
|
||||
|
||||
![][16]
|
||||
|
||||
An earlier [site][17] (not accessible to me now) that also mentioned in the release info, contained information about it including configuration details when I checked last time.
|
||||
|
||||
Don’t want to go the Arch way just for tiling window manager? Try [Regolith Linux][18]. It is Ubuntu preconfigured with i3wm. Awesome, right?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/hash-linux-review/
|
||||
|
||||
作者:[Sarvottam Kumar][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/sarvottam/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/install-arch-linux/
|
||||
[2]: https://arcolinux.com/
|
||||
[3]: https://hashproject.ga/
|
||||
[4]: https://xmonad.org/
|
||||
[5]: https://hashproject.ga/index.html#downloads
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Linux-GUI-Installer.jpg?resize=800%2C451&ssl=1
|
||||
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/06/Installer-Welcome-Page.png?resize=800%2C452&ssl=1
|
||||
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Linux.jpg?resize=800%2C451&ssl=1
|
||||
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/Xmonad-default-layout.png?resize=800%2C452&ssl=1
|
||||
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Moved-to-float.png?resize=800%2C452&ssl=1
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Htop.jpg?resize=800%2C451&ssl=1
|
||||
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/Application-search-menu.jpg?resize=800%2C451&ssl=1
|
||||
[13]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Theme-Selector.png?resize=800%2C452&ssl=1
|
||||
[14]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/06/Upgrading-hash-linux.png?resize=800%2C452&ssl=1
|
||||
[15]: https://itsfoss.com/arch-based-linux-distros/
|
||||
[16]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Linux-Site-URL.png?resize=575%2C193&ssl=1
|
||||
[17]: https://hashproject.org/
|
||||
[18]: https://itsfoss.com/regolith-linux-desktop/
|
@ -1,284 +0,0 @@
|
||||
[#]: subject: (How different programming languages read and write data)
|
||||
[#]: via: (https://opensource.com/article/21/7/programming-read-write)
|
||||
[#]: author: (Alan Smithee https://opensource.com/users/alansmithee)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
How different programming languages read and write data
|
||||
======
|
||||
Every programming language has a unique way of accomplishing a task;
|
||||
that's why there are so many languages to choose from.
|
||||
![Code going into a computer.][1]
|
||||
|
||||
In his article _[How different programming languages do the same thing][2]_, Jim Hall demonstrates how 13 different languages accomplish the same exact task with different syntax. The lesson is that programming languages tend to have many similarities, and once you know one programming language, you can learn another by figuring its syntax and structure.
|
||||
|
||||
In the same spirit, Jim's article compares how different programming languages read and write data. Whether that data comes from a configuration file or from a file a user creates, processing data on a storage device is a common task for coders. It's not practical to cover all programming languages in this way, but a recent Opensource.com series provides insight into different approaches taken by these coding languages:
|
||||
|
||||
* [C][3]
|
||||
* [C++][4]
|
||||
* [Java][5]
|
||||
* [Groovy][6]
|
||||
* [Lua][7]
|
||||
* [Bash][8]
|
||||
* [Python][9]
|
||||
|
||||
|
||||
|
||||
### Reading and writing data
|
||||
|
||||
The process of reading and writing data with a computer is similar to how you read and write data in real life. To access data in a book, you first open it, then you read words or you write new words into the book, and then you close the book.
|
||||
|
||||
When your code needs to read data from a file, you provide your code with a file location, and then the computer brings that data into its RAM and parses it from there. Similarly, when your code needs to write data to a file, the computer places new data into the system's in-memory write buffer and synchronizes it to the file on the storage device.
|
||||
|
||||
Here's some pseudo-code for these operations:
|
||||
|
||||
1. Load a file in memory.
|
||||
2. Read the file's contents, or write data to the file.
|
||||
3. Close the file.
|
||||
|
||||
|
||||
|
||||
### Reading data from a file
|
||||
|
||||
You can see three trends in how the languages in the Opensource.com series read files.
|
||||
|
||||
#### C
|
||||
|
||||
In C, opening a file can involve retrieving a single character (up to the `EOF` designator, signaling the end of the file) or a block of data, depending on your requirements and approach. It can feel like a mostly manual process, depending on your goal, but the general process is exactly what the other languages mimic.
|
||||
|
||||
|
||||
```
|
||||
FILE *infile;
|
||||
int ch;
|
||||
|
||||
infile = [fopen][10](argv[1], "r");
|
||||
|
||||
do {
|
||||
ch = [fgetc][11](infile);
|
||||
if (ch != EOF) {
|
||||
[printf][12]("%c", ch);
|
||||
}
|
||||
} while (ch != EOF);
|
||||
|
||||
[fclose][13](infile);
|
||||
```
|
||||
|
||||
You can also choose to load some portion of a file into the system buffer and then work out of the buffer.
|
||||
|
||||
|
||||
```
|
||||
FILE *infile;
|
||||
char buffer[300];
|
||||
|
||||
infile = [fopen][10](argv[1], "r");
|
||||
|
||||
while (![feof][14](infile)) {
|
||||
size_t buffer_length;
|
||||
buffer_length = [fread][15](buffer, sizeof(char), 300, infile);
|
||||
}
|
||||
|
||||
[printf][12]("%s", buffer);
|
||||
[fclose][13](infile);
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
C++ simplifies a few steps, allowing you to parse data as strings.
|
||||
|
||||
|
||||
```
|
||||
std::string sFilename = "example.txt";
|
||||
|
||||
std::ifstream fileSource(sFilename);
|
||||
std::string buffer;
|
||||
|
||||
while (fileSource >> buffer) {
|
||||
std::cout << buffer << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
Java and Groovy are similar to C++. They use a class called `Scanner` to set up a data object or stream containing the contents of the file of your choice. You can "scan" through the file by tokens (byte, line, integer, and many others).
|
||||
|
||||
|
||||
```
|
||||
[File][16] myFile = new [File][16]("example.txt");
|
||||
|
||||
Scanner myScanner = new Scanner(myFile);
|
||||
while (myScanner.hasNextLine()) {
|
||||
[String][17] line = myScanner.nextLine();
|
||||
[System][18].out.println(line);
|
||||
}
|
||||
|
||||
myScanner.close();
|
||||
```
|
||||
|
||||
#### Groovy
|
||||
|
||||
|
||||
```
|
||||
def myFile = new [File][16]('example.txt')
|
||||
|
||||
def myScanner = new Scanner(myFile)
|
||||
while (myScanner.hasNextLine()) {
|
||||
def line = myScanner.nextLine()
|
||||
println(line)
|
||||
}
|
||||
|
||||
myScanner.close()
|
||||
```
|
||||
|
||||
#### Lua
|
||||
|
||||
Lua and Python abstract the process further. You don't have to consciously create a data stream; you just assign a variable to the results of an `open` function and then parse the contents of the variable. It's quick, minimal, and easy.
|
||||
|
||||
|
||||
```
|
||||
myFile = io.open('example.txt', 'r')
|
||||
|
||||
lines = myFile:read("*all")
|
||||
print(lines)
|
||||
|
||||
myFile:close()
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
|
||||
```
|
||||
f = open('example.tmp', 'r')
|
||||
|
||||
for line in f:
|
||||
print(line)
|
||||
|
||||
f.close()
|
||||
```
|
||||
|
||||
### Writing data to a file
|
||||
|
||||
In terms of code, writing is the inverse of reading. As such, the process for writing data to a file is basically the same as reading data from a file, except using different functions.
|
||||
|
||||
#### C
|
||||
|
||||
In C, you can write a character to a file with the `fputc` function.
|
||||
|
||||
|
||||
```
|
||||
`fputc(ch, outfile);`
|
||||
```
|
||||
|
||||
Alternately, you can write data to the buffer with `fwrite`.
|
||||
|
||||
|
||||
```
|
||||
`fwrite(buffer, sizeof(char), buffer_length, outfile);`
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
Because C++ uses the `ifstream` library to open a buffer for data, you can write data to the buffer, as with C (except with C++ libraries).
|
||||
|
||||
|
||||
```
|
||||
`std::cout << buffer << std::endl;`
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
In Java, you can use the `FileWriter` class to create a data object that you can write data to. It works a lot like the `Scanner` class, except going the other way.
|
||||
|
||||
|
||||
```
|
||||
[FileWriter][19] myFileWriter = new [FileWriter][19]("example.txt", true);
|
||||
myFileWriter.write("Hello world\n");
|
||||
myFileWriter.close();
|
||||
```
|
||||
|
||||
#### Groovy
|
||||
|
||||
Similarly, Groovy uses `FileWriter` but with a slightly "groovier" syntax.
|
||||
|
||||
|
||||
```
|
||||
new [FileWriter][19]("example.txt", true).with {
|
||||
write("Hello world\n")
|
||||
flush()
|
||||
}
|
||||
```
|
||||
|
||||
#### Lua
|
||||
|
||||
Lua and Python are similar, both using functions called `open` to load a file, `write` to put data into it, and `close` to close the file.
|
||||
|
||||
|
||||
```
|
||||
myFile = io.open('example.txt', 'a')
|
||||
io.output(myFile)
|
||||
io.write("hello world\n")
|
||||
io.close(myFile)
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
|
||||
```
|
||||
myFile = open('example.txt', 'w')
|
||||
myFile.write('hello world')
|
||||
myFile.close()
|
||||
```
|
||||
|
||||
### File modes
|
||||
|
||||
Many languages specify a "mode" when opening files. Modes vary, but this is common notation:
|
||||
|
||||
* **w** to write
|
||||
* **r** to read
|
||||
* **r+** to read and write
|
||||
* **a** to append only
|
||||
|
||||
|
||||
|
||||
Some languages, such as Java and Groovy, let you determine the mode based on which class you use to load the file.
|
||||
|
||||
Whichever way your programming language determines a file's mode, it's up to you to ensure that you're _appending_ data—unless you intend to overwrite a file with new data. Programming languages don't have built-in prompts to warn you against data loss, the way file choosers do.
|
||||
|
||||
### New language and old tricks
|
||||
|
||||
Every programming language has a unique way of accomplishing a task; that's why there are so many languages to choose from. You can and should choose the language that works best for you. But once you understand the basic constructs of programming, you can also feel free to try out different languages, without fear of not knowing how to accomplish basic tasks. More often than not, the pathways to a goal are similar, so they're easy to learn as long as you keep the basic concepts in mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/7/programming-read-write
|
||||
|
||||
作者:[Alan Smithee][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alansmithee
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82 (Code going into a computer.)
|
||||
[2]: https://opensource.com/article/21/4/compare-programming-languages
|
||||
[3]: https://opensource.com/article/21/3/file-io-c
|
||||
[4]: https://opensource.com/article/21/3/ccc-input-output
|
||||
[5]: https://opensource.com/article/21/3/io-java
|
||||
[6]: https://opensource.com/article/21/4/groovy-io
|
||||
[7]: https://opensource.com/article/21/3/lua-files
|
||||
[8]: https://opensource.com/article/21/3/input-output-bash
|
||||
[9]: https://opensource.com/article/21/6/reading-and-writing-files-python
|
||||
[10]: http://www.opengroup.org/onlinepubs/009695399/functions/fopen.html
|
||||
[11]: http://www.opengroup.org/onlinepubs/009695399/functions/fgetc.html
|
||||
[12]: http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
|
||||
[13]: http://www.opengroup.org/onlinepubs/009695399/functions/fclose.html
|
||||
[14]: http://www.opengroup.org/onlinepubs/009695399/functions/feof.html
|
||||
[15]: http://www.opengroup.org/onlinepubs/009695399/functions/fread.html
|
||||
[16]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+file
|
||||
[17]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
||||
[18]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
||||
[19]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+filewriter
|
@ -2,7 +2,7 @@
|
||||
[#]: via: (https://fedoramagazine.org/apps-for-daily-needs-part-1-web-browsers/)
|
||||
[#]: author: (Arman Arisman https://fedoramagazine.org/author/armanwu/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -0,0 +1,127 @@
|
||||
[#]: subject: (How to get KDE Plasma 5.22 in Kubuntu 21.04 Hirsute Hippo)
|
||||
[#]: via: (https://www.debugpoint.com/2021/06/plasma-5-22-kubuntu-21-04/)
|
||||
[#]: author: (Arindam https://www.debugpoint.com/author/admin1/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
如何在 Kubuntu 21.04 Hirsute Hippo 中获得 KDE Plasma 5.22
|
||||
======
|
||||
KDE 团队启用了向后移植 PPA,你可以使用它在 Kubuntu 21.04 Hirsute Hippo 中安装和升级到 KDE Plasma 5.22。
|
||||
![Kubnutu 21.04 running with KDE Plasma 5.22][1]
|
||||
|
||||
KDE 团队最近发布了 KDE Plasma 5.22,其中有相当多的增强功能、错误修复以及更新的 KDE 框架和应用版本。这个版本带来了一些改进,如面板的自适应透明度,文件操作弹出时的用户友好通知,“发现”中的软件包类型显示,各种 Wayland 的变化等。在[这里][2]查看更多关于功能细节。
|
||||
|
||||
如果你正在运行 Kubuntu 21.04 Hirsute Hippo 或者,在 [Ubuntu 21.04 Hisrsute Hippo][3] 中安装了自定义的 KDE Plasma,你可以通过以下步骤升级到最新版本。目前的 Hirsute Hippo 系列提供了 KDE Plasma 5.21.04 与 KDE Framework 5.80 的先前版本。
|
||||
|
||||
本指南包含下列主题:
|
||||
|
||||
1. [如何在 Kubuntu 21.04 中安装 KDE Plasma 5.22][4]
|
||||
2. [如何在 Ubuntu 21.04 中与 GNOME 一起安装 KDE Plasma 5.22][5]
|
||||
3. [我可以在 Ubuntu 20.04 LTS 中安装 KDE Plasma 5.22 么][6]
|
||||
4. [如何卸载][7]
|
||||
|
||||
|
||||
|
||||
### 在 Kubuntu 21.04 Hirsute Hippo 中安装 KDE Plasma 5.22 的步骤
|
||||
|
||||
按照下面的步骤进行。
|
||||
|
||||
如果你想使用图形方法,那么在“发现”中添加到软件源,然后点击更新。
|
||||
|
||||
或者,使用下面的终端方法,以加快安装速度。
|
||||
|
||||
* **步骤 1**:打开一个终端,添加下面的 KDE Backports PPA。
|
||||
|
||||
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:kubuntu-ppa/backports
|
||||
```
|
||||
|
||||
* **步骤 2**:然后运行以下程序来启动系统升级。这将在你的 Hirsute Hippo 系统中安装最新的 KDE Plasma 5.22。
|
||||
|
||||
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
sudo apt full-upgrade
|
||||
```
|
||||
|
||||
![Upgrade to Plasma 5.22][8]
|
||||
|
||||
* **步骤 3**:更新后重新启动,你应该会看到一个更新的 KDE Plasma 5.22 桌面。
|
||||
|
||||
|
||||
|
||||
考虑到整个桌面环境的完整版本升级,安装可能需要一些时间。
|
||||
|
||||
### 在 Ubuntu 21.04 中安装 KDE Plasma 5.22
|
||||
|
||||
如果你正在运行基于 GNOME 的默认 Ubuntu 21.04 Hirsute Hippo 桌面,你可以使用这个 PPA 来安装最新的 KDE Plasma。下面是方法。
|
||||
|
||||
打开终端,添加 PPA(像上面的步骤那样)。
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:kubuntu-ppa/backports
|
||||
```
|
||||
|
||||
然后,刷新软件包。
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
然后运行下面的程序来安装 Kubuntu 桌面。
|
||||
|
||||
```
|
||||
sudo apt install kubuntu-desktop
|
||||
```
|
||||
|
||||
这将在 Ubuntu 21.04 中与 GNOME 一起安装 KDE Plasma 桌面。
|
||||
|
||||
### Ubuntu 20.04 LTS 中的 KDE Plasma 5.22
|
||||
|
||||
Ubuntu 20.04 LTS 版拥有早期的 KDE Plasma 5.18、KDE Framework 5.68、KDE Applications 19.12.3。所以,在它的整个生命周期中,它不会收到最新的 KDE 更新。所以,从技术上讲,你可以添加上述 PPA 并安装 KDE Plasma 5.22。但我不建议这样做,因为不兼容的软件包、框架可能会导致系统不稳定。
|
||||
|
||||
所以,建议你使用 Kubuntu 21.04 和上面的向后移植 PPA 或者使用 KDE neon 来体验最新的 Plasma 桌面。
|
||||
|
||||
### 卸载 KDE Plasma 5.22
|
||||
|
||||
如果你改变主意,想回到 KDE Plasma 的原始版本,那么安装 ppa-purge 并清除 PPA。这将使软件包降级,并启用仓库版本。
|
||||
|
||||
```
|
||||
sudo apt install ppa-purge
|
||||
sudo ppa-purge ppa:kubuntu-ppa/backports
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
### 结束语
|
||||
|
||||
我希望这个快速指南能帮助你在 Kubuntu 21.04 Hirsute Hippo 中安装最新的 KDE Plasma 5.22。这可以让你体验到最新的 KDE 技术以及 KDE 框架和应用。然而,你应该知道,并不是所有的功能都应该在向后移植 PPA 中提供,它只有选定的功能和错误修复,这才能通过回归测试并安全使用。也就是说,你总是可以把 KDE Neon 安装成一个全新的系统来享受 KDE 的最新技术。
|
||||
|
||||
* * *
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/2021/06/plasma-5-22-kubuntu-21-04/
|
||||
|
||||
作者:[Arindam][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.debugpoint.com/author/admin1/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.debugpoint.com/blog/wp-content/uploads/2021/06/Kubutu-21.04-running-with-KDE-Plasma-5.22-1024x531.jpg
|
||||
[2]: https://www.debugpoint.com/2021/06/kde-plasma-5-22-release/
|
||||
[3]: https://www.debugpoint.com/2021/04/ubuntu-21-04-hirsute-hippo-release/
|
||||
[4]: tmp.wazjcS11If#plasma-kubuntu-2104
|
||||
[5]: tmp.wazjcS11If#plasma-ubuntu-2104
|
||||
[6]: tmp.wazjcS11If#plasma-ubuntu-2004
|
||||
[7]: tmp.wazjcS11If#uninstall-stock-version
|
||||
[8]: https://www.debugpoint.com/blog/wp-content/uploads/2021/06/Upgrade-to-Plasma-5.22.jpg
|
@ -0,0 +1,135 @@
|
||||
[#]: subject: "Hash Linux: Arch Linux Preconfigured With Xmonad, Awesome, i3, and Bspwm Window Manager"
|
||||
[#]: via: "https://itsfoss.com/hash-linux-review/"
|
||||
[#]: author: "Sarvottam Kumar https://itsfoss.com/author/sarvottam/"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "mcfd"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Hash Linux: 预配置 Xmonad、Awesome、i3 和 Bspwm 窗口管理器的 Arch Linux 衍生版
|
||||
======
|
||||
|
||||
通过一些努力,[你可以安装 Arch Linux][1]。也可以在你的 Arch 系统上安装一个你选择的桌面环境或窗口管理器。
|
||||
|
||||
这需要一些时间和精力,但肯定是可以实现的。但是,有一些项目可以减轻你的痛苦,为你提供一个预先配置好的桌面环境或窗口管理器的系统。[ArcoLinux][2] 就是这样一个例子。
|
||||
|
||||
最近,我发现了另一个项目,它只专注于在出色的 Arch 发行版上提供完善的窗口管理器的选择。
|
||||
|
||||
[Hash Project][3] 提供了四种预配置平铺式窗口管理器的 Arch 变体:Awesome、 [Xmonad][4]、 i3、和 Bspwm。
|
||||
|
||||
如果你是一个初学窗口管理器的人,Hash Project 绝对是你应该马上尝试的。不用先投入时间去配置它,你就可以探索窗口管理器的潜力,并习惯由键盘驱动的系统。
|
||||
|
||||
在本文中,我将讨论我在使用 **Hash Linux Xmonad 版本** 时的部分体验,该版本采用 Linux 5.12的内核。
|
||||
|
||||
### 安装 Hash Linux
|
||||
|
||||
Hash Linux 四个版本的 ISO 镜像均可 [下载][5] ,适用于 x86_64 系统架构。
|
||||
|
||||
为了避免在实体机上安装时出现的各种意外错误,我在 GNOME Boxes 中创建了一个 Hash Linux Xmonad 版本的虚拟机。
|
||||
|
||||
当我启动到 Hash Linux 时,我注意到两件事。 首先是一个面板,提供用于管理窗口和命令的快捷方式。 我将在安装后讨论它。 其次,是一个漂亮且易于使用的 GUI 安装程序。
|
||||
|
||||
![Hash Linux GUI Installer][6]
|
||||
|
||||
像其他衍生版一样,图形化的安装程序使安装过程非常顺畅。在几个步骤的配置中,Hash Linux 已安装完毕,并准备重新启动。
|
||||
|
||||
![Installer Welcome Page][7]
|
||||
|
||||
### 第一印象
|
||||
|
||||
![Hash Linux][8]
|
||||
|
||||
如果你曾经在你的 Linux 系统上安装过 Xmonad 窗口管理器,那么你重启后首先看到的是什么? 空白的屏幕吧。
|
||||
|
||||
如果你是一个初学者,或者你不知道默认的按键绑定,你会被卡在一个屏幕上。因此,在使用任何窗口管理器之前,你必须先阅读其键盘快捷键。
|
||||
|
||||
如果你想把所有重要的快捷键提示都放在窗口上呢?一个备忘单可以为你节省很多时间。
|
||||
|
||||
因此,为了简化和方便初学者,Hash Linux 将重要的快捷键都钉在了桌面上。
|
||||
|
||||
所以,让我们先尝试其中的一些。从最重要的一个开始 `[Super]+Enter`,它可以打开默认的 termite 终端模拟器与 Z shell (ZSH)。
|
||||
|
||||
如果你多次点击它,你会发现默认情况下 Xmonad 遵循一个缩小布局,它首先将一个窗口固定在右边,然后以同样的方式将其余的全部安排在左边。
|
||||
|
||||
![Xmonad default layout][9]
|
||||
|
||||
按下 `[Super]+[Space]`,你也可以将当前的布局改为标签式布局。甚至你可以按下 `[Super]+[left+click]` 将窗口拖动。
|
||||
|
||||
![Moved to float][10]
|
||||
|
||||
要退出当前的窗口,你可以按下 `[Super]+Q`。
|
||||
|
||||
### Hash Linux 中的应用
|
||||
|
||||
默认情况下,Hash Linux 包含几个有用的命令行工具,如:NeoFetch、Htop、Vim、Pacman、Git 和 Speedtest-cli。
|
||||
|
||||
![Htop][11]
|
||||
|
||||
它还拥有大量的图形应用程序,如:Firefox 89、Gparted、Nitrogen、Conky、Flameshot、Geany 和 CPU-X。
|
||||
|
||||
`[Super]+D` 是 Hash Linux 中打开应用程序搜索菜单的默认快捷键。
|
||||
|
||||
![Application search menu][12]
|
||||
|
||||
### 主题美化
|
||||
|
||||
Hash Cyan 是 Hash Linux 的默认主题。除了它之外,Hash Linux 还提供了另外四个主题:Light Orange、Sweet Purple、Night Red 和 Arch Dark。
|
||||
|
||||
Hash Theme Selector 是一个自制的 Hash Linux 应用程序,你可以用它来配置窗口管理器的主题。
|
||||
|
||||
![Hash Theme Selector][13]
|
||||
|
||||
### 升级 Hash Linux
|
||||
|
||||
作为一个滚动发行版,你不需要下载一个新的 Hash Linux 的 ISO 来更新现有系统。你唯一需要的是在终端运行 ` upgrade` 命令来升级你的系统。
|
||||
|
||||
![upgrading hash linux][14]
|
||||
|
||||
### 结束语
|
||||
|
||||
如果你想使用一个窗口管理器来代替桌面环境,但又不想花很多时间来配置它,Hash Project 可以节省你的时间。
|
||||
|
||||
首先,它可以节省你大量的配置时间和精力,其次,它可以很轻松地让你适应使用键盘控制的系统。以后,你肯定可以学会根据自己的需要进行配置。
|
||||
|
||||
由于 Hash Linux 已经提供了4个带有不同的窗口管理器的 ISO,你可以开始使用任何一个版本,并找到你最喜欢的一个版本。总的来说,它是一个[很好的 Arch Linux 衍生版][15]。
|
||||
|
||||
最后我还要提一下,目前 Hash Linux 的官方[网站][3]并没有包含很多关于它的信息。
|
||||
|
||||
![][16]
|
||||
|
||||
早期的[网站][17](我现在无法访问)也在发布信息中提到,在我上次访问时,其中包含了许多关于它的信息,包括配置细节等。
|
||||
|
||||
不想入 Arch 的教,只想用平铺式窗口管理器?可以试试 [Regolith Linux][18] 。它是预先配置了 i3wm 的 Ubuntu。棒极了,对吧?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/hash-linux-review/
|
||||
|
||||
作者:[Sarvottam Kumar][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[mcfd](https://github.com/mcfd)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/sarvottam/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/install-arch-linux/
|
||||
[2]: https://arcolinux.com/
|
||||
[3]: https://hashproject.ga/
|
||||
[4]: https://xmonad.org/
|
||||
[5]: https://hashproject.ga/index.html#downloads
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Linux-GUI-Installer.jpg?resize=800%2C451&ssl=1
|
||||
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/06/Installer-Welcome-Page.png?resize=800%2C452&ssl=1
|
||||
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Linux.jpg?resize=800%2C451&ssl=1
|
||||
[9]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/Xmonad-default-layout.png?resize=800%2C452&ssl=1
|
||||
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Moved-to-float.png?resize=800%2C452&ssl=1
|
||||
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Htop.jpg?resize=800%2C451&ssl=1
|
||||
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/Application-search-menu.jpg?resize=800%2C451&ssl=1
|
||||
[13]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Theme-Selector.png?resize=800%2C452&ssl=1
|
||||
[14]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/06/Upgrading-hash-linux.png?resize=800%2C452&ssl=1
|
||||
[15]: https://itsfoss.com/arch-based-linux-distros/
|
||||
[16]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/Hash-Linux-Site-URL.png?resize=575%2C193&ssl=1
|
||||
[17]: https://hashproject.org/
|
||||
[18]: https://itsfoss.com/regolith-linux-desktop/
|
@ -0,0 +1,281 @@
|
||||
[#]: subject: "How different programming languages read and write data"
|
||||
[#]: via: "https://opensource.com/article/21/7/programming-read-write"
|
||||
[#]: author: "Alan Smithee https://opensource.com/users/alansmithee"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "MjSeven"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
不同的编程语言是如何读写数据的
|
||||
======
|
||||
每种编程语言都有其独特的完成任务的方式,这也说明了为什么有这么多语言可供选择。
|
||||
![Code going into a computer.][1]
|
||||
|
||||
在 Jim Hall 的_[不同的编程语言如何完成相同的事情][2]_文章中,他演示了 13 中不同的语言如何使用不同的语法来完成同一个任务。经验是,编程语言往往有很多相似之处。一旦你了解了一种编程语言,你就可以通过理解它的语法和结构来学习另一种。
|
||||
|
||||
本着同样的精神,Jim 的文章比较了不同编程语言如何读写数据。无论数据来自配置文件还是用户创建的文件,在存储设备上处理数据都是程序员的常见任务。但以这种方式涵盖所有编程语言是不切实际的,最近的 Opensource.com 系列文章提供了对这些编程语言采用的不同方法的深入了解:
|
||||
|
||||
* [C][3]
|
||||
* [C++][4]
|
||||
* [Java][5]
|
||||
* [Groovy][6]
|
||||
* [Lua][7]
|
||||
* [Bash][8]
|
||||
* [Python][9]
|
||||
|
||||
|
||||
|
||||
### 读写数据
|
||||
|
||||
用计算机读写数据的过程和你在现实生活中读写数据的过程类似。要访问书中的数据,你首先要打开它,然后阅读单词或将生词写入书中,然后合上书。
|
||||
|
||||
当程序需要从文件中读取数据时,你向程序传入一个文件位置,然后计算机将该数据读入 RAM 中并解析它。同样,当程序需要将数据写入文件时,计算机会将新数据放入系统的内存写入缓冲区,然后将其同步到存储设备上的文件中。
|
||||
|
||||
下面是这些操作的一些伪代码:
|
||||
|
||||
1. 在内存中加载文件。
|
||||
2. 读取文件内容,或将数据写入文件。
|
||||
3. 关闭文件。
|
||||
|
||||
|
||||
|
||||
### 从文件中读取数据
|
||||
|
||||
从 Opensource.com 系列文章的语言中,你可以看到读取文件的三种趋势。
|
||||
|
||||
#### C
|
||||
|
||||
在 C 语言中,打开文件可能涉及检索单个字符,例如 `EOF` 指示符,表示文件结束,或数据块,具体取决于你的需求和方法。根据你的目标,它可能感觉像一个主要是手工的过程,但这正是其他语言所模仿的。
|
||||
|
||||
|
||||
```c
|
||||
FILE *infile;
|
||||
int ch;
|
||||
|
||||
infile = fopen(argv[1], "r");
|
||||
|
||||
do {
|
||||
ch = fgetc(infile);
|
||||
if (ch != EOF) {
|
||||
printf("%c", ch);
|
||||
}
|
||||
} while (ch != EOF);
|
||||
|
||||
fclose(infile);
|
||||
```
|
||||
|
||||
你还可以选择将文件的某些部分加载到系统缓冲区中,然后在缓冲区外工作。
|
||||
|
||||
|
||||
```c
|
||||
FILE *infile;
|
||||
char buffer[300];
|
||||
|
||||
infile = fopen(argv[1], "r");
|
||||
|
||||
while (!feof(infile)) {
|
||||
size_t buffer_length;
|
||||
buffer_length = fread(buffer, sizeof(char), 300, infile);
|
||||
}
|
||||
|
||||
printf("%s", buffer);
|
||||
fclose(infile);
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
C++ 简化了一些步骤,允许你将数据解析为字符串。
|
||||
|
||||
|
||||
```c++
|
||||
std::string sFilename = "example.txt";
|
||||
|
||||
std::ifstream fileSource(sFilename);
|
||||
std::string buffer;
|
||||
|
||||
while (fileSource >> buffer) {
|
||||
std::cout << buffer << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
Java 和 Groovy 和 C++ 类似。它们使用名为 `Scanner` 的类来设置数据流或对象,这样就会包含你选择的文件内容。你可以通过标记(字节、行、整数等)扫描文件。
|
||||
|
||||
|
||||
```java
|
||||
File myFile = new File("example.txt");
|
||||
|
||||
Scanner myScanner = new Scanner(myFile);
|
||||
while (myScanner.hasNextLine()) {
|
||||
String line = myScanner.nextLine();
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
myScanner.close();
|
||||
```
|
||||
|
||||
#### Groovy
|
||||
|
||||
|
||||
```groovy
|
||||
def myFile = new File('example.txt')
|
||||
|
||||
def myScanner = new Scanner(myFile)
|
||||
while (myScanner.hasNextLine()) {
|
||||
def line = myScanner.nextLine()
|
||||
println(line)
|
||||
}
|
||||
|
||||
myScanner.close()
|
||||
```
|
||||
|
||||
#### Lua
|
||||
|
||||
Lua 和 Python 进一步抽象了整个过程。你不必有意识地创建数据流,你只需给一个变量赋值为 `open` 函数的返回值,然后解析该变量的内容。这种方式快速,最简且容易。
|
||||
|
||||
|
||||
```lua
|
||||
myFile = io.open('example.txt', 'r')
|
||||
|
||||
lines = myFile:read("*all")
|
||||
print(lines)
|
||||
|
||||
myFile:close()
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
|
||||
```python
|
||||
f = open('example.tmp', 'r')
|
||||
|
||||
for line in f:
|
||||
print(line)
|
||||
|
||||
f.close()
|
||||
```
|
||||
|
||||
### 向文件中写入数据
|
||||
|
||||
就写代码来说,写入是读取的逆过程。因此,将数据写入文件的过程与从文件中读取数据基本相同,只是使用了不同的函数。
|
||||
|
||||
#### C
|
||||
|
||||
在 C 语言中,你可以使用 `fputc` 函数将字符写入文件:
|
||||
|
||||
|
||||
```c
|
||||
fputc(ch, outfile);
|
||||
```
|
||||
|
||||
或者,你可以使用 `fwrite` 将数据写入缓冲区。
|
||||
|
||||
|
||||
```c
|
||||
fwrite(buffer, sizeof(char), buffer_length, outfile);
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
因为 C++ 使用 `ifstream` 库为数据打开缓冲区,所以你可以像 C 语言那样将数据写入缓冲区(C++ 库除外)。
|
||||
|
||||
|
||||
```c++
|
||||
std::cout << buffer << std::endl;
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
在 Java 中,你可以使用 `FileWriter` 类来创建一个可以写入数据的对象。它的工作方式与 `Scanner` 类非常相似,只是方向相反。
|
||||
|
||||
|
||||
```java
|
||||
[FileWriter][19] myFileWriter = new [FileWriter][19]("example.txt", true);
|
||||
myFileWriter.write("Hello world\n");
|
||||
myFileWriter.close();
|
||||
```
|
||||
|
||||
#### Groovy
|
||||
|
||||
类似地,Groovy 使用 `FileWriter`,但使用了稍微 "groovy" 的语法。
|
||||
|
||||
|
||||
```groovy
|
||||
new FileWriter("example.txt", true).with {
|
||||
write("Hello world\n")
|
||||
flush()
|
||||
}
|
||||
```
|
||||
|
||||
#### Lua
|
||||
|
||||
Lua 和 Python 很相似,都使用名为 `open` 的函数来加载文件,`writer` 函数来写入数据,`close` 函数用于关闭文件。
|
||||
|
||||
|
||||
```Lua
|
||||
myFile = io.open('example.txt', 'a')
|
||||
io.output(myFile)
|
||||
io.write("hello world\n")
|
||||
io.close(myFile)xxxxxxxxxx myFile = io.open('example.txt', 'a')io.output(myFile)io.write("hello world\n")io.close(myFile)myFile = io.open('example.txt', 'a')io.output(myFile)io.write("hello world\n")io.close(myFile)
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
|
||||
```python
|
||||
myFile = open('example.txt', 'w')
|
||||
myFile.write('hello world')
|
||||
myFile.close()
|
||||
```
|
||||
|
||||
### File 模式
|
||||
|
||||
许多语言在打开文件时会指定一个“模式”。模式有很多,但这是常见的定义:
|
||||
|
||||
* **w** 表示写入
|
||||
* **r** 表示读取
|
||||
* **r+** 表示可读可写
|
||||
* **a** 表示追加
|
||||
|
||||
某些语言,例如 Java 和 Groovy,允许你根据用于加载文件的类来确定模式。
|
||||
|
||||
无论编程语言以何种方式来确定文件模式,你都需要确保你是在 _追加_ 数据,除非你打算用新数据覆盖文件。编程语言不像文件选择器那样,没有内置的提示来警告你防止数据丢失。
|
||||
|
||||
### 新语言和旧把戏
|
||||
|
||||
每种编程语言都有其独特完成任务的方式,这就是为什么有这么多语言可供选择。你可以而且应该选择最合适你的语言。但是,你一旦了解了编程的基本结构,你可以随意尝试其他语言,而不必担心不知道如何完成基本任务。通常情况下,实现目标的途径是相似的,所以只要你牢记基本概念,它们就很容易学习。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/7/programming-read-write
|
||||
|
||||
作者:[Alan Smithee][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alansmithee
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_development_programming.png?itok=4OM29-82 "Code going into a computer."
|
||||
[2]: https://opensource.com/article/21/4/compare-programming-languages
|
||||
[3]: https://opensource.com/article/21/3/file-io-c
|
||||
[4]: https://opensource.com/article/21/3/ccc-input-output
|
||||
[5]: https://opensource.com/article/21/3/io-java
|
||||
[6]: https://opensource.com/article/21/4/groovy-io
|
||||
[7]: https://opensource.com/article/21/3/lua-files
|
||||
[8]: https://opensource.com/article/21/3/input-output-bash
|
||||
[9]: https://opensource.com/article/21/6/reading-and-writing-files-python
|
||||
[10]: http://www.opengroup.org/onlinepubs/009695399/functions/fopen.html
|
||||
[11]: http://www.opengroup.org/onlinepubs/009695399/functions/fgetc.html
|
||||
[12]: http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
|
||||
[13]: http://www.opengroup.org/onlinepubs/009695399/functions/fclose.html
|
||||
[14]: http://www.opengroup.org/onlinepubs/009695399/functions/feof.html
|
||||
[15]: http://www.opengroup.org/onlinepubs/009695399/functions/fread.html
|
||||
[16]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+file
|
||||
[17]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
||||
[18]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
||||
[19]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+filewriter
|
Loading…
Reference in New Issue
Block a user