140、将程序划分为模块:提高代码的可维护性和可读性

将程序划分为模块:提高代码的可维护性和可读性

1. 拆分程序的好处和必要性

将程序分解成更小、更易于管理的部分有几个显著的优点。首先,将程序分解成较小的模块可以减少编译时间。对于小型项目,Code::Blocks只需几秒钟就能处理好代码,但对于非常大的项目,编译时间可能会显著增加。我曾经参与的一些项目,甚至需要整晚的时间才能重新构建。

此外,由于一两行代码的改动而重新编译整个项目是极其浪费资源的。更好的做法是仅重新编译包含改动的模块,然后将其重新链接到所有未改动的模块中,以创建一个包含改动的新可执行文件。通常,编译的时间比链接要长。

其次,理解、编写、测试和调试一个由多个经过深思熟虑但相对独立的模块组成的程序会更加容易。每个模块代表一组逻辑上的功能分组。一个包含所有程序可能使用的所有函数的大型单一源模块很快就会变得难以管理。

第三点是重用的便利性。一个包含可重用函数的模块,可以链接到未来的程序中,这样的模块更容易进行文档编写和维护。对模块进行修改以修复某个错误,可以迅速应用到使用该模块的其他可执行文件中。

最后,团队合作的问题。两位程序员不能(至少不能很好地)同时处理同一个模块。一个更简单的方法是,将一个模块中包含的一组功能分配给一位程序员,同时将另一个模块中的一组不同功能分配给另一位程序员。当模块准备就绪进行测试时,可以将它们链接起来。

2. 创建 Factorial.cpp 示例文件

由Code::Blocks创建的初始控制台应用程序项目只有一个源文件,即 main.cpp 。下一步是创建第二个源文件,该文件将包含阶乘函数。以下是创建

Web自动化测试怎么做?Web自动化测试的详细流程和步骤 阅读详情

相关推荐

深入解析TI CC26xx PRCM寄存器:低功耗嵌入式开发的核心控制

在嵌入式系统开发中,电源、复位和时钟管理是决定系统稳定性、实时性与功耗的关键基础。其核心原理在于通过硬件模块对芯片内部资源进行分级与分区控制,例如划分独立的电源域以实现模块化节能,并利用时钟树与门控技术动态调节各功能模块的工作频率与开关。这项技术的核心价值在于能够显著降低系统动态与静态功耗,尤其对于物联网、可穿戴设备等电池供电场景至关重要。应用场景广泛,从简单的传感器数据采集到复杂的无线音频传输均依赖于此。本文聚焦于德州仪器CC26xx系列微控制器中的PRCM模块,通过剖析其时钟门控、电源域控制及复位管理等

cuiji1279的博客 411

Python Dominate库:优雅生成HTML的面向对象解决方案

在Python Web开发与数据处理中,动态生成HTML是常见需求。传统字符串拼接方式易出错且难以维护,而模板引擎在程序化构建复杂DOM结构时不够灵活。面向对象编程思想为解决这一问题提供了新思路,通过将HTML元素抽象为Python对象,可以实现代码与文档结构的同构映射。Dominate库正是基于这一原理设计的工具,它允许开发者使用纯Python语法构建HTML文档,利用with语句实现直观的嵌套结构,并通过属性字典管理样式与数据。这种技术方案特别适用于需要动态生成报告、邮件模板或管理后台界面的场景,能显著

weixin_34130389的博客 374

MSC8112本地总线地址空间解析与嵌入式外设驱动开发实践

在嵌入式系统开发中,内存映射是连接处理器核心与硬件外设的核心机制。其原理是将外设的控制寄存器、状态寄存器和数据缓冲区映射到处理器的统一地址空间,CPU通过标准的加载/存储指令即可直接访问,从而实现对硬件的精准控制。这种技术价值在于提供了低延迟、高效率的硬件访问路径,是驱动开发、实时数据处理的基石。其应用场景广泛,涵盖通信处理器、工业控制、网络设备等领域。本文以恩智浦MSC8112通信处理器为例,深入剖析其本地总线地址空间的设计逻辑与配置方法,重点讲解如何通过基址寄存器(BR9/BR11)和硬复位配置字(HR

lanmh的专栏 417

【操作系统】 Operation System 第二章:操作系统基础操作

2.1 操作系统的启动 (1)CPU, I/O, 内存通过总线连接。 (2)DISK:存放OS; BIOS:基本I/O处理系统( basic I/O system); Bootloader: 加载OS到内存中。 (3)当电脑通电时,段寄存器CS和指令寄存器IP能够确定一个内存地址,例如CS:IP = 0xf000:fff0. (4)POST(加电自检),寻找显卡和执行BIOS。(显示器,键盘…是否...

iwanderu的博客 1万+

深入了解 Google Gemini:主要功能是什么以及我们为什么要使用它?

Google Gemini开启AI新纪元,以其独特的多模式功能重塑技术未来。

KompasAI的博客 4061

【云迁移工具RDA】迁移常见问题

Agent无法正常启动,Linux系统提示“SMS.0201 Failed to start sms agent!”,Windows系统提示“SMS.0201 源端主机网络繁忙,无法连接api网关”。该问题通常是由于源端没有通公网,或者没有按照要求配置hosts,无法与iam或者sms通信导致。需要排查源端网络。1.登录源端服务器。2.检查源端是否能正常访问互联网,若无法访问,请处理后重新启动Agent。可参考弹性公网IP Ping不通检查源端的DNS,防火墙,安全组、本地网络等。

2404_89358774的博客 1485

告别Keil4!手把手教你用Keil C51 V9.61编译51单片机代码(附最新激活方法)

本文详细介绍了Keil C51 V9.61在51单片机开发中的全栈升级指南,包括编译速度提升、调试器性能优化和现代开发支持等核心优势。通过智能安装方案、项目迁移实战和新特性深度应用,帮助开发者告别Keil4,大幅提升开发效率。附有最新激活方法和实用技巧,适用于嵌入式开发工程师。

weixin_26886855的博客 419

华为OD新系统机试真题 - 准备生日礼物(Py/Java/C/C++/Js/Go)

华为OD机试新系统真题 4.8【准备生日礼物】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【准备生日礼物】

qq_45776114的博客 1478

【Bug已解决】claude: command not found 解决方案

方案适用场景推荐指数添加 PATH全局 bin 目录确实存在但未加入 PATH⭐⭐⭐⭐⭐nvm 重新安装多 Node 版本切换导致失效⭐⭐⭐⭐⭐Windows 环境变量检查Windows 平台专用⭐⭐⭐⭐原生安装脚本想彻底避开 npm PATH 问题⭐⭐⭐⭐清理多重 Node 安装系统里有多套 Node 管理方式冲突⭐⭐⭐报错的核心是npm 全局安装的可执行文件路径没有正确出现在系统的 PATH 环境变量里,而不是安装本身失败了。

一键难忘的博客 1万+

北斗导航 | 卡尔曼滤波与因子图优化对比(附图优化matlab代码)

- 历史数据利用:因子图通过滑动窗口保留历史状态,优化时联合多帧数据;卡尔曼滤波仅依赖当前和上一帧状态 。 - 迭代优化:因子图通过多次迭代逼近最优解,卡尔曼滤波仅单次更新 。 - 误差抑制:因子图的多次线性化可有效抑制非线性误差(如GNSS伪距观测的非线性) 。

尘世冰封的专栏 1299

跨境电商产品信息抓取:使用Python爬虫进行市场分析

跨境电商平台是指为不同国家和地区的买卖双方提供在线交易服务的电子商务平台。亚马逊(Amazon):全球最大的电商平台之一,提供丰富的商品种类和全球配送服务。eBay:全球知名的在线拍卖和购物网站,支持个人和企业卖家。速卖通(AliExpress):阿里巴巴旗下的跨境电商平台,主要面向全球消费者提供中国制造的商品。Wish:以移动端为主的跨境电商平台,主打低价商品和个性化推荐。这些平台上的商品数据包括商品名称、价格、销量、用户评价、库存等信息,对于市场分析具有重要价值。

2201_76125261的博客 1231

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

上一篇: 25、用于历史数据集的 IP 地址归属服务:Back-to-the-Future Whois
下一篇: 21、面向对象编程:多态性与系统扩展性
raspberrypi5
博客等级 码龄1天 0粉丝 1856原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值