>  기사  >  웹 프론트엔드  >  첫 번째 코드 검토

첫 번째 코드 검토

DDD
DDD원래의
2024-09-14 06:28:40804검색

어제 처음으로 다른 사람이 내 코드를 검토했습니다. 제가 수강하고 있는 오픈 소스 개발 과정의 과제 중 하나로서 우리는 서로의 코드를 검토해야 했습니다. 이 연습을 위해 나는 꽤 좋은 프로그래머이기도 한 내 친구 Vinh와 짝을 이루었습니다. 우리는 과정에서 각자 작업해 온 명령줄 도구에 대한 서로의 작업을 테스트하고 문제를 제출하는 임무를 맡았습니다.

First code review

빈년

/vinhyan

비동기식 대 동기식 접근 방식

우리는 텍스트에 대해 동기적으로, GitHub 문제에 대해 비동기적으로 코드 검토를 수행했습니다. 코드 작성자에게 코드를 작성할 때 특정 접근 방식을 취한 이유에 대해 문의하고 즉시 응답을 받을 수 있었기 때문에 동기식 접근 방식이 더 빠른 결과를 가져온다는 것을 알았습니다. 그러나 비동기식 접근 방식을 사용하면 작업을 완료하기 위해 두 사람의 일정에서 고정된 시간을 찾을 필요가 없습니다.

Vinh의 프로그램 테스트하기

Vinh은 AI를 사용하여 텍스트 문구를 다른 언어로 번역하는 Barrierless라는 명령줄 도구를 만들었습니다. 저는 이것이 멋진 아이디어라고 생각했습니다. 제가 Vinh의 프로그램을 테스트하기 시작했을 때는 아직 초기 개발 단계였기 때문에 아직 README가 없었습니다(지금은 있습니다. 가서 확인해 보세요!).

First code review 빈얀 / 무장애

배리어리스란 무엇인가

Barrierless는 한 언어에서 다른 언어로 원활한 번역을 제공하여 언어 장벽을 허무도록 설계된 명령줄 도구입니다. GROQCloud에서 제공하는 이 도구를 사용하면 사용자는 텍스트를 원하는 대상 언어로 신속하게 번역하여 다양한 언어 간 의사소통을 쉽게 할 수 있습니다.

특징

  • 언어를 자동 감지합니다.
  • 다국어 지원: 다양한 언어 간에 텍스트를 번역합니다.
  • GROQCloud 통합: GROQCloud의 고성능 번역 API를 활용합니다.
  • 사용하기 쉬움: 빠른 번역을 위한 간단한 명령줄 인터페이스.
  • 사용자 정의 가능: 추가 언어 기능이나 API 지원을 위해 쉽게 확장할 수 있습니다.

사용방법

설치

  1. 저장소를 복제하고 프로젝트 디렉터리로 이동하세요.
git clone git@github.com:vinhyan/barrierless.git
  1. 프로젝트 디렉토리로 이동하세요:
cd barrierless
  1. 필수 종속성을 설치합니다.
npm install
  1. Groq API 키를 저장할 .env 파일 생성
    참고: Groq API 키를 얻고 저장하는 방법에 대한 지침은 .env.example을 참조하세요

  2. 3단계에서 npm install -g를 사용한 경우 이 단계를 생략하세요…

GitHub에서 보기

A feature I really liked is the colorful output text which makes the user experience a little bit more pleasant - something I neglected in my own program in trying to model it after CLI tools like git.

I read the package.json file to find out how the program should be run, and when it immediately crashed I realized I forgot to add the API key as an environment variable. After adding my API key, the program ran without errors, although I did find an interesting quirk - the program defaults the output language to English, so if you didn't specify one, and the input was in English, it seemed to choose a language to translate to on its own - either randomly, or based on context from the input.

First code review

First code review

I opened a few other issues, mostly to do with improving code quality:

  • A missing try/catch block around an async function call

Uncaught exception in index.js #7

First code review
uday-rana posted on

index.js contains the following async function calls which are not wrapped in a try/catch block and may lead to an uncaught exception:

export async function main(text, targetLang) {
  const chatCompletion = await getGroqChatCompletion(text, targetLang);
  console.log(chatCompletion.choices[0]?.message?.content || '');
}

...

program
  ...
  .action(async (text, options) => {
    console.log(chalk.blue(`Translating  <span class="pl-s1"><span class="pl-kos">${text}</span>...`</span>));

    await main(text, options.language);
  });
Enter fullscreen mode Exit fullscreen mode
View on GitHub
  • Some suggestions to make code easier to understand

Could simplify code #8

First code review
uday-rana posted on

Some changes may be made to to the project make it easier to understand and work on:

  • [x] Move Groq configuration above program initialization with commander
  • [x] main() seems unnecessary since it contains two lines of code and there are more lines of code involved in creating and invoking the function than if it was omitted
  • [ ] prompt.js seems unnecessary since it just contains a single function which places arguments into a template literal and returns them
  • [x] Exporting main() and getGroqChatCompletion() seems unnecessary
View on GitHub
  • Adding a comment to explain the use of both import and require statements

Add comments explaining mixed import/require #9

First code review
uday-rana posted on

The project uses both ES6 import and CommonJS require due to the chalk module requiring the use of import and using import for package.json leading to an error. It would be helpful to add a comment explaining this.

View on GitHub

My turn

Next it was my turn to be reviewed. I wasn't sure what kind of issues would turn up, but Vinh ended up finding a bunch of issues I hadn't paid attention to:

  • Adding npm link as another option for not having to prefix the tool with node in the instructions in the README

README.md does not include instruction to run `npm link` #2

First code review
vinhyan posted on

The README.md file is missing instructions to run npm link, which is necessary for local development and testing of the CLI tool

View on GitHub
  • Unnecessary command assignment using commander.js

`program.command("run")` is unnecessary since the CLI does not have subcommands #3

First code review
vinhyan posted on
View on GitHub
  • A variable name typo

Variable name typo #4

First code review
vinhyan posted on

index.js line 31: typo in variable name: reponseStream

View on GitHub

Conclusion

I thought I'd done a pretty good job but goes to show there's always a bug that might've been missed or a feature that could be improved. It was great having a fresh pair of eyes scrutinize the code I wrote. For now, I fixed the typo and updated the README, but the other issues require testing and I plan on getting to those before I release version 0.1.

위 내용은 첫 번째 코드 검토의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.