Suggestion: Forward Methods to Object Variables
Posted: Fri Jan 03, 2014 1:44 am
I have an unusual suggestion. First, let me outline the problem I am trying to solve. Imagine you are making a custom class for WX.Net. This class is a labeled text entry box. It inherits wx.Panel and has the object variables .label (wx.StaticText object) and .entry (wx.TextCtrl object). If you want to support many of the methods TextCtrl supports you have to do the following:
That's fine for two methods. It gets annoying for 30. I propose the following syntax:
The above is the equivalent of:
This makes code much shorter, and generates docstrings from TextCtrl and StaticText (the programmer may make a mistake in the docstring, or may be too lazy to write docstrings for all the borrowed methods)
Thoughts?
Wow, trying to post this on a smartphone was annoying.
def getValue as String
"""Returns text in entry box"""
return .entry.getValue
def setValue(text as String)
"""Sets the text in the entry box"""
.entry.setValue(text)
That's fine for two methods. It gets annoying for 30. I propose the following syntax:
- Code: Select all
forward to .entry
getValue
setValue
forward to .label
getLabel
setLabel
The above is the equivalent of:
def getValue as String
"""Docstring imported from wx.TextCtrl method"""
return .entry.getValue
def setValue(text as String)
"""Docstring"""
.entry.setValue(text)
def getLabel as String
"""Docstring"""
return .label.getLabel
def setLabel(text as String)
"""Docstring"""
.label.setLabel(text)
This makes code much shorter, and generates docstrings from TextCtrl and StaticText (the programmer may make a mistake in the docstring, or may be too lazy to write docstrings for all the borrowed methods)
Thoughts?
Wow, trying to post this on a smartphone was annoying.