May-29-2024, 10:53 AM
(This post was last modified: May-29-2024, 10:53 AM by Gribouillis.)
Thank you all for your input. I think
There is an example of a smart pointer in the standard library: weak references
Another example is that of tkinter variables, which are just pointers dereferenced by the get() method.
get_preamble_and_content()
is too specific. It gives the impression that a mediator is a container which it is not, I want to keep it clear that it is some kind of pointer. get_pointer_data()
and read_data()
are a little verbose, the 'data' could be avoided. I think I'll use the followingresource = mediator.get() # resource has members resource.preamble resource.textThe
.get()
makes it clear that we are dereferencing something. A known example isresponse = requests.get(url)We can see a url as a pointer to a resource on the internet, and it suffices to indicate that we dereference this pointer. A benefit of returning a single object is that this object's content can change later more easily.
There is an example of a smart pointer in the standard library: weak references
>>> from weakref import ref >>> class A: pass ... >>> a = A() >>> r = ref(a) >>> r <weakref at 0x7fedeedb1350; to 'A' at 0x7fedeed7f490> >>> r() <__main__.A object at 0x7fedeed7f490>Here the
__call__()
is used to dereference the pointer, but I think it is cryptic for the reader of the program. get()
is better than call.Another example is that of tkinter variables, which are just pointers dereferenced by the get() method.
string = stringvar.get()Thanks again, if you have more ideas about this, please add them to this thread.
« We can solve any problem by introducing an extra level of indirection »