History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-503
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Marcus Griep
Reporter: Arron Washington
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Better naming of autogenerated methods that represent closures / callables

Created: 05/Oct/05 11:19 AM   Updated: 11/Apr/08 01:45 AM
Component/s: Compiler
Affects Version/s: 0.6
Fix Version/s: 0.8.2

Time Tracking:
Not Specified

File Attachments: 1. Text File closurename.patch (4 kb)



 Description  « Hide
It would be nice to have a better way of naming auto-generated code that represent closures.

Right now its __closure1, __closure2, __closure3...

I think a better way to name them would be, "__ClassClosureName" for members, or "__ClassMethodClosureName" for closures declared inside of a method... etc.

The way they're currently declared, its practically impossible to use profiling applications like NProf or ANTS with Boo. :/



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Arron Washington - 06/Oct/05 02:37 PM
Bamboo mentioned that he would like those closures to be in their own namespace, but the clever bastard escaped from IRC before I could pull more information out of him.

What does you, the viewer, think? One way or another, BOO-503 will come to pass, so do not ph33r the inevitable.


Arron Washington - 07/Oct/05 06:07 PM
At the moment the naming scheme is basically "ParentClass.__closureUniqueID"

I was thinking about what kind of attributes could be used to uniquely name a closure while still giving enough context someone trying to debug a problem, and thought of this:

"__ParentClass.Closure_LINE_COLUMN"
class t:
def method():
z = { }

This would be: __t.Closure_3_15

This way is undeniably specific; you know where, exactly, this particular closure was declared. Its not very friendly to the eyes, though.

Another way is,

__ParentClass.LocalNameClosure/Callable_LINE_COLUMN

So now it would looke like, __t.zClosure_3_15

Now its a little more distinct, and if the variable is uniquely named enough I can just go to that particular chunk of the source code and search for it.

What happens to this, though?

a = { print 'wtfpwned' }
a = { print 'another closure entirely' }

What should the second closure be named? If we follow the second set of suggested naming rules, then we've got two closures named very similarly.

They are distinct, of course, __aClosure_1_1 and __aClosure_2_2.

With the first form, you don't have that sort of potential visual confusion, but you lack the potential ease of use of identifying them by parameter name.

With the second form, its vice versa.

Hm.


Doug H - 08/Oct/05 11:05 AM
closurename.patch tacks line and column number to the end of closure and callable names.
Also it adds support for docstrings to closures. Start a closure with a standalone string that starts with "Name:" and it will be converted to the node's docstring, like below. The name after "Name:" will be used for the closure and callable names instead of the default name.

Edit the patch to suit your tastes.

c1 = {"Name:FirstMethod"; print("c1")}
c1()

c2 = def(x as int):
"""Name: AnotherMethod
Some other documentation..."""
print "c2", x
c2(3)


Arron Washington - 08/Oct/05 11:52 AM
Ok, I really like this patch better than my proposed musings. I think that could easily be considered suitable.

The patch looks really nice!


Sorin Ionescu - 08/Oct/05 11:36 PM
Speaking of smart callable naming, I would like to have short event definition like VB:

public event SomeEvent as callable(sender, e as SomeEventArgs)

That would generate the following in the type where it is defined.

public callable SomeEventHandler(sender as object, e as SomeEventArgs) as void

Right now, this is supported:
public event SomeEvent as callable(object, SomeEventArgs), which generates some ugly delegates with arg0, arg1, etc. as parameters.


Rodrigo B. de Oliveira - 10/Apr/08 05:39 PM
I think the names are good now, no?

Marcus Griep - 10/Apr/08 05:56 PM
There are still some of the form __callable# that are made. For those, I'm thinking adding the line number/column number and method/class/module name if available. How does that sound?