program Structure

本文介绍了JavaScript中的变量声明方式,包括let、var和const等关键字的使用。同时深入探讨了环境(Environment)、函数(Function)以及控制流(Control flow)的概念,并且讲解了如何使用箭头函数和可选参数等功能来提高代码效率。此外,还涉及到了数据结构如对象和数组的操作方法。

BINDINGS or variables 

    keyword: let, var, const:

BINDING NAMES: 

        A binding name may include dollar signs ($) or underscores (_) but no other

    punctuation or special characters.

ENVIRONMENT:

        The collection of bindings and their values that exist at a given time is called
    the
environment. When a program starts up, this environment is not empty. It
    always contains bindings that are part of the language standard, and most of the
    time, it also has bindings that provide ways to interact with the surrounding
    system. For example, in a browser, there are functions to interact with the
    currently loaded website and to read mouse and keyboard input.


FUNCTIONS:

    A function is a piece of program wrapped in a value .

Control flow :

    C类似: if whiel, do-while, for-loops, break, continue, switch-case

Functions as values

    let launchMissiles = function() {
        missileSystem.launch("now");
    }; 

    Declaration notation (没有顺序)

    function square(x) {
        return x * x;
    } 

Arrow functions

    const square1 = (x) => { return x * x; };

Optional Arguments

    function minus(a, b) {
    if (b === undefined) return -a;
        else return a - b;
    }

 Rest parameters 

 function max(...numbers) {

        let result = -Infinity;
        for (let number of numbers) {
        if (number > result) result = number;
        }
            return result;
        }
    console.log(max(4, 1, 9, -2));
    // → 9 

function power(base, exponent = 2) {

    let result = 1;
    for (let count = 0; count < exponent; count++) {
        result *= base;
    }
        return result;
    } 


Data Structures: Objects and Arrays

let anObject = {left: 1, right: 2};
console.log(anObject.left);
// → 1
delete anObject.left;
console.log(anObject.left);
// → undefined
console.log("left" in anObject);
// → false
console.log("right" in anObject);
// → true 

console.log(Object.keys({x: 0, y: 0, z: 2}));
// → ["x", "y", "z"] 

let objectA = {a: 1, b: 2};
Object.assign(objectA, {b: 3, c: 4});
console.log(objectA);
// → {a: 1, b: 3, c: 4} 


mutability:

对象的比较是对象id的比较,类似python对象 is 比较

Number , string,  boolen, 内置数据类型不可变,

let kim = "Kim";
kim.age = 88;
console.log(kim.age);
// → undefined 

DESTRUCTURE

function phi(table) {
return (table[3] * table[0] - table[2] * table[1]) /
Math.sqrt((table[2] + table[3]) *
(table[0] + table[1]) *
(table[1] + table[3]) *
(table[0] + table[2]));
} 

function phi([n00, n01, n10, n11]) {
return (n11 * n00 - n10 * n01) /
Math.sqrt((n10 + n11) * (n00 + n01) *
(n01 + n11) * (n00 + n10));
} 

JSON

JSON.stringify(object) , JSON.parse(string)







    

 



<think>我们正在讨论软件开发中的程序结构(programstructure)。根据引用[1]:“程序是数据结构和算法的结合,以特定编程语言表达。”程序结构指的是代码的组织方式,包括如何将代码分解为模块、函数、类等,以及它们之间的关系。程序结构的关键要素包括:1.**模块化**:将程序划分为独立的模块,每个模块负责特定功能。2.**层次结构**:模块之间形成层次关系,例如高层模块调用底层模块。3.**控制流**:程序执行的顺序,包括条件分支、循环等。4.**数据结构**:数据如何组织和存储。例如,一个简单的程序结构可能包括:-主模块(main):程序入口。-功能模块:实现具体功能,如输入处理、计算、输出。良好的程序结构有助于提高代码的可读性、可维护性和可扩展性。§§相关问题§§1.程序结构设计的原则有哪些?2.如何评估程序结构的好坏?3.常见的程序结构模式有哪些?</think>### 程序结构(Program Structure) 程序结构指软件系统中代码的组织方式,包括模块划分、数据流控制、组件交互等核心要素。其核心目标是提升代码的可维护性、可扩展性和可复用性[^1]。以下是关键概念: #### 1. **基本构成** - **数据结构**:存储和组织数据的方式(如数组、链表)。 - **算法逻辑**:处理数据的步骤(如排序、搜索)。 引用[1]指出:*“程序是数据结构和算法在特定编程语言中的结合”*。 #### 2. **核心设计原则** - **模块化**:将功能拆分为独立模块(如函数、类),降低耦合度。 ```python # 示例:计算模块 def calculate_sum(a, b): return a + b ``` - **分层架构**: - 表现层(UI) - 业务逻辑层 - 数据访问层 引用[3]提到:*“简化与外部框架(如TensorFlow/PyTorch)的接口”* 体现了分层思想。 - **控制流**:通过条件/循环语句控制执行顺序,例如: ```python if user_input > 0: process_data() else: raise_error() ``` #### 3. **典型结构模式** | 模式 | 特点 | 应用场景 | |---------------|-------------------------------|-----------------------| | **面向过程** | 线性流程,强调函数调用 | 小型工具脚本 | | **面向对象** | 封装数据与行为(类/对象) | 大型系统(如引用[4]的汽车实体) | | **事件驱动** | 响应外部事件(如用户操作) | GUI应用、游戏开发 | #### 4. **优化实践** - **高内聚低耦合**:模块内部紧密关联,模块间依赖最小化。 - **接口抽象**:引用[3]强调简化外部调用接口,提升兼容性。 - **错误处理**:隔离异常逻辑,保障核心流程稳定。 > 程序结构直接影响软件质量。引用[4]描述汽车实体时,其*“独立移动能力”* 和*“随机速度生成”* 体现了数据与行为的封装,是面向对象结构的典型应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值