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?
-
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– ford2012年03月06日 23:55:26 +00:00Commented Mar 6, 2012 at 23:55
-
Some would say that PHP is a bad language for that very reason.kingsfoil– kingsfoil2014年09月24日 20:29:08 +00:00Commented Sep 24, 2014 at 20:29
2 Answers 2
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.
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.
-
-
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 .Daniel Auger– Daniel Auger2011年02月01日 22:16:51 +00:00Commented Feb 1, 2011 at 22:16