Hacker News new | past | comments | ask | show | jobs | submit login

> All other languages should either provide a COALESCE function/operator, or a sane alternative to "||" which skips only NULL values and nothing else.

In Ruby, only nil and false are false, so you can use || to catch 0s and empty strings. In Perl, 0s and empty strings are false, but there's the // operator (as well as the || or or operators) that catches the first defined value.

I'm not sure if this is something specific to the database framework that you're using - sorry if you know all that already.




> In Ruby, only nil and false are false, so you can use || to catch 0s and empty strings.

But there's still trouble with things like boolean configuration variables ...

> In Perl [...] there's the // operator

Thanks for mentioning that! [1] The // operator is indeed a clean operator, almost equivalent to COALESCE.

So we have Perl and SQL. Any other language with such an operator?

[1] http://perldoc.perl.org/perlop.html#C-style-Logical-Defined-...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: