A
A
Alexander Grishin2016-03-19 20:17:36
Ruby on Rails
Alexander Grishin, 2016-03-19 20:17:36

There is an opinion that metaprogramming does not take place in web projects. Is it so?

Actually the question is in the header. If so, what is it for? And how can it affect a high-load project? If the speed, namely interpretation (not development), falls then by how much in percentage if the implementation were without it? Would the speed drop be essential to not use metaprogramming? Maybe someone has real experience comparing all the pros and cons?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Burmakin, 2016-03-19
@Freika

This is not true. Metaprogramming, as elsewhere, serves the web to reduce the amount of code. The speed depends more on the code than on the language (as always in the interpreted ones). I worked in a team where there were about 10 projects using metaprogramming, everything worked like clockwork.

C
CorbenDallass, 2016-04-08
@CorbenDallass

Metaprogramming can help structure your code and improve performance. Let's say you have a module (concern) that adds some functionality to different objects. Let's call them objects and subjects.
One class may have

include MyModule
act_as_object

In a different
include MyModule
act_as_subject

In the act_as_object and act_as_subject methods, we already create the necessary method sets
module MyModule
  def act_as_object
    define_method :obj_meth_1 do; end
    define_method :obj_meth_2 do; end
  end
  def act_as_subject
    define_method :subj_meth_1 do; end
    define_method :subj_meth_2 do; end
  end
end

Thus, the functionality needed for different models is collected in one place, and when you connect the module, you can choose which specific methods to add to them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question