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

merged 1 commit into from Feb 11, 2014


None yet

3 participants


Just as before, TestMode gets different logic until names are generated when S._disableTestFuncNames is true.!topic/liftweb/5G0UyCn0HBc

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

Just as before, TestMode gets different logic until names are generated
when S._disableTestFuncNames is true.
@Shadowfiend Shadowfiend commented on the diff Feb 7, 2014
@@ -2600,7 +2600,17 @@ trait S extends HasParams with Loggable with UserAgentCalculator {
- def formFuncName: String = if (Props.testMode && !disableTestFuncNames_?) {
+ def formFuncName: String = LiftRules.funcNameGenerator()
+ /** Default func-name logic during test-mode. */
+ def generateTestFuncName: String =
+ if (disableTestFuncNames_?)
+ generateFuncName
+ else
+ generatePredictableFuncName
+ /** Generates a func-name based on the location in the call-site source code. */
+ def generatePredictableFuncName: String = {
Shadowfiend Feb 7, 2014

Why not be explicit here and call it generatePredictableFuncNameFromStack?

japgolly Feb 7, 2014

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

Shadowfiend Feb 7, 2014

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.

japgolly Feb 7, 2014

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 = // ...
Shadowfiend Feb 7, 2014

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.

japgolly Feb 10, 2014

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.)

Shadowfiend Feb 11, 2014

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 Shadowfiend merged commit 17513a2 into lift:master Feb 11, 2014
@fmpwizard fmpwizard added this to the 2.6-M3 milestone Feb 11, 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 😉

Lift Web Framework member

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

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