Function is a block of code which performs a specific task.

learn more… | top users | synonyms

0
votes
1answer
167 views

Setting up folders and importing modules in Python

I'm building an app to automate some processes that are annoying to do by hand (looking in a file, taking certain information out of a file, building another file with that information). My project ...
1
vote
1answer
153 views

Haskell types for functions

I don't understand the answer to this question: Q: Can Haskell find a type for the function selfapply defined by: selfapply f = f f A: The function selfapply is not typeable in the simple ...
-1
votes
2answers
123 views

What is an anonymous function? [closed]

I am new in programming and it's kind of difficult for me to understand what the context of an anonymous function is. this is my code: toevoegButton.addEventListener('click', function() { ...
4
votes
3answers
287 views

Functions whose parameters are implicitly supplied

Callback functions are able to accept some parameters, but they are not explicitly declared when calling the function. How does this actually work? What is going on that allows us to pass a function ...
-3
votes
0answers
35 views

How to define member function in separate source file? [migrated]

Consider following two programs. p1.cpp #include <iostream> struct test { void fun(); }; int main() { test t; t.fun(); } p2.cpp #include <iostream> void test::fun() { ...
5
votes
2answers
107 views

What is the difference between currying and partial function application in practice

I understand the difference between partial function application and a curried function (f(X x Y x Z) -> N vs f(X -> (Y -> (Z -> N)))), but I do not see what the consequence of this ...
3
votes
1answer
366 views

What does comma signify in a function definition?

From PHP manual: array array_change_key_case ( array $array [, int $case = CASE_LOWER ] ) What does comma signify in a function definition?
1
vote
1answer
67 views

Function name in parentheses after fuction call in Python

