comp.lang.ada
 help / color / mirror / Atom feed
From: Peter Chapin <PChapin@vtc.vsc.edu>
Subject: Re: Top 10 Worst C# Features
Date: Sat, 5 Sep 2015 08:07:24 -0400
Date: 2015-09-05T08:07:24-04:00	[thread overview]
Message-ID: <MPG.3054a4bb76ba739c989683@text.giganews.com> (raw)
In-Reply-To: d4vhcnF9eulU1@mid.individual.net

In article <d4vhcnF9eulU1@mid.individual.net>, 
niklas.holsti@tidorum.invalid says...

> I have long wished for an easier way to return multiple results from a 
> call, especially when the set of results that is really available 
> depends on the run-time outcome of the call, for example on whether the 
> called operation succeeded or failed in some way.

Functional languages have thought about this. Most provide a way of 
defining a kind of variant record with very lightweight syntax so 
defining a new record for each use isn't onerous.

As an example Scala (for instance) has an Option type in its library 
specifically for use by functions that may not have a valid value to 
return. A function that might or might not return an integer can be 
declared to run an Option[Int] (like a generic instance) that either 
holds the integer in question or has the special value None. This can be 
simulated in Ada without too much pain but what makes functional 
languages different is that it is easy to define and use variations of 
this idea without a lot of ceremony.

> Then it should be possible to call a procedure in a way that opens a 
> block that implicitly starts with a case statement and separates into 
> different branches for different outcomes...

This is done using pattern matching in functional languages which, as 
you observe, complements the features above very nicely. Actually Scala 
provides higher order methods on the Option type that allows you, in 
that case, to operate on data that might or might not be there without 
worrying about checking for its existence until the last minute. This 
pushes error handling out of the main logic of your program without 
using exceptions for that purpose.

I'm not sure how possible it would be to retrofit these ideas into Ada. 
I'm going to guess it would be hard. Ada is not a functional language 
and as soon as you start walking down the path I'm talking about here 
you end up dragging in a lot of the usual functional machinery.

Peter


  parent reply	other threads:[~2015-09-05 12:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02 10:59 Top 10 Worst C# Features Stefan.Lucks
2015-09-02 17:37 ` Álex R. Mosteo
2015-09-02 19:39 ` Randy Brukardt
2015-09-03  8:14   ` Georg Bauhaus
2015-09-03  9:26     ` Dmitry A. Kazakov
2015-09-03 11:39       ` G.B.
2015-09-03 12:00         ` G.B.
2015-09-03 13:59           ` Dmitry A. Kazakov
2015-09-03 19:12           ` Randy Brukardt
2015-09-04  7:33             ` Georg Bauhaus
2015-09-04 21:34               ` Randy Brukardt
2015-09-05  6:31                 ` Dmitry A. Kazakov
2015-09-05  6:44                 ` Georg Bauhaus
2015-09-05  7:07                   ` Dmitry A. Kazakov
2015-09-05  6:45                 ` Niklas Holsti
2015-09-05  7:21                   ` Dmitry A. Kazakov
2015-09-05 12:07                   ` Peter Chapin [this message]
2015-09-06 10:45                   ` Georg Bauhaus
2015-10-13 19:57                   ` Eryndlia Mavourneen
2015-09-05  7:16                 ` Shark8
2015-09-03 13:47         ` Dmitry A. Kazakov
2015-09-03  8:51 ` gautier_niouzes
2015-10-01 14:03 ` Paul Colin de Gloucester
2015-10-14  8:00   ` Maciej Sobczak
2015-10-14 14:26     ` Ben Bacarisse
2015-10-14 16:50       ` Paul Rubin
2015-10-14 18:17         ` Stefan.Lucks
2015-10-14 19:54           ` Ben Bacarisse
2015-10-15 12:24       ` Maciej Sobczak
2015-10-15 13:59         ` Ben Bacarisse
2015-11-06 14:50     ` Nicholas Collin Paul de Gloucester
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox