New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added LiftRules.funcNameGenerator which controls the logic of S.formFuncName #1506

Merged
merged 1 commit into from Feb 11, 2014

Conversation

Projects
None yet
3 participants
@japgolly
Copy link
Contributor

japgolly commented Nov 28, 2013

Just as before, TestMode gets different logic until names are generated when S._disableTestFuncNames is true.

https://groups.google.com/forum/#!topic/liftweb/5G0UyCn0HBc

Added LiftRules.funcNameGenerator which controls the logic of S.formF…
…uncName.

Just as before, TestMode gets different logic until names are generated
when S._disableTestFuncNames is true.
generatePredictableFuncName

/** Generates a func-name based on the location in the call-site source code. */
def generatePredictableFuncName: String = {

This comment has been minimized.

@Shadowfiend

Shadowfiend Feb 7, 2014

Member

Why not be explicit here and call it generatePredictableFuncNameFromStack?

This comment has been minimized.

@japgolly

japgolly Feb 7, 2014

Author Contributor

My thinking was generatePredictableFuncName describes the purpose and not the how.

This comment has been minimized.

@Shadowfiend

Shadowfiend Feb 7, 2014

Member

Fair, but in this caseI feel like the purpose is important. It answers the question “why would I ever want to replace this” ;) If the configurable hook were this method, it would make sense for it to be non-specific, but since the hook is funcNameGenerator, I think we benefit from specificity. Could be wrong, though; willing to hear different thoughts.

This comment has been minimized.

@japgolly

japgolly Feb 7, 2014

Author Contributor

You mean you feel like the how is important? I think I see your point, if it were more specifically named it would make it easier to answer the question "why would I ever want to replace this". Personally I don't think many people would ask that question though, I imagined it would be "what do I get from using this".

Both our perspectives are valid. That considered I guess the most technically appropriate would be:

// Default for those who don't care how and just want a deterministic ID.
def predictableFuncName = predictableFuncNameDerivedFromStackTrace

// For those concerned with or dependant on the stack-trace approach specifically
def predictableFuncNameDerivedFromStackTrace = // ...

This comment has been minimized.

@Shadowfiend

Shadowfiend Feb 7, 2014

Member

I think that approach makes sense if predictableFuncName is replaceable. In this context, it really isn't, which is why I figure you can just shortcut to the specific, purpose-tied name. The specific one answers “what do I get” both generally (it's predictable) and specifically (it's from the stack). This can be useful because there are cases where the predictable generator actually is too predictable—you can get duplicates at times, leading to weird behavior—and knowing that it comes from the stack trace as a user might help tell you what weirdness is happening without having to get into the nitty gritty of what the framework is doing.

Basically my attitude for the framework is the less work for a user doing debugging, the better. I can see this helping that goal.

I don't consider it a huge deal, and other than that this PR looks good.

This comment has been minimized.

@japgolly

japgolly Feb 10, 2014

Author Contributor

Can you explain why you think predictableFuncName is not replaceable? I can't think of any reasons why it wouldn't be, in fact I'd hope that one day it gets a better implementation that works in all cases (it fails given my usage).

I get your point about making life as easier as possible for the framework user and I agree. It is a noble goal. I'm not sure that making the function name more specific would help too much as it would already take a bit of digging to get to that point and it doesn't call out to user code meaning for the name to show up in a debugger they'd either need to do lots of stepping or already be aware of the functions existence and have set a breakpoint.

(Personally I think that generateTestFuncName which is there to preserve existing behaviour, is more of a barrier to clarity and comprehension.)

This comment has been minimized.

@Shadowfiend

Shadowfiend Feb 11, 2014

Member

I meant runtime-replaceable. I'm also not sure it should be publicly callable.

In general, I have a preference for encoding some things in the function name that others put in the comment above it. I find that makes it more likely for the thing that describes what the function does to be updated when the implementation changes, vs the comment which is often left behind.

Net net, I'm good to go on this. Haven't seen any other objections, so I'm going to go ahead and merge it. Hang onto your butts 😎

Shadowfiend added a commit that referenced this pull request Feb 11, 2014

Merge pull request #1506 from japgolly/liftrule_for_funcname_gen
Added LiftRules.funcNameGenerator which controls the logic of S.formFuncName

Introduce a funcNameGenerator volatile var in LiftRules that points to a function that
generates a function name when called. Defaults to S.generateTestFuncName in
test mode, S.generateFuncName otherwise, and these have the same implementations
as the previous implementations for test and other modes.

@Shadowfiend Shadowfiend merged commit 17513a2 into lift:master Feb 11, 2014

@fmpwizard fmpwizard added this to the 2.6-M3 milestone Feb 11, 2014

@japgolly

This comment has been minimized.

Copy link
Contributor Author

japgolly commented Feb 12, 2014

@Shadowfiend Cheers Antonio. If later you'd like me to fine-tune some of the things we were talking about I'll be happy to, just ping me 😉

@fmpwizard

This comment has been minimized.

Copy link
Member

fmpwizard commented Nov 29, 2014

In case this comes up again, we are using a volatile var instead of a FactoryMaker due to performance reasons. This code path is critical for Lift, so we need to keep it as fast as possible.

Numbers gathered by @farmdawgnation

Var test time: 58 millis
FactoryMaker test time: 504 millis

more details at https://github.com/farmdawgnation/factorymaker-performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment