Can signatures be made simpler and error messages be made better?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Sat Jun 12 09:36:26 UTC 2021


On Saturday, 12 June 2021 at 08:58:47 UTC, zjh wrote:
> On Saturday, 12 June 2021 at 08:13:42 UTC, Ola Fosheim Grøstad 
> wrote:
>> One of the things I don't like about C++ is that signatures
>
> Life cycle is an range, should used `belonging to(∈), equal 
> to(==), including(∈,flips)`, and the opposite`(¢,!=)`.

Yes, you can think of it as "being within" too, but what if you 
only care about destruction order?

I am thinking that we only need "<" and "<=" for function 
signatures as we assume that the object is already constructed? 
Although maybe there are use cases where you want to be able to 
delay construction (as an optimization or for some other reason).


```
Number maximum(Number a, Number b)
require(£return <= £a && £return <= £b)
{
…
}

```

As a more advanced language extension:
```
Number maximum(Number a, Number b)
require(!(a >= b) || £return <= £a)
require(!(a >= b) || £return <= £b)
{
…
}

```

or simply

```
Number maximum(Number a, Number b)
{
    if (a >= b) {
       assert(£return <= £a)
       reuturn a
    }
    assert(£return <= £b)
    return b
}

```

(I have little experience with lifetimes in practice as I have 
not given Rust a shot yet.)



More information about the Digitalmars-d mailing list