<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="http://git.reviewboard.kde.org/r/102432/">http://git.reviewboard.kde.org/r/102432/</a>
</td>
</tr>
</table>
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<p style="margin-top: 0;">On August 27th, 2011, 12:19 a.m., <b>Milian Wolff</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">I have no clue about python: what is a decorator? the @staticmethod ? Then the def foo function definition should be marked static. What is the decorator trying to solve?</pre>
</blockquote>
<p>On August 27th, 2011, 7:08 a.m., <b>Sven Brauch</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Hey,
in python, you don't write "static int foo", but "def foo", and then foo = staticmethod(foo). The "staticmethod" function converts the "foo" function into a new one which is static. To simplify this, instead of
class my_class():
def foo(): pass
foo = staticmethod(foo)
you can also write
class my_class():
@staticmethod
def foo(): pass
Those two are equivalent. You can also define your own decorators, which take functions as arguments and return other functions. There's also a few predefined ones in python.
Doesn't PHP also have that "@" syntax? Or is that just in docstrings?
Whatever, kdev-python documentation files do something like this:
@TypeContainer
class list():
@appendsType(0)
def append(arg0): pass
This is the way to let my code know it should track the content type of "list" instances, and other decorators tell it which functions modify that content type.</pre>
</blockquote>
<p>On August 27th, 2011, 4:05 p.m., <b>Milian Wolff</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">well the static example doesn't need decorators, you just mark the function as static in the duchain
php has no @ syntax, only in docstrings
and I still don't get what the @ things in your list example are doing. Anyhow, I doubt this is required for other languages. Imo make it python-only for now until we find another language that has something like that.
bye</pre>
</blockquote>
<p>On August 27th, 2011, 4:27 p.m., <b>Davide Simoncelli</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">If I'm not wrong Java uses decorators</pre>
</blockquote>
</blockquote>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Okay, so here's another example:
-----
>>> def decorate(obj):
... obj.some_other_attribute = 42
... obj.some_attribute = 1337
... return obj
...
>>> @decorate
... class my_class(): pass
...
>>> my_instance = my_class()
>>> my_instance.some_attribute
1337
-----
The class definition construct is again equivalent to writing class my_class(): pass; my_class = decorate(my_class). A more useful example is this:
-----
def debug_return_value(func):
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)
print ret
return ret
return wrapper
@debug_return_value
def my_func(arg):
return [arg, arg]
my_result = my_func("Hello World!")
-----
The last line will, instead of just writing the return value of my_func into my_result, also print it on the screen, because my_func is replaced by the "wrapper" function by the decorator. Obviously, this is much more flexible than writing print statements all over the function.
I hope it is understandable from this what decorators can be used for.
--
Storing the decorators will be useful, if only for displaying them in the navigation widget.
I'm also okay with making this python-specific, but then I'd need some hints on subclassing data classes with appended lists, while adding more appended lists in the child class. Is this even possible? I didn't manage to do so yet, and I tried quite a few times.</pre>
<br />
<p>- Sven</p>
<br />
<p>On August 25th, 2011, 1:22 p.m., Sven Brauch wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('http://git.reviewboard.kde.org/media/rb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
<tr>
<td>
<div>Review request for KDevelop.</div>
<div>By Sven Brauch.</div>
<p style="color: grey;"><i>Updated Aug. 25, 2011, 1:22 p.m.</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This adds a list of Decorators to each class and function declaration, and a Decorator class which stores information about those decorators.
This is currently relevant for the python language, which has a pattern like this:
class c():
@staticmethod
def foo():
pass
I didn't have an internet connection for research available, but I think other languages might have similar patterns, so this can go into kdevplatform.
Also, even after several hours of experimentation I couldn't figure out how to inherit from a class which defines appended lists, adding another one... some documentation on that would be appreciated :)</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>language/CMakeLists.txt <span style="color: grey">(4399ebb)</span></li>
<li>language/duchain/classdeclaration.h <span style="color: grey">(409a3a4)</span></li>
<li>language/duchain/classdeclaration.cpp <span style="color: grey">(0670209)</span></li>
<li>language/duchain/decorator.h <span style="color: grey">(PRE-CREATION)</span></li>
<li>language/duchain/functiondeclaration.h <span style="color: grey">(7f084a9)</span></li>
<li>language/duchain/functiondeclaration.cpp <span style="color: grey">(fb442dc)</span></li>
</ul>
<p><a href="http://git.reviewboard.kde.org/r/102432/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>