gpt4 book ai didi

javascript - 在 Node.js 中管理大型代码库

转载 作者:行者123 更新时间:2023-11-30 06:53:45 25 4
gpt4 key购买 nike

我即将开始一个具有相当大代码库的 Node.js 项目。我更愿意将我的代码与 node_modules 分开。

理想情况下,我希望使用命名空间和文件夹,因为我认为这是一种很好的管理方式。但是,假设我没看错,这意味着我必须使用文件路径导入我需要的任何文件/“类”,这将非常困惑且难以管理。

管理 Node.js 项目的大量代码的实际方法是什么?

最佳答案

我的建议是使用静态类型语言,因为它们提供有助于管理大型代码库的自动功能。例如,可以是 dart、typescript 或 coffeescript,它们都能够生成 javascript。

这篇文章很好地解释了好处(尤其是与 JS 相比): http://arstechnica.com/information-technology/2014/06/why-do-dynamic-languages-make-it-difficult-to-maintain-large-codebases/

链接文章中陈述的一些主要问题:

There is no modularization system; there are no classes, interfaces,or even namespaces. These elements are in other languages to helporganize large codebases.

The inheritance system—prototypeinheritance—is both weak and poorly understood. It is by no meansobvious how to correctly build prototypes for deep hierarchies (acaptain is a kind of pirate, a pirate is a kind of person, a person isa kind of thing...) in out-of-the-box JavaScript.

There is noencapsulation whatsoever; every property of every object is yielded upto the for-in construct, and is modifiable at will by any part of theprogram.

There is no way to annotate any restriction on storage; anyvariable may hold any value.

如果您从 JS 开始并且不想放弃当前的代码库,则可以切换到 TypeScript。在我的 JS 项目达到 5000 行代码(大约 15 个文件)之前不久,我将其移至 typescript。我花了大约 4 个小时才让它恢复运行。

这篇文章提供了一些将 Node.js 迁移到 typescript 环境的人的见解: http://tech.kinja.com/my-experience-with-typescript-710191610

关于javascript - 在 Node.js 中管理大型代码库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21205368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com