named-parameters

Why do we need to specify parameter name in interface?

拟墨画扇 提交于 2019-12-03 08:27:25
问题 When we create interface methods, can't we do something like in java : void interface_method(Integer,String, /* other parameter */); Instead I noticed that we also need to give the parameter names lile: void interface_method(Integer i, String s); Also the interface implementor don't need to have the same parameter name as in interface method. I found a similar question about c# over here . They mention one scenario of named parameter but I don't find any other relevent reason specifically in

Differences between using ? and :param in prepare statement

倾然丶 夕夏残阳落幕 提交于 2019-12-03 03:49:31
Let's say I want to select records where Id = 30 . Prepared statements allow two ways of binding parameters: question marks $id = 30; $q = $conn->prepare("SELECT * FROM pdo_db WHERE id > ?"); $q->execute(array($id)); // Here above ID will be passed named parameters $sth = $conn->prepare("SELECT `id`, `title` FROM `pdo_db` WHERE `id` > :id"); $sth->execute(array( ':id' => 30 )); Both are working fine and give accurate results but I am not able to get the exact differences between these two nor when I should use one or another? Question mark parameters are called positional parameters.

Optional named arguments in Mathematica

允我心安 提交于 2019-12-03 00:48:42
What's the best/canonical way to define a function with optional named arguments? To make it concrete, let's create a function foo with named arguments a , b , and c , which default to 1, 2, and 3, respectively. For comparison, here's a version of foo with positional arguments: foo[a_:1, b_:2, c_:3] := bar[a,b,c] Here is sample input and output for the named-arguments version of foo : foo[] --> bar[1,2,3] foo[b->7] --> bar[1,7,3] foo[a->6, b->7, c->8] --> bar[6,7,8] It should of course also be easy to have positional arguments before the named arguments. dreeves I found the standard way to do

Why do we need to specify parameter name in interface?

限于喜欢 提交于 2019-12-02 22:11:17
When we create interface methods, can't we do something like in java : void interface_method(Integer,String, /* other parameter */); Instead I noticed that we also need to give the parameter names lile: void interface_method(Integer i, String s); Also the interface implementor don't need to have the same parameter name as in interface method. I found a similar question about c# over here . They mention one scenario of named parameter but I don't find any other relevent reason specifically in java. From a technical standpoint it wouldn't be necessary. I've always taken it as a syntax

Passing lambda functions as named parameters in C#

回眸只為那壹抹淺笑 提交于 2019-12-02 17:27:39
Compile this simple program: class Program { static void Foo( Action bar ) { bar(); } static void Main( string[] args ) { Foo( () => Console.WriteLine( "42" ) ); } } Nothing strange there. If we make an error in the lambda function body: Foo( () => Console.LineWrite( "42" ) ); the compiler returns an error message: error CS0117: 'System.Console' does not contain a definition for 'LineWrite' So far so good. Now, let's use a named parameter in the call to Foo : Foo( bar: () => Console.LineWrite( "42" ) ); This time, the compiler messages are somewhat confusing: error CS1502: The best overloaded

ADO parameterised query not returning any result

瘦欲@ 提交于 2019-12-02 05:55:22
问题 I am using this query to get some results from my vbscript in a classic asp page and It does not come back with any values. The page is blank and there are no errors too. Any suggestion please? dim cmd, admin_no admin_no = request.QueryString("admin") set cmd = server.CreateObject("ADODB.Command") cmd.ActiveConnection = con sql = "" sql = sql & "DECLARE @admin_no int;" sql = sql & "SELECT field1, field2 FROM mydb.mytable where admin_no = @admin_no" cmd.CommandText = sql cmd.CommandType =

leaving out some implicit parameters

吃可爱长大的小学妹 提交于 2019-12-01 23:18:55
问题 Is it possible to leave out some implicit parameters but not all of them? I tried with named parameters: def foo(implicit a: Int, b: String) { if (a > 0) { println(b) foo(a = a-1) // error } } Unfortunately, the compiler rejects the recursive call of foo with: not enough arguments for method foo Unspecified value parameter b 回答1: It is not possible to leave out some implicit parameters. So, in your example def foo(implicit a: Int, b: String): Unit = ??? It is not possible to only specify a .

Call a parameterized Oracle query from ADODB in Classic ASP

。_饼干妹妹 提交于 2019-12-01 05:25:52
I’m currently working on a classic ASP project talking to an Oracle database. I’m trying to find a way to safely call an Oracle PL/SQL script and passing parameters with ADO. The currently solution builds the SQL script by hand with embedded variables like this: strSQL = "SELECT field1, etc FROM my_table WHERE (field = '" & filter_value & "')" This, of course, is ugly and insecure, and open to abuse. The code that I have so far (purloined from various non classic asp based web sites) looks like this: dim strSQL, oConn, oCommand, oParam set oConn = server.createobject("ADODB.Connection") oConn

Call a parameterized Oracle query from ADODB in Classic ASP

霸气de小男生 提交于 2019-12-01 03:26:33
问题 I’m currently working on a classic ASP project talking to an Oracle database. I’m trying to find a way to safely call an Oracle PL/SQL script and passing parameters with ADO. The currently solution builds the SQL script by hand with embedded variables like this: strSQL = "SELECT field1, etc FROM my_table WHERE (field = '" & filter_value & "')" This, of course, is ugly and insecure, and open to abuse. The code that I have so far (purloined from various non classic asp based web sites) looks

When to use keyword arguments aka named parameters in Ruby

那年仲夏 提交于 2019-12-01 02:28:27
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 { bar(7,8,9) } } end # user system total real # foo 2.797000 0.032000 2.829000 ( 2.906362) # bar 0