TISKBSD #1 How to articulately answer ‘What is a Lambda?’ (Java)

When a contract end nears it’s time to start interviewing again, and time to realise what we don’t know or what we do know, but can’t articulately explain.  This leads me to my first Things I Should Know But Somehow Don’t (TISKBSD) post.

I know what a Lambda is, I use them nearly every day when coding, but when asked the question I found I myself babbling far too much for my liking, so here I try to rectify that.

Writing it down should allow me to cement things in my mind and also cover any gaps in my knowledge.  I am not trying to break new ground with these posts, but simply collect topics in a suitable place largely for my own benefit and on the off-chance that others also find it useful.


What is a Lambda (in Java)?

A Lambda Expression in Java is simply a compact way to create/represent single-method classes, i.e., classes that implement a Functional Interface.   More generally a Lambda is an anonymous function.

Performance:  For most developers, Lambda Expressions, are syntactic sugar, allowing them to write more concise code, but there is a performance advantage to Lambdas over anonymous classes, because Lambdas are implemented using Java’s Invoke Dynamic mechanism (though I suspect the difference to be negligible in the vast majority of cases – one for richardstartin.uk to benchmark?).

Closures:  When an anonymous function refers to values outside it’s scope, we say it encloses those variables, i.e., it is a Closure.  In Java, a Lambda expression can only reference (enclose) final or effectively-final variables, but since these can refer to heap objects, we can make a Java Lambda Expression act like a Closure.  If I want to enclose a non-final stack variable, I usually just put it in an array of length 1 – not pretty, but it works.

Posted in Uncategorized | Leave a comment

Baby Led Development

With a baby in the house, one has little time and energy available for side-projects.  It is, therefore, important to be efficient with your time in order to make any progress when you do find yourself with a spare moment.

Recently, I have begun a side-project and found a couple of ways that my development has been ‘baby led’.  Firstly, I knew I needed a database for the project. As I was familiar with it, I decided to use Liquibase for the schema definition. Once up and running, and with a basic model in place, I began to think about adding in an ORM, but very quickly ruled it out. At this stage, I decided, it would add little benefit.

I’m not saying an ORM would be wrong for this project, but the interesting thing to me is how quickly I decided I could live without one.  In the past, or if I had more time, I probably would have included one without much thought (and then gone on to add Spring too ;)).  I can always add one later on if I feel it’s necessary and by then the model is likely to be more stable anyway.

Another tactic I have used is to do all my workflow prototyping in unit tests. This allows me to quickly experiment and refine the model and functions without polluting my src/main area.  I can then promote code from src/test when it is ready or more mature.

I don’t claim to have any ground breaking thoughts or ideas in the above. I just think it is interesting how I adapted my development in,  what I think is, a good way and that I might not have done so without being a Daddy.

Posted in Development | Tagged , , , , , , , | Leave a comment

ActivePivot: Member Properties and Analysis Hierarchies (together at last).

Analysis Hierarchies

Analysis hierarchies* are one of the key features of ActivePivot.  They allow data, aggregated in a compressed/OOP form, to be expanded dynamically at query time from a single aggregated Object to display its components individually against derived MDX Members.

A classic use case is a set of VaR scenarios that are aggregated in an array object, but are displayed with an MDX member for each scenario.

Member Properties

A standard feature of the MDX language is Member Properties.  These allow meta-data to be included with a member.  On a Pivot Table in Excel, these member properties can be displayed in a tool-tip when the user selects the member cell.  For example, a product name could be the member value, with its serial number as a member property.

In ActivePivot, Member Properties are implemented as extended plugins and then instantiated as defined for hierarchy levels in the cube schema, e.g.:

<level name="Product">
        <property name="Serial No." pluginKey="ProductSerialNumber"/>

Together at last

Unfortunately, this will not work for Analysis Hierarchies**, because their levels are created programmatically based on the plugin implementation of the hierarchy with no reference to the cube schema file.

To add member properties to an analysis dimension, one can override the createLevels() function in their class that extends ActivePivot’s external class AAnalysisHierarchy, and use reflection*** like so:

