|
> From: James Rich > > I am saying that returning a pointer to private storage is bad design and > using static to fix that problem continues the bad design. static has > good uses. Using it to keep your storage around so you can return a > pointer to it is not one of them. What do you consider "private storage"? If you are talking about internal state-holding variables, then certainly it's a bad idea to expose them. On the other hand, there are a number of times when a subprocedure might need to return a pointer to internal storage. These are typically called "factory" methods, and a typical example is a connection pool. While certainly not as common in RPG as in OO languages, the idea of a factory class is still perfectly valid. Let's take Nathan Andelin's template-based HTML generation, for example. It would make a ton of sense to have a factory method that loads and caches these templates, returning pointers to them on request. The argument might be that a pool of objects returned from a factory are not "private storage". While true from a "common sense" standpoint, there is no particular attribute that automatically indicates that a given object is "private storage" or "public storage". It's pretty much a matter of definition. There are other reasons to return a pointer to private storage. Again, I'm talking in general terms rather than specifically in RPG terms, but it is much easier (and faster) to compare two pointers to structures rather than to compare the entire contents of the structure. Let's say a method is designed to return one of several structures. It can either create a new clone of the structure each time, or a pointer to an internally defined structure. If this method always returns a pointer to a specific internally defined structure, a programmer may use a much more efficient pointer comparison to determine equality. Anyway, my point is that determining whether a given technique is "right" or "wrong" really depends upon the implementation and the reason. Joe
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.