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

learn more… | top users | synonyms

3
votes
5answers
866 views

Functions with side-effects in Delphi/Pascal

What is the proper approach to functions that have side-effects in Delphi/Pascal? For example, I could have a boolean function DeleteFile that returns True if the file was deleted and False ...
85
votes
10answers
6k 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 ...
7
votes
4answers
1k 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 ...
3
votes
2answers
1k views

Setting $_POST variables as a means of passing data / Not passing parameters in functions

I've got a legacy PHP web application wherein almost each and every function makes references to $_POST variables - retrieving their values, AND setting them (or setting new POST variables) as a means ...
10
votes
8answers
6k views

Feature vs. Function

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 ...
3
votes
8answers
469 views

Wrapping simple statement in a function in java?

I was working on neo4j graph database in java. To get the reference node of this db: GraphDatabaseService graphDb=new EmbeddedGraphDatabase(DB_PATH); Node Root=graphDb.getReferenceNode() I ...
10
votes
2answers
715 views

Design: Object method vs separate class's method which takes Object as parameter?

For example, is it better to do: Pdf pdf = new Pdf(); pdf.Print(); or: Pdf pdf = new Pdf(); PdfPrinter printer = new PdfPrinter(); printer.Print(pdf); Another example: Country m = new ...
3
votes
4answers
998 views

Is function memoization really only for primitives?

I was thinking about this for quite some time. Is function memoization really only for primitives? I currently have this piece of code: Public Shared Function Mize(Of TArg1 As Structure, ...
6
votes
3answers
2k views

Good use of wrapper functions?

What do you consider good use of wrapper functions? When are they useful abstractions and in what cases harmful and unnecessary complexity?
12
votes
5answers
2k views

Why are PHP function signatures so inconsistent? [closed]

I was going through some PHP functions and I could not help notice the following: <?php function foo(&$var) { } foo($a); // $a is "created" and assigned to null $b = array(); foo($b['b']); ...
5
votes
3answers
1k views

Static methods or static functions?

I was just reading http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function and all of a sudden, the thing came to my mind was the static methods. As static ...
12
votes
7answers
3k views

Is there an optimal number of lines of code per function? [closed]

Functions are not only used to minimize duplication of code - they are also used to split up a long function into smaller ones to increase readability, as well as making the code self-commenting. Yet ...
6
votes
18answers
3k views

What do you name functions/variables/etc when you can't think of a good name?

When you are defining a function/variable/etc and are not sure what to name it, what do you name it? How do you come up with a name? If you use a temporary name as a place-card until you give it it's ...