I ran into these lines of code in the QPYTHON Android app. They are part of a sample that uses the Bottle module to create a simple Web server that seems to work fine. app = Bottle() app.route('/', ...
5
votes
3answers
670 views

What can procs and lambdas do that functions can't in ruby

I've been working in Ruby for the last couple weeks, and I've come to the subject of procs, lambdas and blocks. After reading a fair share of examples from a variety of sources, I don't how they're ...
2
votes
2answers
110 views

What's wrong about extending a class with prototype methods?

I was at a bar last night with a few of my colleagues. They said that it's a bad idea to extend the functionality of basic JavaScript Objects with a prototype method. For example, let's say you ...
15
votes
4answers
11k views

In C++ why and how are virtual functions slower?

Can anyone explain in detail, how exactly the virtual table works and what pointers are associated when virtual functions are called. If they are actually slower, can you show the time that the ...
-1
votes
2answers
48 views

problems compiling a function with a trait Add in Rust [closed]

I'm trying to write a generic function summ in rust - but to no avail. Could someone please elucidate the problem? fn summ<T:Add>(a:T,b:T)->T { a+b }
7
votes
5answers
395 views

Should private functions be held to the same standards as public functions?

If I'm building private utility functions, should they be held to the same rigorous standards in terms of handling invalid data as public functions? Example:If I'm writing code to calculate the ...
0
votes
1answer
94 views

Const and non-const methods, and possible mutable data member?

I'm working on a design and implementation change due to a bug. The bug fix requires us to modify a class object in a const method. I think the two options are: Have the non-const method cast this ...
0
votes
4answers
124 views

How can Guard Statements and Small Functions coexist?

By Guard Statements I mean something similar to the first part of the function: def doSomething(String something) { // Guard Statement if(!something) { return false } // ...
4
votes
5answers
3k views

Template Functions and Function templates in C++

I came across a question which asked the difference between Function Templates and Template Functions in C++ and also Template Classes and Class Templates. I was under the impression that Function ...
4
votes
8answers
565 views

Confusion regarding def function within Python

I've been learning Python for about 2 months now (Started with Learn Python The Hard Way, now reading Dive Into Python), and within both books, I still seem to be confused over this one bit of code. ...
1
vote
2answers
106 views

Are there constraints for functions in structured programming?

I just talking with a colleague (University instructor) who teaches C (Fundamental of programming Course). He said I won't give score to a student, if he uses I/O (scanf or printf or cin count) in a ...
9
votes
9answers
7k views

Why Java does not allow function definitions to be present outside of the class?

Unlike C++, in Java, we cannot have just function declarations in the class and definitions outside of the class. Why is it so? Is it to emphasize that a single file in Java should contain only one ...
29
votes
4answers
28k views

Why store a function inside a python dictionary?

I'm a python beginner, and I just learned a technique involving dictionaries and functions. The syntax is easy and it seems like a trivial thing, but my python senses are tingling. Something tells me ...
14
votes
8answers
9k views

Feature vs. Function [closed]

Often I hear PMs (Project Managers) talk about feature and function. And I'm just so puzzled to differentiate them. Sometimes I think of a feature to be equivalent to a user story. Something like "As ...
0
votes
2answers
149 views

Is there a approximate string comparison function which is odd like mathematical functions are odd?

I say odd like a mathematical function, a mathematical function is odd if f(-x) = -f(x) I understand that comparing two strings may seem to have little to do with this, because the arguments cannot ...
1
vote
1answer
89 views

When should one create a new py-function rather than tweaking another one?

Me and a co-developer are arguing when it's wise to cast a new function rather than tweaking another one. By tweaking I mean an option or a hidden check in an existing function. The question could be ...
1
vote
2answers
221 views

Are any side effects not concrete side effects?

In Chapter 23 of "Object Oriented Software Construction" (1988), Betrand Meyer makes a distinction between side effects, concrete side effects, and abstract side effects. Meyer defines a side effect ...
26
votes
5answers
2k views

Method extraction vs underlying assumptions

When I split big methods (or procedures, or functions — this question is not specific to OOP, but since I work in OOP languages 99% of the time, it's the terminology that I'm most comfortable with) ...
1
vote
3answers
366 views

How are basic functions implemented in a programming language if they are not built in? [closed]

The lowest levels of a programming language's library functions are always obscure and often have no code that looks like it even remotely does anything. Some languages have these functions like ...
-4
votes
1answer
115 views

Is there is a way to pass more than one value to the calling function in c++? [closed]

I'm new at computer science and programming, Can any one give me a hand to know "Is there is a way to pass more than one value to the calling function in c++". Explain how?
0
votes
1answer
142 views

Can i create a function with variable parameters in C?

I've always wondered where a single function such as printf(); can take in variable parameters and provide the right results. For example, printf("Number is %d",a); which has two parameters, and ...
1
vote
2answers
52 views

Function that would output all distinct values in an array

I want to create a function that outputs the distinct values in a given array. For example, in the following sequence 2 2 1 1 5 2 , the distinct digits are 2 1 5. What I've done till now is: void ...
30
votes
1answer
2k views

Name for a Function which Returns its Arguments?

A function that does nothing, takes no arguments and returns nothing is traditionally called a noop, or no-op. An example of a noop is below: function noop(){} http://en.wikipedia.org/wiki/NOP So ...
2
votes
5answers
815 views

When, if ever, should I daisy chain functions?

I'll try to be as brief as possible in respect to your time. In a program divided up into many functions by which it is intended that they execute themselves one after another, when (if ever) is it ...
8
votes
5answers
2k views

When would dynamic scoping be useful?

With dynamic scoping, a callee can access the variables of its caller. Pseudo C code: void foo() { print(x); } void bar() { int x = 42; foo(); } Since I have never programmed in a ...
0
votes
3answers
140 views

What is the difference between a helper and a convenience function?

The title and the question are the same! The two seem the same to me: a convenience is a helper. A helper is a convenience. So when is it good to use the one or the other term?
-1
votes
1answer
816 views

Python: Faster to use global variable or pass as arguments to a function? [duplicate]

Hey so i was wondering which is the more efficient way, or better practice to do in this situation. 1, def function(): global number number += 2 Or 2, def function(number): return ...
36
votes
10answers
4k views

Why is Today() an example of an impure function?

It seems like, when reading something like this Wikipedia article about "pure functions", they list Today() as an example of an impure function but it seems pretty pure to me. Is it because there is ...
0
votes
2answers
52 views

Iterating a function with a static argument: Global functions + lambdas vs internal function?

I am never sure which of these is better form: Option A def a(x,y): def b(z): return z+y return map(b, x) print a([10,20], 5) Option B def b(z,y): return z+y def a(x,y): return ...
8
votes
4answers
518 views

why empty function are needed

I started learning python and I am wondering why empty function are needed in a programming language e.g. in python: def empty_func(): pass even in shell scripts empty function empty functions ...
3
votes
2answers
115 views

Strategies for parameter wrapping

Methods with many parameters are often sometimes unavoidable. In my own experience I often find this is the case for program entry points and complex mathematical procedures - where refactoring is ...
22
votes
4answers
14k views

Where should I put functions that are not related to a class?

I am working on a C++ project where I have a bunch of math functions that I initially wrote to use as part of a class. As I've been writing more code, though, I've realized I need these math functions ...
3
votes
4answers
745 views

int * vs int [N] vs int (*)[N] in functions parameters. Which one do you think is better?

When programming in C (or C++) there are three different ways to specify the parameter in a function that takes an array. Here is an example (implementing std::accumulate from C++ in C) that shows ...
89
votes
11answers
7k views

One-line functions that are called only once

Consider a parameterless (edit: not necessarily) function that performs a single line of code, and is called only once in the program (though it is not impossible that it'll be needed again in the ...
15
votes
1answer
3k views

Is there a difference between arguments and parameters?

It might be like this: Parameter means from the callers POV and arguments mean inside the procedure, or other way round. Or is there no difference? Update In Swedish we say "anropsparametrar" i.e. ...
13
votes
5answers
3k views

Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?

Consider the following "C" code: #include<stdio.h> main() { printf("func:%d",Func_i()); } Func_i() { int i=3; return i; } Func_i() is defined at the end of the source code and ...
1
vote
1answer
67 views

Are there defined standards for argument sequence? [closed]

Say I have a function taking three arguments: a symbol (an alias for a class, method or function name) a mirror/reflection of a specific object a mirror/reflection of a class in general is there a ...
3
votes
3answers
295 views

When is inlining worth it?

Modern compilers often inline functions when they decide it is worth it. But here comes my question: how does one define if it is optimal to inline function at given time, or more important how to ...
1
vote
0answers
17 views

Hidden event handlers and their parameters

I'm having a bit of trouble understanding why has an event handler to be defined as a function. AFAIK, a function can be used as anonymous called procedure as event handler It defines a ...
0
votes
2answers
149 views

memory needed to store a function in javascript

I have been using sizeof.js to investigate the size of various objects in javascript. It appears from this that the size of a function is essentially zero bytes, regardless of how many instructions ...
1
vote
2answers
214 views

How does the CPU access the values of stack-allocated variables? [duplicate]

Consider the following C++ function: void doStuff() { Thing thingA; Thing thingB; thingA.doSomething(); // .. etc } During the execution of this function, variables thingA and ...
20
votes
8answers
4k views

What is the benefit of a function without parameters which only calls another function

A tutorial (for Javascript) I'm doing suggests we write a function like this one: function sayHello() { //Some comments explaining the next line window.alert("Hello"); } Other than ...
35
votes
12answers
5k views

Why do most programming languages have special keyword or syntax for declaring functions? [closed]

Most programming languages (both dynamically and statically typed languages) have special keyword and/or syntax that looks much different than declaring variables for declaring functions. I see ...