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

I just don't see how

  JWalk.getString(user, "them", "public_keys", "primary", "bundle");
is better than

  user.them.public_keys.primary.bundle
What am I missing?


In Ruby or Python or JS, you should be able to do the user.them... form. In a statically typed language like Java or Go it’s harder, and I happened to be working on an Android app, thus Java.


Failure semantics are the obvious ones. At the very least you'll need some flavor of

    try {
      user.them.public_keys.primary.bundle
    } rescue {
      OhDamn
    }
Less obvious is the potential for multiple targets. JWalk probably doesn't do this, but it could. For more ideas for how this could work take a look at

http://research.microsoft.com/pubs/77415/theessenceofdataacc...


That JWalk library is in Java so there won't be something you can use dynamically like that.


You can use GSON and just parse your objects into POJOs and access them with dot notation.

In fact, now that I think about it, I wonder if you can rig up your POJOs as Java 8 Option<> and remove some of the null checking. I'll have to look into that.


That's a good place to start. Basing it on the list monad instead of the option monad gives you traversals with monoidal summaries.


AH! That's the missing piece for me. I thought this was all in JS.


What if them is `undefined`? You'll get an exception when usually you just want `undefined` as the answer.

As a side note, Ember.js has a nice method for this built in, that works on plain old Javascript objects as well as the heavier Ember ones:

Em.get(obj, 'user.them.public_keys.primary.bundle')


try{} ?


Not blowing up when one part of the chain goes "undefined"




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

Search: