Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


About using Java Reflection

Fred Daoud
  • Fred Daoud
    Fred Daoud

    As of the 0.7 release of FunctionalJ, objects of the Function class use Java Reflection behind the scenes. Some (but not all) of the consequences are:


    - Code is simpler, clearer and more concise;
    - Existing methods can be used without modification;
    - No particular interfaces need to be implemented;
    - Functions can refer to any method regardless of the type and number of parameters;
    - others.


    - Slower performance;
    - Code becomes more difficult to refactor and to debug;
    - Some features provided by IDEs do not work well with code that uses Reflection;
    - others.

    I am considering, for a future release, to provide both options: using Reflection or implementing an interface, so that people can decide which pros they prefer, or which cons have less impact on them.

    Frederic Daoud

    • andrew cooke
      andrew cooke

      personally, i like the reflection approach, but providing both would let people use the more efficient case when optimising inner-loops (more practically, perhaps, people who use "efficiency" as their single measure of "good" won't dismiss the project).  in particular, i like how functionalj ends up (in my code at least) being used as "glue" that connects methods in existing classes together - functionalj allows me to use a functional approach to composition while keeping the rest of the program in "plain old java".  this feels like a good compromise (if i want to write all my code in a more functional style i could use scala, or ocaml, or ml, or haskell, in some kind of progression towards "purity" - functionalj sits nicely to the left of that list).

      anyway, what i was posting to ask was - could you add templates to Functions (to make return types explicit)?  there are still going to be casts because method names are strings, but they could be isolated in the function definitions, rather than occurring whenever a function is called.

      • Fred Daoud
        Fred Daoud

        Hi Andrew,

        I'm working on the next version of FunctionalJ, which will include both JDK 1.4 and 1.5 versions. The 1.5 version will use type parameters so that you can define the type of the function's result as well as the types of the parameters for functions with a fixed number of parameters.

        I'm hoping to release FunctionalJ 0.8 within the next couple of months.

        If you have any more comments or suggestions please let me know.