named-parameters

Named parameter doesn't work with MySql LIKE statement

拈花ヽ惹草 提交于 2019-12-23 12:37:13
问题 I'm trying to organize a search function on the site, using the Spring-jdbc NamedParameterJdbcTemplate. public List<PhoneEntry> searchPhoneEntries(String search, String username) { String SQL = "select * from entries, users where users.enabled=true " + "and entries.username=:username " + "and concat(secondName, firstName, patronymic, mobile, tel, " + "address, entries.email) like ('%:search%')"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("username", username);

How do I use [] as a default value for a named function argument in python? [duplicate]

淺唱寂寞╮ 提交于 2019-12-22 10:50:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I have this code class Test(object): def __init__(self, var1=[]): self._var1 = var1 t1 = Test() t2 = Test() t1._var1.append([1]) print t2._var1 and I get "[[1]]" as the result. So clearly t1._var1 and t2._var1 are addressing the same list. If I put t3 = Test() print t3._var1 then I get "[[1]]" as well. So var1=[] seems to permanently bind var1 to the

C++ named arguments implementation with derived classes

孤者浪人 提交于 2019-12-22 08:32:16
问题 I'm trying to create a named-arguments-like constructor for some of the classes of a project. The way I'm doing it is by defining a class proxy which will hold the arguments and pass an instance of this proxy to the constructor of my classes. Everything worked fine until I had to derive one of my classes. Basically I thought: I'm gonna derive the new derived class proxy from the base class proxy. This works too, but only if I use only the derived proxy class arguments. Here is an example

Use Curiously Recurring Template Pattern (CRTP) with additional type parameters

只谈情不闲聊 提交于 2019-12-20 12:41:11
问题 I try to use the Curiously Recurring Template Pattern (CRTP) and provide additional type parameters: template <typename Subclass, typename Int, typename Float> class Base { Int *i; Float *f; }; ... class A : public Base<A, double, int> { }; This is probably a bug, the more appropriate superclass would be Base<A, double, int> -- although this argument order mismatch is not so obvious to spot. This bug would be easier to see if I could use name the meaning of the parameters in a typedef:

When to use keyword arguments aka named parameters in Ruby

痞子三分冷 提交于 2019-12-19 05:08:51
问题 Ruby 2.0.0 supports keyword arguments (KA) and I wonder what the benefits/use-cases are of this feature in context of pure Ruby, especially when seen in light of the performance penalty due to the keyword matching that needs to be done every time a method with keyword arguments is called. require 'benchmark' def foo(a:1,b:2,c:3) [a,b,c] end def bar(a,b,c) [a,b,c] end number = 1000000 Benchmark.bm(4) do |bm| bm.report("foo") { number.times { foo(a:7,b:8,c:9) } } bm.report("bar") { number.times

Named Parameters solution in PHP 7+

蹲街弑〆低调 提交于 2019-12-18 08:57:44
问题 How can I implement the named argument feature in PHP 7+? The ideal syntax is: find($wildcard, relative = true, listIfEmpty = false) { ... } But there is no solution to do like that. In the answer, I implemented the shortest possible solution that supports: Refactoring Type Hints for the params and function result Reusable param set Typesafe params Default values for params Getter for each param ( no hard-coded string ) Very simple setter/getter that you need to change just one name for every

Emulating named function parameters in PHP, good or bad idea?

社会主义新天地 提交于 2019-12-17 23:27:34
问题 Named function parameters can be emulated in PHP if I write functions like this function pythonic(array $kwargs) { extract($kwargs); // .. rest of the function body } // if params are optional or default values are required function pythonic(array $kwargs = array('name'=>'Jon skeet')) { extract($kwargs); // .. rest of the function body } Apart from losing intellisense in IDEs what are the other possible downsides of this approach? Edit: Security: Shouldn't security be a non-issue in this case

MS Access, Named parameters and Column Names

耗尽温柔 提交于 2019-12-17 22:28:12
问题 I have the following query which I am executing on an Access database. The query, when run in Access returns accurate results. However when run from the code I get back all of the items in the database, even those which fall outside the date range I am searching for. I was wondering if the issue was because the parameter names are the same as the column names in the table, so I changed the parameter names @StartDate and @EndDate to be @FromDate and @ToDate and this fixed the problem, if the

Are Options and named default arguments like oil and water in a Scala API?

六月ゝ 毕业季﹏ 提交于 2019-12-17 21:49:07
问题 I'm working on a Scala API (for Twilio, by the way) where operations have a pretty large amount of parameters and many of these have sensible default values. To reduce typing and increase usability, I've decided to use case classes with named and default arguments. For instance for the TwiML Gather verb: case class Gather(finishOnKey: Char = '#', numDigits: Int = Integer.MAX_VALUE, // Infinite callbackUrl: Option[String] = None, timeout: Int = 5 ) extends Verb The parameter of interest here

Python Named Argument is Keyword?

◇◆丶佛笑我妖孽 提交于 2019-12-17 16:59:24
问题 So an optional parameter expected in the web POST request of an API I'm using is actually a reserved word in python too. So how do I name the param in my method call: example.webrequest(x=1,y=1,z=1,from=1) this fails with a syntax error due to 'from' being a keyword. How can I pass this in in such a way that no syntax error is encountered? 回答1: Pass it as a dict. func(**{'as': 'foo', 'from': 'bar'}) 回答2: args = {'x':1, 'y':1, 'z':1, 'from':1} example.webrequest(**args) // dont use that