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
and the following code does not work
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?
In your case: yes, it's not acceptable. Conceptually the order is not important there, it's the implementation which is forcing a fixed order to work. Not nice.
In general: Of course in a non-lazy language like Ruby the order of statements matter. But it's not the same the order "dependency" in
x = 1; y = 2 * x
that one that involves state and side-effects (silly example:x = []; x << 1 if condition1?; x << 2 if condition2?; x
).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.
So if you have some code in
statement_a
that relies on behaviour added bystatement_b
then puttingstatement_b
beforestatement_a
is the only solution...