BP-4-1 Sub-Program

Chapter 04 Procedural Abstraction - Function

1. General Description

When people design a complex program, they usually uses the method of function decomposition and function mix.

  • Function decomposition refers to designing a program in a top-down and step-wise way, which means dividing a large goal into several smaller ones and dividing these smaller ones into some tiny ones if possible until we can solve the problem easily.
  • Function mix refers to apply the outcome of each atomic problems to finally get to the initial goal in a bottom-up way.

In the process of decomposition and mix, we need a system of abstraction, such as procedural abstraction and functional abstraction, which indicates that we don’t have to know clearly how to do it in the every beginning, we just need to know what to do and what we’d like to achieve.

2. Sub-Program

2.1 What is Sub-program?

Sub-program is a block of code that has its unique name and in the program, where these code is need will be placed the name. And this practice will help us avoid repeating many unnecessary codes as well as accomplishing procedural abstraction.

In addition to procedural abstraction, sub-program also plays a role of encapsulation and information hiding.

2.2 Data Transfer Between Sub-programs

When defining a function, we need to set its parameters and when making a function call, we need to input some arguments according to its parameters, in which process we transfer data to the function and get a return value.

The most elementary two ways are call-by-value and call-by-reference, the latter one is more faster and efficient but will have some side effects.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值