Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "monthly"
27 changes: 27 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches:
- main
workflow_dispatch:

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install and Build
run: |
npm install
npm run docs:build
- name: Deploy (main)
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs/.vitepress/dist
28 changes: 28 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Preview

on:
pull_request:

permissions:
contents: write # upload gh-pages
pull-requests: write # create pr comment

concurrency:
group: 'preview-${{ github.ref }}'
cancel-in-progress: true

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install and Build
env:
BASE_URL: "/Clean-Code-zh/pr-preview/pr-${{ github.event.pull_request.number }}/"
run: |
npm install
npm run docs:build -- --base $BASE_URL
- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: docs/.vitepress/dist
5 changes: 3 additions & 2 deletions docs/ch2.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ If names are too clever, they will be memorable only to people who share the aut

![](figures/ch2/2_3fig_martin.jpg)

Cuteness in code often appears in the form of colloquialisms or slang. For example, don’t use the name whack() to mean kill(). Don’t tell little culture-dependent jokes like eatMyShorts() to mean abort().
Cuteness in code often appears in the form of colloquialisms or slang. For example, don’t use the name `whack()` to mean `kill()`. Don’t tell little culture-dependent jokes like `eatMyShorts()` to mean `abort()`.

> 扮可爱的做法在代码中经常体现为使用俗话或俚语。例如,别用 whack[ ](13)来表示 kill( )。别用 eatMyShorts[ ](14)这类与文化紧密相关的笑话来表示 abort( )。
> 扮可爱的做法在代码中经常体现为使用俗话或俚语。例如,别用 `whack()` 来表示 `kill()`。
别用 `eatMyShorts()` 这类与文化紧密相关的笑话来表示 `abort()`。

Say what you mean. Mean what you say.

Expand Down
4 changes: 2 additions & 2 deletions docs/ch3.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ In Listing 3-7 we had no choice because the callers were already passing that fl

### 3.6.3 Dyadic Functions 二元函数

A function with two arguments is harder to understand than a monadic function. For example, writeField(name) is easier to understand than writeField(output-Stream, name).10 Though the meaning of both is clear, the first glides past the eye, easily depositing its meaning. The second requires a short pause until we learn to ignore the first parameter. And that, of course, eventually results in problems because we should never ignore any part of code. The parts we ignore are where the bugs will hide.
A function with two arguments is harder to understand than a monadic function. For example, `writeField(name)` is easier to understand than `writeField(output-Stream, name)`. (^10) Though the meaning of both is clear, the first glides past the eye, easily depositing its meaning. The second requires a short pause until we learn to ignore the first parameter. And that, of course, eventually results in problems because we should never ignore any part of code. The parts we ignore are where the bugs will hide.

> 有两个参数的函数要比一元函数难懂。例如,writeField(name)writeField[outputStream,name](10)好懂。尽管两种情况下意义都很清楚,但第一个只要扫一眼就明白,更好地表达了其意义。第二个就得暂停一下才能明白,除非我们学会忽略第一个参数。而且最终那也会导致问题,因为我们根本就不该忽略任何代码。忽略掉的部分就是缺陷藏身之地。
> 有两个参数的函数要比一元函数难懂。例如,`writeField(name)` 比 `writeField[outputStream,name]` (^10)好懂。尽管两种情况下意义都很清楚,但第一个只要扫一眼就明白,更好地表达了其意义。第二个就得暂停一下才能明白,除非我们学会忽略第一个参数。而且最终那也会导致问题,因为我们根本就不该忽略任何代码。忽略掉的部分就是缺陷藏身之地。

10. I just finished refactoring a module that used the dyadic form. I was able to make the outputStream a field of the class and convert all the writeField calls to the monadic form. The result was much cleaner.

Expand Down