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?

Robert Harvey
201k55 gold badges469 silver badges682 bronze badges
asked Jan 31, 2011 at 22:21
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. Commented Mar 6, 2012 at 23:55
  • Some would say that PHP is a bad language for that very reason. Commented 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.

answered Jan 31, 2011 at 22:39
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.

answered Feb 1, 2011 at 2:38
2
  • What is MVVM? What is SRP? Commented 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 . Commented Feb 1, 2011 at 22:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.