Back to Course Home 返回课程主页

📚 COMP1531 Week 2 Study NotesCOMP1531 第2周学习笔记

Multi-file Programming, Package Management, Testing & Team Project Management多文件编程、包管理、测试与团队项目管理

Last updated: September 2025最后更新:2025年9月

🎯 Week 2 Overview第2周概览

Week 2 builds upon the foundation laid in Week 1, diving deeper into advanced JavaScript concepts, professional development practices, and essential team collaboration skills for software engineering projects. 第2周在第1周基础上深入学习高级JavaScript概念、专业开发实践和软件工程项目必备的团队协作技能。

📋 Topics Covered涵盖主题

  • Multi-file JavaScript & Module System多文件JavaScript与模块系统
  • NPM Package ManagementNPM包管理
  • Dynamic Testing with Jest使用Jest进行动态测试
  • Team Project Survival Strategies团队项目生存策略

🎨 Key Skills核心技能

  • Modular Code Organization模块化代码组织
  • Dependency Management依赖管理
  • Black-box Testing Methodology黑盒测试方法论
  • Effective Team Communication有效团队沟通

🔧 2.2 Multi-file & Importing2.2 多文件编程与导入

📚 Importing Libraries导入库

JavaScript has built-in libraries that come with Node.js, similar to how C has standard libraries. These don't need to be installed separately. JavaScript有内置库随Node.js一起提供,类似于C的标准库。这些库无需单独安装。

C Library ImportC库导入

#include <stdio.h>

int main() {
  printf("Hello\n");
}

JavaScript ImportJavaScript导入

import path from 'path';
console.log(path.resolve('./'));

🦸‍♂️ Importing Our Own Files导入自定义文件

We can separate logic into multiple files and import them, enabling better code organization and reusability. 我们可以将逻辑分离到多个文件并导入它们,实现更好的代码组织和复用性。

📤 Export Methods导出方法

Default Export (Single Item)默认导出(单项)
// lib.js
function manyString(repeat, str) {
  let result = '';
  for (let i = 0; i < repeat; i++) {
    result += str;
  }
  return result;
}

export default manyString;

// main.js
import manyString from './lib.js';
Named Export (Multiple Items) - Recommended命名导出(多项)- 推荐
// lib.js
function manyString(repeat, str) { ... }
function addBrackets(string) {
  return `(${string})`;
}

export {
  manyString,
  addBrackets,
};

// main.js
import { manyString, addBrackets } from './lib.js';

💡 Best Practices最佳实践

  • Prefer named exports for flexibility优先使用命名导出以获得灵活性
  • Keep function names consistent between files在文件之间保持函数名一致
  • Use meaningful file and function names使用有意义的文件名和函数名

📦 2.3 Package Management with NPM2.3 使用NPM进行包管理

🧩 What is NPM?什么是NPM?

NPM (Node Package Manager) is automatically installed with Node.js and manages dependencies/modules/libraries for JavaScript projects. It allows you to download and use external libraries from the npmjs website. NPM(Node包管理器)与Node.js一同自动安装,管理JavaScript项目的依赖/模块/库。它允许您从npmjs网站下载和使用外部库。

🚀 Getting Started开始使用

1. Initialize Project初始化项目

npm init

Creates package.json - your project's NPM configuration file创建package.json - 项目的NPM配置文件

2. Install Dependencies安装依赖

npm install [package-name]

# Example:
npm install date-fns

Downloads and installs external libraries下载并安装外部库

📁 NPM File StructureNPM文件结构

📄 package.json

Project metadata & dependency list项目元数据和依赖列表

Commit to Git提交到Git

🔒 package-lock.json

Exact version information确切版本信息

Commit to Git提交到Git

📂 node_modules/

Installed dependencies已安装的依赖

DON'T commit不要提交

💡 Environment Reproducibility环境可重现性

By committing package.json and package-lock.json (but NOT node_modules), team members can run 'npm install' to get the exact same dependency versions, ensuring consistent development environments. 通过提交package.json和package-lock.json(但不提交node_modules),团队成员可以运行'npm install'来获得完全相同的依赖版本,确保一致的开发环境。

3.3 Dynamic Verification & Testing3.3 动态验证与测试

👩‍🔬 Why Software Testing Matters软件测试的重要性

Software failures can be catastrophic and expensive. In 2016, software failures in the US cost $1.1 trillion and affected 4.4 billion customers. Testing helps prevent bugs, reduce development costs, and improve performance. 软件故障可能是灾难性和昂贵的。2016年,美国软件故障损失1.1万亿美元,影响44亿客户。测试有助于预防bug、降低开发成本并提高性能。

🐧 Black-box Testing & Abstraction黑盒测试与抽象

