使陈述依赖于其他陈述的顺序是一个好主意吗? [英] Is it a good idea to make statements to depend on the order of other statements?
问题描述
我之前的问题,一个答案( @Andy H )说相关问题是陈述的顺序。那么,一般来说,是否具有前后语句依赖关系是正确/正确?例如,如果我有以下工作代码
After a my previous question, an answer (@Andy H) said that the related problem was the order of statements. So, in general, is it "correct" / "right" to have "before-after statement dependencies"? That is, for example, if I have the following working code
class Article < ActiveRecord::Base
acts_as_list ...
include MyModule
end
以下代码不工作
class Article < ActiveRecord::Base
include MyModule
acts_as_list ...
end
是否有一些不好的理由不继续执行该类?也就是说,一般来说,是一个好主意,使语句依赖于其他语句的顺序吗?
Is there some "bad" reason to do not continue the implementation of the class? That is, in general, is that a good idea to make statements to depend on the order of other statements?
推荐答案
我认为这不是好与坏的问题。
I think this is not a question of "good" vs "bad".
恰好是代码从上到下执行的情况。
It just happens to be the case that code gets executed from top down.
因此,如果您在 statement_a
中有一些代码依赖于 statement_b添加的行为
然后在之前放入
是唯一的解决方案...... statement_b
,statement_a
So if you have some code in statement_a
that relies on behaviour added by statement_b
then putting statement_b
before statement_a
is the only solution...
这篇关于使陈述依赖于其他陈述的顺序是一个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!