游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2525|回复: 7

探循环和模块化的异同

[复制链接]

362

主题

3023

帖子

3553

积分

论坛元老

Rank: 8Rank: 8

积分
3553
发表于 2009-2-8 21:12:00 | 显示全部楼层 |阅读模式
循环,模块化,两者都是代码重用。不过我一直比较纳闷,他们似乎一样,又似乎不一样...

例:
generate a url
download the page by the url
filter the page
output{...} filtered result
假设这里的download是确定的, 而其他3个动词都是可变的,即:
如何generate, 如何filter, 如何output

这里为了方便,上面4句可以合并成
output{...} the filtered page downloaded by the url generated

作为例子,我们写下面的代码:

output1{...} the filtered1 page downloaded by the url generated1
output2{...} the filtered2 page downloaded by the url generated2
output3{...} the filtered3 page downloaded by the url generated3

(A) 循环。

我们假设 output1{...} == output{...}(1) , 其他一样, 那么
for n = 1 to 3
   output{...}(n) the filtered(n) page downloaded by the url generated(n)
next

(B) 模块化。

首先,我们假设 output1{...} == output2{...} == output3{...}
那么, 我们可以统统用 myoutput 代替这三个代码段
myoutput the filtered1 page downloaded by the url generated1
myoutput the filtered2 page downloaded by the url generated2
myoutput the filtered3 page downloaded by the url generated3
接着,我们假设 filtered1 == filtered(1), 以及 generated1, 则
for n = 1 to 3
   myoutput the filtered(n) page downloaded by the url generated(n)
next

我们看到, 模 块 化 可 以 减 少 本 身 的 代 码, 但 不 能 减 少 其 他 代 码

12

主题

172

帖子

174

积分

注册会员

Rank: 2

积分
174
发表于 2009-2-8 22:38:00 | 显示全部楼层

Re:探循环和模块化的异同

你做过什么游戏, 40000的RPG

362

主题

3023

帖子

3553

积分

论坛元老

Rank: 8Rank: 8

积分
3553
 楼主| 发表于 2009-2-9 00:07:00 | 显示全部楼层

Re:探循环和模块化的异同

不要吵,我在写gather

362

主题

3023

帖子

3553

积分

论坛元老

Rank: 8Rank: 8

积分
3553
 楼主| 发表于 2009-2-9 00:22:00 | 显示全部楼层

Re:探循环和模块化的异同

我突然觉得,没有必要写gather,直接用迅雷下就行了。只要写个site generater即可

12

主题

172

帖子

174

积分

注册会员

Rank: 2

积分
174
发表于 2009-2-9 07:59:00 | 显示全部楼层

Re: 探循环和模块化的异同

[em2] [em2] [em2]
sf_20092975834.jpg

3

主题

263

帖子

267

积分

中级会员

Rank: 3Rank: 3

积分
267
发表于 2009-2-11 20:20:00 | 显示全部楼层

Re: 探循环和模块化的异同

模块化增加了编码量,和实际生成的二进制大小.
循环源代码简洁,生成的二进制代码也小,但是附加了循环开销啊
哈哈,这是基本常识啊.....小学生都知道 [em19]

12

主题

733

帖子

734

积分

高级会员

Rank: 4

积分
734
发表于 2009-2-13 19:03:00 | 显示全部楼层

Re: Re:探循环和模块化的异同

instemast: Re:探循环和模块化的异同

不要吵,我在写gather


写你妹,还有,楼上发的图就是inst

1

主题

5

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2009-2-21 00:37:00 | 显示全部楼层

Re:探循环和模块化的异同

是个人都能看的出来,打酱油去,是那条狗的马甲,我真对中国东海边的岛国感觉的厌恶至极,
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 06:54

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表