Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Writing C++ code that's as functional as I think is reasonable; lots of recursive function objects operating on containers, but with mutable data.


I have a similar approach for Java:

- as functional as possible, using classes almost only as namespaces.

- lots of little inner classes as data tuples.

- lots of recursive functions filling in/trimming out containers.

- the 'final' keyword is the best of the lot.

And no standard boiler-plate "patterns" for which the java language is sadly know (and which make java code unreadable, unpleasant, and altogether a horrible experience).


Why not take the jump and just use Scala? I have. :)


I second that (using Scala), it's amazing. Totally compatible with Java and the JVM, but lets you mix in really concise functional programming, along with a dozen other big pluses and scores of little treats (for a long-time Java programmer like me). We're using it as the primary language for our start-up. I use the Emacs mode for syntax-highlighting and indentation (and I've fixed a couple annoyances). I use two Emacs shell-mode buffers for a scala prompt and a shell prompt to run build scripts (I don't use whatever facilities scala-mode has for those things).


what editor are you using for scala? The eclipse plug barely does anything and I am fed up of using the scala interpreter on emacs :(.


Sorry to say that I use emacs, so I can't help you too much. It occasionally screws up indentation but otherwise stays out of my way.

(I'm far from an emacs power user -- also I don't use the interactive toplevel much, and never from inside emacs; instead I throw that sort of thing in run-once junit code in case it becomes a test suite.)


Because Scala still has a lot of the verbosity of java. So I'd rather use plain java for the plumbing, and then use concise, clean, reads-like-documentation short jython scripts for high-level programming.

[edit: by which I mean I don't have such a need for properly functional programming with function-as-argument etc. Most of what I do is plain ol' number crunching, paired with threading.]

[edit 2: i.e. "blub" is better. I have to give scala a better look one of these days.]


If I were in an arguing mood, I'd say that in terms of verbosity, scala is closer to jython than it is to java... the only major number-of-characters difference is that you need type annotations for method arguments (and return value if it's recursive).

Still from a 'conciseness' point of view and ignoring all the benefits of closures, first-class-functions, and other goodies, scala still has some serious awesomeness to serve up, especially when navigating the world of Enterprisey Java Libraries: implicit conversions. A good explanation is here: http://www.artima.com/weblogs/viewpost.jsp?thread=179766

There are also some downsides, of course ... I'd say they can all be summed up by the facts that scala is a young language, still evolving, and it is a large language with lots of features (some rather hard to grok at first).

Cheers!


What does your code look like? I'd love to see an example. While I have to implement a decent amount of scaffolding (lots of brain-dead constructors for simple function objects), being able to overload operator() helps.




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

Search: