重新组织函数--Inline Method(内联函数)

IntelliJ IDEA 2021.1:有哪些基础的重构方法? 下载IntelliJ IDEA 2021.1 如您所知,IntelliJ IDEA提供的两种最流行的基本重构:Extract Method和Inline Method。 第一种方法使方法更短且更具可读性,而第二种方法使不必要的方法的数量减至最少,并使代码更直接。 在IntelliJ IDEA中,您可以连续使用这两种操作来获得更复杂的结果-我们将此过程称为多步骤重构。 让我们来看看,看看我们可以做些什么,用更少的成本实现更多。 问题 假设我们有一个只检查一个条件的方法: void repair 阅读详情
一个函数的本体与名称同样清晰易懂

在函数调用点插入函数本体,然后移除该函数。

int getRating(){
return (moreThanFiveLateDeliveries()?2:1);
}

boolean moreThanFiveLateDeliveries(){
_numnerOfLateDeliveries>5;
}

int getRating(){
return (_numberOfLateDeliveries>5)?2:1;
}





C++内联函数深度解析:从原理到性能优化实战 在C++性能优化中,函数调用开销是影响程序效率的关键因素之一。其原理在于每次调用都涉及上下文保存、跳转和恢复等操作,累积起来可能成为性能瓶颈。为了消除这种开销,C++引入了内联函数机制,它允许编译器在编译时将函数代码直接插入调用点,从而避免函数调用的成本。这项技术的核心价值在于实现“零开销抽象”,在保持代码模块化的同时追求极致性能。在实际应用场景中,内联函数特别适用于体积小、调用频繁的访问函数(如getter/setter)以及工具函数。值得注意的是,现代编译器具备强大的自动内联优化能力,而`inline` 阅读详情

相关推荐

海港综合能源系统物流-能量协同优化Matlab实现全解析

综合能源系统优化调度是当前能源与交通交叉领域的研究热点,其核心挑战在于多能互补与多系统耦合。其中,海港作为典型的高耗能物流枢纽,其物流作业与能量管理之间存在强耦合关系:泊位分配、岸桥调度直接影响负荷曲线与用能成本,而微电网内光伏、储能与购电策略又反向制约作业节奏。传统的顺序优化往往顾此失彼,协同优化则通过统一的混合整数线性规划模型,将物流决策与能量决策置于同一框架下联合求解,以港口综合运行成本最低为目标,挖掘削峰填谷与时间弹性潜力。这类问题在工程落地时常依赖Matlab结合Yalmip与Gurobi求解器实

weixin_33928137的博客 139

将函数内联化

Inline Method(将函数内联化)Updated on Wednesday, November 10, 2004Summary: 将被内联化的函数,其本体(method body)与其名称(method name)同样清楚易懂,那么就在函数的调用点插入函数本体以消除该函数。 Tips: 如果你手上有一群组织不甚合理的函数,你可以试着把它们都i

Allen Lee's Magic 1272

embedding计算过程

文章目录embedding计算过程(错了跟我讲,我会改)参考示例个人理解过程图示总结(基于pytorch) embedding计算过程(错了跟我讲,我会改) 参考示例 https://www.jianshu.com/p/63e7acc5e890 个人理解过程图示 总结(基于pytorch) 总的来说,就是将独热向量的长度(对应嵌入层的num_embeddings)转变为嵌入层的emdedding_size(而独热向量的维数就是你的数据中一共产生了多少个不一样的词,至少是这么多)。 数据的变化,将二维

纸上得来终觉浅,绝知此事要躬行! 1632

Inline Method 内联函数

一个函数的本体与名称同样清楚易懂 在函数调用点插入函数本体 ,然后移除该函数 int getRating() { return (moreThanFiveLateDeliveries()) ? 2 : 1 } boolean moreThanFiveLateDeliveries() { return _numberOfLateDeliveries > 5 } int...

记录日常 710

基因树构建全流程:从OrthoFinder到iTOL的保姆级教程(附兰科植物案例)

本文提供了一份从OrthoFinder到iTOL的基因树构建全流程保姆级教程。详细解析了利用OrthoFinder构建物种树、IQ-TREE构建无根基因树、Notung进行树调和生根,以及最终在iTOL中实现专业可视化的每一步操作与实战经验,并以兰科植物NB-ARC基因家族为例进行演示,帮助研究者系统掌握基因树分析方法。

tequila的博客 523

海康VM加密狗无法识别常见问题排查

海康VM加密狗无法识别常见问题排查

视觉人机器视觉的博客 2713

6.2 Inline Method 内联方法

在方法调用点插入方法本体,然后移除该方法 更多精彩 更多技术博客,请移步 asing1elife’s blog 动机 一系列组织不合理的方法相互调用,可以通过内联方法将其合并成一个大型方法,在通过 6.1 Extract Method 提炼方法 将这些代码重新提炼 过多的使用间接层,导致系统中大部分方法看上去都只是另一个方法的简单委托 案例 public int getRating()...

asing1elife's blog 560

STM32 SPI驱动TFT LCD实战:时序配置与硬件协同

SPI(串行外设接口)是一种高速、全双工、同步串行通信协议,广泛应用于微控制器与显示模组等外设的数据交互。其核心依赖时钟极性(CPOL)与时钟相位(CPHA)组合定义的四种工作模式,直接影响数据采样可靠性;而片选(NSS)与MOSI/SCLK等信号的硬件映射,则决定了多设备共总线下的通信稳定性。在TFT LCD驱动场景中,SPI凭借低开销、高吞吐优势成为主流选择,尤其适配ST7789、ILI9341等集成显示控制器的模块。本文聚焦STM32L系列MCU通过SPI2驱动1.3寸LCD的完整链路,涵盖Mode

