You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
the return result the same
Proposed Solution
val1 := sm.get('bad_key', '')add a language feature that makes the code clearer and eliminates implicit assignments
OR :
Other Information
No response
Acknowledgements
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.