Merge: Rename Container to Ref
authorJean Privat <jean@pryen.org>
Fri, 17 Jul 2015 21:03:18 +0000 (17:03 -0400)
committerJean Privat <jean@pryen.org>
Fri, 17 Jul 2015 21:03:18 +0000 (17:03 -0400)
commite3246a08abceacbbf6953f1a3961f2958131a11b
treeb80586e5a2aca2c4f52a5e5b11d5aabcf4c2c218
parentc51e6df9e19e4b25cb14d82b2e92a730c3b14b49
parent31fe92e3425c5f5f82ff218a7ccfbdc611784f8f
Merge: Rename Container to Ref

The `Container` class is widely misunderstood and underused.  However it can be very useful to implement a return parameter. This PR rename the class according to this usage. It will make some signatures easier to understand: (example inspired by a similar function from `UDPSocket`)

~~~nit
# This method has 3 outputs:
# * The received message written into `buffer`.
# * The number of bytes written as the return value.
# * The information on the sender of the message is stored in `sender_info`.
fun recv_from(buffer: NativeString, sender_info: Ref[nullable SocketAddress]): Int
~~~

### Bonus Ref tip!

`Ref` can also be used as a hackish equivalent to a `static` variable in C. This example use the dreaded `once` keyword to easily get a singleton, but it could be done cleaner with an attribute in `Sys`.

~~~nit
fun foo
   ...

    # Count the number of times foo is executed
    var counter = once new Ref[Int](0)
    counter.item += 1
    print "foo has been executed {counter.item} times"
end
~~~

Pull-Request: #1573
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Jean Privat <jean@pryen.org>