php55的博客 1209

6.2Inline Method(内联函数)

   

&& 350

【Photoshop JSX脚本】强大的事件监听器脚本 - event_listener.jsx

新手第一次了解的事件监听一定是ScriptingListener.8bi插件,如果你对此插件有了基本运用,那么现在了解一款更方便的时间监听脚本event_listener.jsx。不再像ScriptingListener.8bi插件那样晦涩难懂。 1、准备event_listener.jsx文件到 F:\Program Files\Adobe Photoshop 2020\Presets\...

Greless的后花园 8207

[AI] 嵌入模型选择:bge / text-embedding-3 / Jina Embeddings 对比与选型指南

摘要: 本文对比了BGE-M3、OpenAI和Jina三种主流嵌入模型在语言覆盖、性能、延迟、维度和成本等维度的差异。BGE-M3适合中文场景,本地部署成本低;OpenAI API多语能力强但依赖网络;Jina在多语表现突出但需关注商用许可。测试显示BGE-M3本地延迟3-6ms,OpenAI API延迟200-600ms。选型建议:隐私场景选BGE本地部署,多语低维护选OpenAI,高精度选Jina。部署时需注意批处理优化、向量库压缩和商用许可等问题,建议建立评测指标并监控关键指标。

每日出拳老爷子的博客 428

重新组织你的函数之二 :Inline Method(将函数内联化)

一个函数,其本体(method body)应该与其名称(method name)同样清楚易懂。 在函数调用点插入函数本体,然后移除该函数。 int getRating() {      return (moreThanFiveLateDeliveries()) ? 2 : 1; } boolean moreThanFiveLateDeliveries() {      ret

yuwei629的专栏 943

Codex 接入自定义大模型终极教程:插件解锁、会话管理、国产模型一键搞定

🚀 Codex 默认只能使用 OpenAI 官方模型?这篇文章带你从零接入 DeepSeek、通义千问、GLM 等国产大模型,并彻底解锁插件、会话删除、多模型切换等隐藏功能。配置原理、常见坑点、傻瓜式增强工具分享,小白也能轻松上手!🔥

XiaoqiangClub的博客 3144

2、重新组织函数

1、Extract Method(提炼函数)       1、无局部变量       2、有局部变量         1、被提炼代码段只是读取变量的值,并不修改他们。           简单传给目标函数         2、被提炼代码段对局部变量再赋值           1、如果发现源函数的参数被赋值,使用Remove Assignments to Para

姬世霆的专栏 1037

基于YOLOv8的违规抽烟/打电话检测系统:从数据集构建到部署实战

模型优点缺点精度高速度慢(5 FPS)SSD速度快小目标检测差YOLOv5平衡性好官方支持停止YOLOv8最新、最快、最准需要PyTorch环境YOLOv8相比前代:骨干网络升级(C2f模块)无锚框检测(Anchor-Free)动态任务对齐分配(TaskAlignedAssigner)支持分类/检测/分割/姿态估计。

YOLO 98

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

【笔记】《重构:改善既有代码的设计》第6章-重新组织函数

第6章 重新组织函数 几乎所有时刻,问题都源于Long Methods(过长函数)。这很讨厌,因为它们往往包含太多信息,这些信息又被函数错综复杂的逻辑掩盖,不易鉴别。对付过长函数,一项重要的重构手法就是Extract Method,它把一段代码从原先函数中提取出来,放进一个单独函数中。Inline Method正好相反:将一个函数调用动作替换为该函数本体。如果在进行多次提炼之后,意识到提炼所得的某...

ZeromaXHe的博客 447

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

重构——2内联函数(Inline Method)

内联函数(Inline Method) 一个函数本体与名称同样清楚易懂,在函数调用点插入函数本体,然后移除该函数。 一、动机 1、非必要的间接性总让人不舒服 2、把组织不合理的一群函数重新组织 3、并不是所有的间接层都有价值,委托太多,会让人晕头转向 二、做法 1、检查函数,确定它不具多态性 2、找出这个函数所有的被调用点 3、将这个函数所有的调用点都替...

weixin_33785108的博客 117

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 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")

《重构》-重新组织函数

重构 重新组织函数 1.Extract Method(提炼函数) a. 原因 如果有一个过长的函数或者需要一段注释才能让人理解用途的代码,那么就将这段代码放进一个独立函数中。 b. 好处 函数粒度小,被复用的机会大 使高层函数读起来像注释 函数都是细粒度,更易被复写 c. 步骤 1. 创建一个新函数,根据这个函数的意图来对他命名 2. 即使你想要提炼的代码非常简单,例如只是...

weixin_30409849的博客 144

重新组织函数

重新组织函数 大多数问题都源于Long Methods,因为他们往往包含了大量的信息,而这些信息有被函数中错综复杂的逻辑所掩盖,不易甄别。所以重新组织函数中最主要的重构手法就是extract method。在使用extract method的手法时一般需要用到处理参数的一些手法,如:replace temp with query,split temporary varaibable和replac...

iteye_4524的博客 254

重构手法(一) —— 重新组织方法

    重新组织方法    Extract Method     将一段可以被组织在一起的代码独立出来,并让函数名称解释该函数的用途。可以强化代码的清晰度。     Inline Method     某些函数的内部代码和函数名同样清晰易读,便可去除该函数,直接使用其中代码。     利用该方法还可以将多个小型函数inline到一个大型函数中,再对其重新提炼整理。     Inline Temp

幽客独往 2696
上一篇: 重新组织函数----Extra Method(提炼函数)
下一篇: 重新组织函数--以查询取代临时变量(Replace Temp with Query)
HDPCOMEON
博客等级 码龄15年 1粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值