Sujet : Re: New VSI post on Youtube
De : seaohveh (at) *nospam* hoffmanlabs.invalid (Stephen Hoffman)
Groupes : comp.os.vmsDate : 25. Aug 2024, 02:33:39
Autres entêtes
Organisation : HoffmanLabs LLC
Message-ID : <vae1lj$1jrbm$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Unison/2.2
On 2024-08-20 12:36:51 +0000, Simon Clubley said:
One thing I wish was available in all languages is the ability to return multiple values from a function call so you can return both a status and the value(s) in one assignment. Ie: "a, b, c = demo_function(param1, param2);".
In languages with dynamic associative arrays (such as PHP), I simulate this by returning an associative array from a function call with both status and value fields. Makes coding _so_ much cleaner and robust.
For those following along at home, C supports returning a struct.
Languages including Swift allow returning an "optional", where you either get a value such as an object, or an indication or its absence. Swift uses the concept of "unwrapping" a result marked optional, which means you have to check before access.
Returning objects is more widely available, and hides a lot of this mess, as well as hiding dealing with potentially-larger data buffers. Objects and message-passing is akin to itemlist-based APIs, dragged forward a few decades.
In other languages, support for an optional requires explicit code, whether that might return a struct, or might return a value and a sentinel, or ilk.
-- Pure Personal Opinion | HoffmanLabs LLC