Great testing treats functions as "black boxes" - focus on inputs and outputs without worrying about internal implementation. This abstraction allows you to write tests even before implementing the function. 优秀的测试将函数视为"黑盒"——专注于输入和输出,不关心内部实现。这种抽象允许您甚至在实现函数之前就编写测试。

🤡 Jest Testing FrameworkJest测试框架

Jest is a popular JavaScript testing framework that provides structured testing capabilities with powerful matchers and descriptive output. Jest是流行的JavaScript测试框架,提供结构化测试能力,具有强大的匹配器和描述性输出。

📦 Installation & Setup安装与设置

# Install Jest as development dependency
npm install --save-dev jest

# Add test script to package.json
{
  "scripts": {
    "test": "jest"
  }
}

🏗️ Jest Test StructureJest测试结构

import { removeVowels } from './lib.js';

describe('removeVowels function', () => {
  test('handles strings with no vowels', () => {
    expect(removeVowels('bcd')).toEqual('bcd');
    expect(removeVowels('xyz')).toEqual('xyz');
  });

  test('removes all vowels correctly', () => {
    expect(removeVowels('hello')).toEqual('hll');
    expect(removeVowels('javascript')).toEqual('jvscrpt');
  });
});

🎯 Testing Best Practices测试最佳实践

  • Write tests before or alongside implementation在实现之前或同时编写测试
  • Test edge cases and error conditions测试边界情况和错误条件
  • Use descriptive test names that explain the behavior使用描述性测试名称解释行为
  • Keep tests independent and repeatable保持测试独立和可重复

🤝 2.1 How to Survive Group Projects2.1 团队项目生存指南

📋 Effective Meeting Management有效会议管理

Great Meetings优秀会议

  • Always run on time准时进行
  • Clear agenda and goals清晰议程和目标
  • Encourage contribution from all鼓励所有人参与
  • People come prepared参会者有备而来

Terrible Meetings糟糕会议

  • Run overtime超时进行
  • Aimless discussions漫无目的讨论
  • Dominated by one person被一人主导
  • Unprepared participants参会者无准备

Standups & Check-ins站会与签到

🔙 What did I do?我做了什么?

Yesterday's progress昨天的进展

🚫 What blockers?遇到什么阻碍?

Current problems当前问题

🔜 What's next?接下来做什么?

Today's plan今天的计划

🎯 Ensuring Timely Delivery确保按时交付

📋 6 Core Strategies6个核心策略

  1. Always set deadlines总是设定截止日期
  2. Avoid social diffusion effect避免社会扩散效应
  3. Exploit commitment bias利用承诺偏差
  4. Use social facilitation effect利用社会促进效应
  5. Regular check-ins and reminders定期签到和提醒
  6. Teams need leadership团队需要领导

👑 Team Leader Roles团队领导角色

  • Setting goals设定目标
  • Delegate tasks委派任务
  • Plan timeline规划时间线
  • Facilitate communication促进沟通
  • Monitor progress监控进度
  • Mediate conflicts调解冲突

🎯 Success Tips成功技巧

  • Be transparent and proactive about problems对问题保持透明和积极主动
  • Embrace challenges - you'll learn along the way拥抱挑战——你会在过程中学习
  • Apply 80/20 rule - focus on high-impact tasks应用80/20法则——专注于高影响力任务
  • Break problems down into smaller pieces将问题分解成小块
  • Use resources: try first, then ask for help利用资源:先尝试,然后寻求帮助

🗺️ Week 2 Learning Path第2周学习路径

graph TD A[Multi-file Programming] --> B[Package Management] B --> C[Dynamic Testing] C --> D[Team Project Skills] A --> A1[Import/Export] A --> A2[Named vs Default] A --> A3[File Organization] B --> B1[NPM Commands] B --> B2[package.json] B --> B3[Dependencies] C --> C1[Jest Framework] C --> C2[Black-box Testing] C --> C3[Test Organization] D --> D1[Meeting Management] D --> D2[Task Distribution] D --> D3[Conflict Resolution] style A fill:#e07a5f,stroke:#333,stroke-width:2px style B fill:#81b29a,stroke:#333,stroke-width:2px style C fill:#f2cc8f,stroke:#333,stroke-width:2px style D fill:#e07a5f,stroke:#333,stroke-width:2px

Quick Reference快速参考

🔧 NPM CommandsNPM命令

npm init
npm install
npm install [package]
npm run [script]

📦 Import/Export导入/导出

export { func };
import { func } from './file.js';

export default func;
import func from './file.js';

🧪 Jest TestingJest测试

describe('module', () => {
  test('behavior', () => {
    expect(result).toEqual(expected);
  });
});

🤝 Standup Questions站会问题

  • What did I do?做了什么?
  • Any blockers?有阻碍吗?
  • What's next?接下来做什么?