-
Notifications
You must be signed in to change notification settings - Fork 275
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2013 WorldWide Conferencing, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.liftweb | ||
package http | ||
|
||
import org.specs2.mutable.Specification | ||
import util.Helpers | ||
import util.Props.RunModes | ||
import LiftRules.defaultFuncNameGenerator | ||
|
||
object SSpec extends Specification { | ||
"S Specification".title | ||
|
||
"formFuncName" should { | ||
"generate random names when not in Test mode" in { | ||
for (mode <- RunModes.values if mode != RunModes.Test) { | ||
val a,b = defaultFuncNameGenerator(mode)() | ||
a must startWith("F") | ||
a.length must_== Helpers.nextFuncName.length | ||
a must_!= b | ||
} | ||
} | ||
|
||
"generate predictable names in Test mode" in { | ||
val a,b = S.formFuncName | ||
a must startWith("f") | ||
a.length must_!= Helpers.nextFuncName.length | ||
a must_== b | ||
a must_!= S.formFuncName | ||
} | ||
|
||
"generate resort back to random names when test func-names disabled" in { | ||
S.disableTestFuncNames { | ||
val a,b = S.formFuncName | ||
a must startWith("F") | ||
a.length must_== Helpers.nextFuncName.length | ||
a must_!= b | ||
} | ||
} | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not be explicit here and call it
generatePredictableFuncNameFromStack
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was
generatePredictableFuncName
describes the purpose and not the how.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😎