protected List createLevels() {
    List levels = super.createLevels();
            .filter(l -> !ILevel.ALLMEMBER.equals(l.getName()))
            .forEach(l -> {
                    try {
                        Map<String,IProperty> analysisMemberProperties = new HashMap<>();
                                Registry.createExtendedPluginValue(ICustomProperty.class, AlternateFormat.PLUGIN_KEY, new Object[]{"alternativeFormattedValue"})
                        FieldUtils.writeDeclaredField(l.getLevelInfo(), "memberProperties", analysisMemberProperties, true);
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException("Unable to set level member property for analysis hierarchy", e);
    return levels;

* Known as Analysis Dimensions in verions prior to ActivePivot 5.
** At least not in versions 5.1.5 or lower.
*** The field is type final.

Posted in Development | Tagged , , , , , , , , , | Leave a comment

[Reblog] 10 Modern Software Over-Engineering Mistakes

I have seen all of these and plead guilty to quite a few of them too…

10 Modern Software Over-Engineering Mistakes

Few things are guaranteed to increase all the time: Distance between stars, Entropy in the visible universe, and Fucking business requirements. Many articles simply say “Dont over-engineer” but don’t say why or how. Here are 10 clear examples.

Posted in Development | Tagged , | Leave a comment


I have, at different times, had various opinions on how to treat static analysis violations.

Using Find Bugs and Sonar Way rules, I initially saw any violation as an insult to my code and would do my best to fix all of them.  I realized, however, that this sometimes led to repetitive safety checks (null pointer) or additional code that I didn’t really want.

It’s better not to have violations, of course, but on the other hand, one doesn’t want to add too many lines of code unnecessarily or use additional libraries to fix issues that aren’t really there.

I now have a more pragmatic view and believe that the all violations should be treated as advisory.  It’s better not to have them, but it’s not always necessary to fix them.

The evolution-of-a-software-engineer joke comes to mind.

When working as a team, I think it is enough to have the following principles:

  • Try to avoid introducing new violations
  • For existing violations, have periodic reviews of the reports together as a team and identify those that should be fixed.





Posted in Development, Uncategorized | Tagged , , , | Leave a comment

[Reblog] Write code that is easy to delete

Great article here…  Write code that is easy to delete, not easy to extend.

  • “Projects either fail or become legacy code eventually anyway. Failure happens more than success. It’s quicker to write ten big balls of mud and see where it gets you than try to polish a single turd.”


Posted in Development | Tagged | Leave a comment

Testing Dojo Modules that need the DOM

This is a short post to summarize how I test Dojo 1.x modules that need the DOM.  In the future, I plan a more detailed post along with a Dojo 1.x playground repository on BitBucket with real examples, but for now I will just outline the steps I took.

The testing framework that Dojo 1.x uses is not adequate (at least as far as I could tell).  I wanted to be able to run all my tests in a build script, even those that require the DOM.

The following two articles gave me what I needed:

  1. Testing react with jsdom.
  2. Dojo and Node.js


From the first article, I borrowed the test framework and the use of jsdom to set global DOM variables.  From the second article, I borrowed the method of loading node modules with the Dojo loader.  That allowed me to load the should.js assert library in my dojo tests, which report to mocha.

    "dojo/hash",  // we are going to use the DOM.
    "dojo/node!should"  // import node module, should, which will report to mocha.
) {


To run the tests, mocha calls the following bootstrap file.  Note that, unlike in the linked article, dojoConfig sets “dom”:1.

// ---------------------------------------------------------------
// Create a DOM object and set global variables.
// ---------------------------------------------------------------
var jsdom = require('node-jsdom')
document = jsdom.jsdom('<!doctype html><html><body></body></html>')
window = document.defaultView
location = window.location;

// ---------------------------------------------------------------
// Configure dojo
// ---------------------------------------------------------------
// Array of test modules to run
dojoTestModules = ["test/main/foo", "test/main/bar"];

dojoConfig = {
    baseUrl: "../../..", // Where we will put our packages
    async: 1, // We want to make sure we are using the "modern" loader
    hasCache: {
        "host-node": 1, // Ensure we "force" the loader into Node.js mode
        "dom": 1 // Ensure that the code assumes we have a DOM
    // While it is possible to use config-tlmSiblingOfDojo to tell the
    // loader that your packages share the same root path as the loader,
    // this really isn't always a good idea and it is better to be
    // explicit about our package map.
    packages: [{
        name: "dojo",
        location: "dojo-src-full/dojo"
        name: "dijit",
        location: "dojo-src-full/dijit"
        name: "dojox",
        location: "dojo-src-full/dojox"
        name: "bootstrap",
        location: "app/bootstrap"
          name: "main",
          location: "app/main"
         name: "test",
         location: "app/tests/mocha/"
     deps: dojoTestModules 

// Now load the Dojo loader
// This will run all the tests in dojoTestModules
Posted in Development | Tagged , , , | Leave a comment

GW150914: First results from the search for binary black hole coalescence with Advanced LIGO

I’m humbled to be a co-author on this companion paper to the GW150914 detection paper.


As I said before, many congratulations to all involved.

Posted in Science | Leave a comment

“Proxy Aspects and @ManagedResource do not work together”

Mucsij!  You had the exact same problem as me (only nine years ago).

There I was, in my day job, with a classic case of XKCD‘s Wisdom of the Ancients.


In this instance, the forum was dead, so I couldn’t even try to track Mucsij down.  Fortunately, I was able to solve my issue after some time of pain and head-desk interactions.

In my case, the problem was that my @EnableAspectJAutoProxy  annotation needed proxyTargetClass set to true (default is false) – see stackoverflow.com/questions/10664182/what-is-the-difference-between-jdk-dynamic-proxy-and-cglib for an explanation on the difference.

If you are out there Mucsij, I hope you also found a solution.


Posted in Development | Tagged , , , , | Leave a comment

LinkedIn Confidential

Your name has been referred to me confidentially as someone I should be speaking with…” – A. Recruiter.

Hmmm, you could say that to everyone.

Posted in Uncategorized | Tagged | Leave a comment