<p>Is there something like the Python descriptor protocol implemented in other languages? It seems like a nice way to increase modularity/encapsulation without bloating your containing class' implementation, but I've never heard of a similar thing in any other languages. Is it likely absent from other languages because of the lookup overhead?</p>

[{'answer_id': 34266, 'author': 'Andrew Wilkinson', 'author_id': 2990, 'author_profile': 'https://Stackoverflow.com/users/2990', 'pm_score': 3, 'selected': True, 'text': "<p>I've not heard of a direct equivalent either. You could probably achieve the same effect with macros, especially in a language like Lisp which has extremely powerful macros.</p>\n\n<p>I wouldn't be at all surprised if other languages start to incorporate something similar because it is so powerful.</p>\n"}, {'answer_id': 48974, 'author': 'Eli Courtwright', 'author_id': 1694, 'author_profile': 'https://Stackoverflow.com/users/1694', 'pm_score': 0, 'selected': False, 'text': '<p>Ruby and C# both easily let you create accessors by specifying getter/setter methods for an attribute, much like in Python.  However, this isn\'t designed to naturally let you write the code for these methods in another class the way that Python allows.  In practice, I\'m not sure how much this matters, since every time I\'ve seen an attribute defined through the descriptor protocol its been implemented in the same class.</p>\n\n<p>EDIT: Darn my dyslexia (by which I mean careless reading).  For some reason I\'ve always read "descriptor" as "decorator" and vice versa, even when I\'m the one typing both of them.  I\'ll leave my post intact since it has valid information, albeit information which has absolutely nothing to do with the question.</p>\n\n<p>The term "decorator" itself is actually the name of a design pattern described in the famous "Design Patterns" book.  The Wikipedia article contains many examples in different programming languages of decorator usage: <a href="http://en.wikipedia.org/wiki/Decorator_pattern" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Decorator_pattern</a></p>\n\n<p>However, the decorators in that article object-oriented; they have classes implementing a predefined interface which lets another existing class behave differently somehow, etc.  Python decorators act in a functional way by replacing a function at runtime with another function, allowing you to effectively modify/replace that function, insert code, etc.</p>\n\n<p>This is known in the Java world as Aspect-Oriented programming, and the AspectJ Java compiler lets you do these kinds of things and compile your AspectJ code (which is a superset of Java) into Java bytecode.</p>\n\n<p>I\'m not familiar enough with C# or Ruby to know what their version of decorators would be.</p>\n'}]
['https://Stackoverflow.com/questions/34243', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3594/']