[#100309] How to use backport custom field — Jun Aruga <jaruga@...>
Please allow my ignorance.
9 messages
2020/10/06
[#100310] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/06
IkJhY2twb3J0IGN1c3RvbSBmaWVsZCIgaXMgb25seSBhdmFpbGFibGUgZm9yIHRpY2tldHMgd2hv
[#100311] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/06
On Tue, Oct 6, 2020 at 4:44 PM NARUSE, Yui <[email protected]> wrote:
[#100314] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/06
VGhhbmsgeW91IGZvciBjb25maXJtYXRpb24uCkkgY2hlY2tlZCBhZ2FpbiBhbmQgdG8gZWRpdCBi
[#100322] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/07
On Tue, Oct 6, 2020 at 7:25 PM NARUSE, Yui <[email protected]> wrote:
[#100326] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/07
SSBhZGRlZCB5b3UgdG8gIlJlcG9ydGVyIiByb2xlIGluIHRoZSBwcm9qZWN0CgoyMDIw5bm0MTDm
[#100327] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/07
On Wed, Oct 7, 2020 at 1:42 PM NARUSE, Yui <[email protected]> wrote:
[ruby-core:100250] [Ruby master Feature#13820] Add a nil coalescing operator
From:
akim.demaille@...
Date:
2020-10-01 08:47:06 UTC
List:
ruby-core #100250
Issue #13820 has been updated by akim (Akim Demaille).
shyouhei (Shyouhei Urabe) wrote in #note-8:
> bsarrazin (Ben Sarrazin) wrote in #note-7:
> > Kotlin has this feature, Swift has this feature, many other languages have this feature.
>
> No. Kotlin does not have this feature (distinguish `false` and `null`).
I disagree. Kotlin does have the feature which is the topic of this page: a null coalescing operator (https://kotlinlang.org/docs/reference/null-safety.html#elvis-operator). And you are rightfully stating it:
> That is why they need `?:` operator
which exactly corresponds to the proposal about `??`.
----------------------------------------
Feature #13820: Add a nil coalescing operator
https://bugs.ruby-lang.org/issues/13820#change-87837
* Author: williamn (William Newbery)
* Status: Open
* Priority: Normal
----------------------------------------
It would be nice if Ruby had an operator that only considered `nil` as false, like the null coalescing operators or "Logical Defined-Or operator" (Perl) found in some other languages. Ive seen things like `//` and `//=`m `??` and `??=`, or `?:` used for this.
This would work like `||` and `||=` for short circuiting etc. except that only `nil` is considered a false condition.
While Ruby considers only "false" and "nil" as false, with everything else true ("", [], {}, etc.) I still find occasionally people trip up when using logical or, `||` and `||=` when the value may be false.
```ruby
a = 0 || 55 # = 0 Ruby already considers 0, "", etc. as true (oter languages do differ a lot here)
a = 0 ?? 55 # = 0 So no change here
a = nil || 55 # = 55, nil is false so right side is evaulated.
a = nil ?? 55 # = 55, again no change
a = false || 55 # = 55, however false is false for logical or
a = false ?? 55 # = false, but its still a non-nil value
```
For example when doing things like:
```ruby
def lazy
@lazy ||= compute_this
end
def fetch(id, **opts)
host = opts[:host] || default_host
https = opts[:https] || true
port = opts[:port] || (https ? 443 : 80)
...
```
Normally the intention is to use a default value or compute an action if no value is provided, which if the value may be false then requires special handling, or sometimes is missed and results in a bug.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>