7

I've started to learn a little ROR and everthing I read says that ROR espouses the DRY principle and they seem to imply that this is a big thing that makes ROR different from other languages/frameworks.

What language does encourage duplicate code?

2
  • php is often considered guilty of this; it's not that php is bad, but it is quite easy to write bad php code.
    – ford
    Mar 6, 2012 at 23:55
  • Some would say that PHP is a bad language for that very reason.
    – kingsfoil
    Sep 24, 2014 at 20:29

2 Answers 2

6

It's not that other languages encourage duplicate code, per se, but the DRY principle of Rails people is pretty extreme in that anything that might be considered repetition is programmed away using the metaprogramming features of Ruby.

For example, in many web frameworks, the database schema and the object definitions have the same fields but have to be maintained separately. In C and C++, functions often have to be declared twice—once in a header file and once in the code itself. All of this kind of repetition is strongly deprecated in the RoR ethos.

0

In the case of modern languages, it's the designs, and moreover, the architectures, that encourage or discourage DRY. Keep in mind that some architectures favor one over the the other. Example: in MVVM, SRP > DRY in most cases. In MVVM you may find several classes and/or data structures that could be considered repetitious, but the main goal is to keep each class beholden to one master rather than to keep one class from repeating the code in another class.

2
  • What is MVVM? What is SRP?
    – nohat
    Feb 1, 2011 at 3:31
  • Model-View-ViewModel (MVVM) is a presentation pattern common in WPF (.net). True, it's not a Ruby pattern, but it is an example of how a pattern and / or architecture can encourage the violation of DRY. SRP stands for Single Responsibility Principle: en.wikipedia.org/wiki/Single_responsibility_principle . Feb 1, 2011 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.