4gl中的assign语句的效率如何? [英] what is the efficiency of an assign statement in progress-4gl

查看:90
本文介绍了4gl中的assign语句的效率如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么一个assign语句比不使用assign更有效?

why is an assign statement more efficient than not using assign?

同事们说:

assign
  a=3
  v=7
  w=8.

比以下效率更高:

a=3.
v=7.
w=8.

为什么?

推荐答案

您始终可以自己对其进行测试并查看...,但是,是的,它的效率稍高.还是那是我最后一次测试它.原因是编译器将这些语句组合在一起,并且生成的r代码要小一些.

You could always test it yourself and see... but, yes, it is slightly more efficient. Or it was the last time I tested it. The reason is that the compiler combines the statements and the resulting r-code is a bit smaller.

但是效率几乎总是一个不佳的理由.为了避免磁盘IO或选择更有效的算法,在这里和那里节省一微秒的时间显得微不足道.很好的理由:

But efficiency is almost always a poor reason to do it. Saving a micro-second here and there pales next to avoiding disk IO or picking a more efficient algorithm. Good reasons:

0)在黑暗时代,每个程序的r代码限制为63k.这是减小r代码大小并保持在该限制以下的方法(好的,这可能不是好的"理由).另一种有用的方法是,您还可以经常避免使用DO ... END对,并进一步减小r代码的大小.

0) Back in the dark ages there was a limit of 63k of r-code per program. This was a way to reduce the size of r-code and stay under that limit (ok, that might not be a "good" reason). One additional way this helps is that you could also often avoid a DO ... END pair and further reduce r-code size.

1)创建记录时,属于索引的字段将在分配时(而不是在事务结束时)写回到数据库中-将所有分配分组到一个语句中有助于避免不一致脏读. (这可能是最好的理由了.)

1) When creating a record the fields that are part of an index will be written back to the database as they are assigned (not at the end of the transaction) -- grouping all assignments into a single statement helps to avoid inconsistent dirty reads. (This is probably the best reason to still do it.)

2)可读性-您可以辩称,将连续的作业分组可以更清楚地显示您的意图,因此更具可读性. (我喜欢这个原因,但并非所有人都同意.)

2) Readability -- you can argue that grouping consecutive assignments more clearly shows your intent and is thus more readable. (I like this reason but not everyone agrees.)

这篇关于4gl中的assign语句的效率如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