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

learn more… | top users | synonyms

-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
286 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
66 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('/', ...
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 ...
-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 }
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 } // ...
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 ...
1
vote
1answer
152 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 ...
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 ...
0
votes
1answer
158 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
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 ...
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
3answers
138 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?
2
votes
5answers
809 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 ...
-1
votes
1answer
806 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 ...
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 ...
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 ...
8
votes
4answers
513 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
4answers
734 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 ...
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 ...
0
votes
2answers
134 views

Is there a way for Object 1 to call Object 2's enums in a function call?

For example, if I have two classes "Director" and "Follower". I want the Director to tell the follower where to go (ex: follower1.go(direction.LEFT)), and I want the Director to know what directions ...
0
votes
1answer
92 views

Why does this function work even though the vars are different

$inumber1 = 10; $inumber2 = 20; function add($number1, $number2) { echo $number1 + $number2; } add($inumber1, $inumber2); I'm learning PHP coding for the first time and I'm ...
2
votes
1answer
431 views

How do multiple levels of inheritance affect virtual function call overhead in C++?

I am considering using a class hierarchy with more than a single level of inheritance, where virtual member functions form a "chain", for example: struct Base { virtual void foo(); }; struct D1 : ...
0
votes
1answer
111 views

How to split a Service class in two but still use them like one?

I've got a class: AuthenticationService findLoggedInUser() Checks session if User is logged in. If not, check client persistent user login cookie and log in. loginUser($email, $pw, $remember = ...
14
votes
7answers
2k views

Function only returns unchanged parameter, useless?

I just found this function in the project I'm working at: -- Just returns the text unchanged. -- Note: <text> may be nil, function must return nil in that case! function Widget:wtr(text) ...
41
votes
9answers
5k views

Beginning a sentence with a function name? [closed]

Occasionally while typing something up that relates to a case-sensitive programming language I end up starting a sentence with a function name. Now the rules of English state that the first word in a ...
0
votes
1answer
317 views

Does this function do one thing only?

Is the following method considered to be doing one thing only? I'm wondering about that since it takes an optional argument. public function findErrors($name = null) { if ($name) { ...
9
votes
4answers
642 views

Are first-class functions a substitute for the Strategy pattern?

The Strategy design pattern is often regarded as a substitute for first-class functions in languages that lack them. So for example say you wanted to pass functionality into an object. In Java you'd ...
28
votes
8answers
6k views

Is splitting up a function into several inner functions an anti-pattern? [duplicate]

Imagine a long and complicated process, which is started by calling function foo(). There are several consecutive steps in this process, each of them depending on result of the previous step. The ...
0
votes
2answers
125 views

Should you avoid adding unecessary stack frames?

I have been working with laravel (PHP) recently, and there is an option when using their fluent ORM to define where clauses using closures. This gives us two, functionally equivalent, ways to specify ...
2
votes
2answers
187 views

Property or Method to obtain information about a collection?

Suppose I have a MyList class which extends ObservableCollection<MyObject> where MyObject has the Boolean Property Enabled. Let's say I want the number of MyObject objects that have the ...
0
votes
3answers
183 views

Use of malloc in C

Is it necessary to call free function every time we use malloc in C. I am asking this because I have seen many times that it is not called . Thank you