Do some variable name cleanup in lift-json. #1519

Merged
merged 3 commits into from Mar 30, 2014

2 participants

@farmdawgnation
Lift Web Framework member

We have a memo named declaredFields and another named declaredFieldsMap, that was added recently to prevent us from having to reflect on each retrieval of the declared fields. These names are a bit confusing, so let's change them up.

I'm thinking hasDeclaredFieldsMemo and declaredFieldsMemo.

@farmdawgnation farmdawgnation added this to the 2.6-M3 milestone Feb 15, 2014
@farmdawgnation farmdawgnation added the JSON label Feb 15, 2014
@farmdawgnation farmdawgnation self-assigned this Feb 15, 2014
@farmdawgnation farmdawgnation Clarify some of the Memo names used in Meta.Reflection.
I noticed when we merged a PR that the names of the various Memos in
Meta.Reflection were getting a bit confusing, so I've cleaned them up a
bit to 1) reduce confusion between what are now called
hasDeclaredFieldsMemo and declaredFieldsMemo and 2) to clarify what the
primaryConstructorArgumentsMemo actually contained.
bf56a65
@Shadowfiend
Lift Web Framework member

Since Memo is an internal thing here, thoughts on making Memo take a function that actually populates the memo for a given entry, and have the things that call e.g. hasDeclaredFields call the memo directly instead? I'm thinking a pattern kind of like RequestVar, something like:

  private val classHasDeclaredField = new Memo[(Class[_], String), Boolean]({
    case (clazz, name) =>
      try {
        clazz.getDeclaredField(name)
        true
      } catch {
        case e: NoSuchFieldException => false
      }
  })

Used as:

  def hasDeclaredField(clazz: Class[_], name: String): Boolean = classHasDeclaredField((clazz, name))

Still not 100% clean, but I think it's a little cleaner, and puts the thing that the memo is memoizing in the same place as the memo itself.

Thoughts?

@Shadowfiend
Lift Web Framework member

Oh and also… hasDeclaredField is no longer being used. Looks like #1517 also removed the call to it, so it's dead code now heh.

@Shadowfiend
Lift Web Framework member

@farmdawgnation any updates on this?

@farmdawgnation
Lift Web Framework member

Lol. Yeah, completely forgot this existed. Adding a reminder to myself to update it so we can get it merged.

@farmdawgnation
Lift Web Framework member

Will (hopefully) get to it tomorrow or Tuesday.

@farmdawgnation
Lift Web Framework member

I looked at the change you suggested. I like it. I started doing it but it's more than a simple cut-and-paste. Some of the code that is passed to populate the memo uses variables generated inside the functions where the memo is called, meaning I'd have to take a deeper look at how the code in there is architected to make it happen. Deeper than I want to do in this particular PR this evening.

What do you say we merge this and create a ticket for looking at implementing those changes?

@Shadowfiend
Lift Web Framework member

I'm down.

@Shadowfiend
Lift Web Framework member

I'll try and have a look/merge later tonight.

@farmdawgnation
Lift Web Framework member

Ping. ;)

@Shadowfiend
Lift Web Framework member

Tests passing, code looks good, this guy looks good to go. 👍

@Shadowfiend Shadowfiend merged commit 78546a0 into master Mar 30, 2014
@Shadowfiend Shadowfiend deleted the msf_issue_1519 branch Mar 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment