top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Which one is better Ruby or Python ?

+1 vote
Which one is better Ruby or Python ?
posted May 8, 2014 by Mishthy Mukherjee

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

Broadly, Ruby and Python implement very similar models, and have similarly powerful libraries and communities. The biggest distinction is in syntax.

Ruby includes several syntactic features which make dynamic extension of and higher-order interaction with external (library) code more straightforward. In particular:

Blocks allow arbitrary, multi-line closures to be cleanly passed in-line nearly anywhere. (Closures are anonymous functions which are lexically scoped inside the point at which they are defined, so they can access enclosing stack variables.) Python allows two syntaxes for in-line closure declaration: lambdas and nested def statements. Lambdas are equivalent to Ruby blocks, in that they are expressions which evaluate to a closure (and so can be used in-line), but syntactically they can only easy express a single expression, not multiple nested statements. Nested definitions have the full syntax of any other function definitions, and so easily support multiple statements and control flow within themselves, but they are statements not expressions, so they cannot be used in-line.

Mix-ins allow imported classes and modules to be extended and overridden by user code after it is imported. Python's runtime model is sufficiently dynamic to inject new or altered methods and fields into an external class or object, but its syntax is procedural (assigning values to fields of an object), rather than declarative and identical to the standard class definition syntax.

(These are the two features to which Charlie Cheever refers.)

Most things implementable with block and mix-in syntax are also achievable in Python, they are simply less syntactically natural and clear, and so less commonly form the centerpiece of major libraries or common styles of programming.

These features, combined with a lighter-weight syntax with fewer restrictions (whitespace flexibility, optional parentheses, etc.) make Ruby more suitable to pervasive and relatively transparent use of metaprogramming.

At the same time, while this flexibility and the Ruby community's tendency to use it for metaprogramming can facilitate aesthetically pleasing code, they can also create stylistic variation in how the language is used, and obscure the mechanisms by which code actually works. (Try running a Rails app inside a debugger—the layers of dynamically-injected behavior can make it quite nontrivial to understand where and how your code is actually running.) Python's more restrictive syntax is intentionally designed to steer developers towards one canonical "pythonic" style to improve accessibility and comprehension. It is a simple tradeoff.

Suggestions Pending

answer May 9, 2014 by Brijesh Talwar
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.