View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0012455Insight Software Consortium(No Category)public2011-09-13 16:032011-09-13 16:03
ReporterBenjamin Schwartz 
Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusnewResolutionopen 
PlatformOSOS Version
Summary0012455: WrapITK Python is not idiomatic
DescriptionAn uninformed opinion:

According to [1], a goal for ITK 4 wrapping is: "Have ITK behaves in the different languages as close to the native code as possible"

The python example at [2] has the code:

"""
reader = readerType.New()
writer = writerType.New()
reader.SetFileName( argv[1] )
writer.SetFileName( argv[2] )
writer.SetInput( reader.GetOutput() )
writer.Update()
"""

IMHO this is unpythonic. In idiomatic python the interface would be

"""
reader = readerType()
writer = writerType()
reader.fileName = argv[1]
writer.fileName = argv[2]
writer.input = reader.output
writer.update()
"""

The specific issues are:
1. Factory methods (i.e. New()) are uncommon in Python. Instead, the name of the type is called directly as a constructor to instantiate and initialize a new object. This is semantic sugar over the __new__ and __init__ methods.

This pattern is used by list(), set(), dict(), str(), int(), file(), and also the complex types in the standard library.

2. Explicit Setters and Getters are discouraged in Python. Instead properties should be accessed directly. When the object needs a setter or getter to maintain internal state, it should be hidden behind a property() abstraction [3].

[1] http://cmake.org/Wiki/ITK_Release_4/Wrapping [^]
[2] http://cmake.org/Wiki/ITK_Release_4/Wrapping/Examples [^]
[3] http://docs.python.org/library/functions.html#property [^]
TagsNo tags attached.
Attached Files

 Relationships

  Notes
There are no notes attached to this issue.

 Issue History
Date Modified Username Field Change
2011-09-13 16:03 Benjamin Schwartz New Issue


Copyright © 2000 - 2018 MantisBT Team