NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
other languages (Score:1)
Also, ocaml's option type is way better than perl's undef. We hates undef!
Re:other languages (Score:2)
I think undef would be fantastic if Perl better supported three-value logic. Right now we have true or false. If Perl natively supported "true", "false" and "unknown", many problems could be made simpler.
I did allude to other paradigms (logic programming, to be specific), but I confess that I don't know much about OCaml.
Re:other languages (Score:1)
Ocaml has a nice distinction between a type "foo" and a type "foo option" -- the latter can be undef, whereas the former is guaranteed to have a value:
let succ_int i = i + 1;;
let succ_int_option o = match o with
| None -> 0
| Some i -> i + 1;;
Re:other languages (Score:2)
Keep to a strict convention and it's easier to remember. Don't return undef or a false value when you mean false, just return. A bare return will return undef in scalar context and an empty list in list context. By keeping to this convention, you can simplify your code. If you're returning from a ternary operator, use parens:
Personally, I usually return as soon as I know a function will fail and I don't get to the ternary operator too often (though that's not always the case. Depends upon what I'm working on).
Reply to This
Parent