3 ms·
I'm a bit disappointed in this discussion. "strangest" language feature sounds like a crowd pointing and laughing. Boring! What are some novel, underappreciated
by silentbicycle 16y ago
I'm a bit disappointed in this discussion. "strangest" language feature sounds like a crowd pointing and laughing. Boring! What are some novel, underappreciated, unexpectedly useful language features? (And this emphatically isn't about "my favorite language vs yours".)
Here are a couple, to get things rolling.
Pattern matching. This is a favorite of mine - stating what you want (or expect), possibly with variables, and letting the language generate the tree of if/case statements. I find pattern-matching code extremely easy to read, easy to extend, almost always right the first time, etc. It works with both static (ML-style variant types, reminding you to check exhaustively) and dynamic (Erlang-style, "handle what you can or throw an exception") typing. awk is based around a weaker form of pattern matching (only matching against ints and regexes, rather than whole trees), and it's still great for quick hacks. PM seems to mesh poorly with conventional OO, though.
Compile-time metaprogramming. This is HN, you've probably heard plenty about Lisp macros, so I'll leave it at that.
Incremental development / hot code loading. Erlang has this (with soft real-time guarantees), Lisp, Smalltalk, and basically anything image-based has had this for ages. It's often easier to grow a system piece by piece than to build it upfront and plug in together afterward.
Iterators/generators. Without needing a fully lazy-by-default language such as Haskell, it's often handy to have a handle into a (possibly infinite) stream that you can pull from as necessary. Prolog combines pattern matching (unification really, a step beyond pattern matching) with backtracking, so you can write "generate and test" code: "here's what I want, this generates a stream of all possible candidates, here's how to narrow it down". It's sometimes too slow for use in production (due to combinatorial blowups), but it's excellent for prototyping, and can usually be made good enough with some tweaks.
Coroutines and actors. Like iterators and generators, but breaking the flow of execution into lots of little autonomous pieces. Communication makes dataflow explicit, most things can be easily understood in isolation, and they can often be run in parallel. (Coroutines are cooperative.)
- kanak 16y agoTo this excellent list I'd add: First Class Continuations like in Scheme.
- silentbicycle 16y agoWhat other languages have first class continuations? Scheme does, some SML implementations do (smlnj has call/cc, IIRC), Ruby has call/cc* , anything else? * But I've heard it's really not implemented for performance, and probably doesn't get used that much. I'm not really into Ruby, so...anyone? Of course, you can do CPS yourself, though realistically you need first-class functions, tail-call optimization, and garbage collection or the extra bookkeeping will make it overwhelmingly complicated.