-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.This issue is made to request a feature or an enhancement to an existing one.
Description
Describe the feature
i hate the default zero value in Go.
the default return zero value makes it hard for me to tell whether it's none or 0
Use Case
module main
fn main() {
sm := {
'abc': 'xyz',
'def': '',
}
val1 := sm['bad_key']
val2 := sm['def']
println('bad_key is :${val1}--')
println('def is :${val2}--')
}
out >>
bad_key is :--
def is :--
the return result the same
Proposed Solution
module main
fn main() {
sm := {
'abc': 'xyz',
'def': '',
}
val1 := sm['bad_key'] // panic: key not found: bad_key
val1 := sm.get('bad_key', 'bad') // val1 is 'bad'
val2 := sm['def']
println('bad_key is :${val1}--')
println('def is :${val2}--')
}
out >>
bad_key is :bad--
def is :--
val1 := sm.get('bad_key', '')
add a language feature that makes the code clearer and eliminates implicit assignments
OR :
val1 := sm['bad_key'] or {
println('bad_key is not found')
'default_value'
}
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
Version used
v 0.4.9
Environment details (OS name and version, etc.)
windows
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Avey777D4MI4NX
Metadata
Metadata
Assignees
Labels
Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.This issue is made to request a feature or an enhancement to an existing one.