3 ms·
"I don't know if there are programmers out there whose pseudo-language is functional. Maybe it's just human nature to think imperatively." A lot of time it jus
by jimbokun 18y ago
"I don't know if there are programmers out there whose pseudo-language is functional. Maybe it's just human nature to think imperatively."
A lot of time it just kills me that "if" statements don't default to returning the true branch or false branch. You need the ternary conditional operator in Java and other C-derivatives, and in Python you need to resort to some hack with and/or precedence.
I'm also wondering if I should declare all variables final in Java, and only change that default if I really, really have to.
- vang3lis 18y agoon python - not anymore, since 2.5 (probably earlier) you can do: (x if cond else y) which is essentially (cond ? x : y)
- jimbokun 18y agoDefinite improvement! Thanks for the information.
- jcausey 18y agoThe previous ternary hack in Python (which was still relatively elegant) was: a = ("False", "True")[condition] It's a little fugly -- but if you know the basic semantics of Python, it's quite readable. It is nice that we have a proper ternary now, though.
- EliAndrewC 18y agoActually I think the more common hack was a = cond and x or y which had the downside that if the second part (in this case x) evaluates to False then a ends up equal to y even through that's not what you were trying to do. Sometimes this is a problem and sometimes not, but it's been irrelevant for the past few years.
- jcausey 18y agoVery true. I've seen that hack before, but I guess I mentally settled on my first example (probably due to the irksome possibility of x=0\False). Unfortunately, there were probably more hacks than our two examples. Thank goodness Guido (etc) settled on a real ternary semantic -- we were heading into Perl more-than-9000-ways-to-do-something territory!
- bk 18y agoI guess that's why Ruby has been called an "acceptable lisp". I take "everything is an expression" so for granted by now, and it makes for beautiful, terse code. The non-working python if statement/assignment example from the article works perfectly fine in Ruby. (No python/ruby flamewar please, that's really not the point)
- arohner 18y agoHow about a ruby/lisp flamewar? :-) J/K. In all seriousness though, I've recently moved to Clojure from Ruby. I'm not looking back. Clojure is significantly cleaner, faster, and has better libraries than Ruby.