diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7d62bb8 --- /dev/null +++ b/.github/dependabot.yml @@ -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" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..d75f7b7 --- /dev/null +++ b/.github/workflows/CI.yml @@ -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 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..ebc7937 --- /dev/null +++ b/.github/workflows/preview.yml @@ -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 diff --git a/docs/ch2.md b/docs/ch2.md index 16f280e..1f1d88f 100644 --- a/docs/ch2.md +++ b/docs/ch2.md @@ -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. diff --git a/docs/ch3.md b/docs/ch3.md index c145dfe..d8321e5 100644 --- a/docs/ch3.md +++ b/docs/ch3.md @@ -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.