| View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||||
| 0012455 | Insight Software Consortium | (No Category) | public | 2011-09-13 16:03 | 2011-09-13 16:03 | ||||||||
| Reporter | Benjamin Schwartz | ||||||||||||
| Assigned To | |||||||||||||
| Priority | normal | Severity | minor | Reproducibility | have not tried | ||||||||
| Status | new | Resolution | open | ||||||||||
| Platform | OS | OS Version | |||||||||||
| Summary | 0012455: WrapITK Python is not idiomatic | ||||||||||||
| Description | An 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 [^] | ||||||||||||
| Tags | No tags attached. | ||||||||||||
| Attached Files | |||||||||||||
| Relationships | |
| Relationships |
| Notes | |
| There are no notes attached to this issue. |
| Notes |
| Issue History | |||
| Date Modified | Username | Field | Change |
| 2011-09-13 16:03 | Benjamin Schwartz | New Issue | |
| Issue History |
| Copyright © 2000 - 2018 MantisBT Team |