Questions tagged [functions]

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

319 questions
129
votes
12 answers

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 future). It could perform a query, check some…
deprecated
  • 3,297
43
votes
8 answers

Beginning a sentence with a function name?

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 sentence needs to be capitalized; the function…
36
votes
1 answer

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 is there a name for a function which is meant only…
21
votes
7 answers

Is there an optimal number of lines of code per function?

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 this gain is not directly inversely proportional…
gablin
  • 17,407
10
votes
2 answers

Solving the problems that come with the dyadic function assertEquals(expected, actual)

After years of cowboy coding, I decided to pick up a book on how to write good quality code. I'm reading Clean Code by Robert Cecil Martin. In chapter 3 (functions) there is a section on dyadic functions. Here is an excerpt from the book. Even…
HBeel
  • 219
3
votes
3 answers

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 decide that it should be avoided?
zduny
  • 2,653
1
vote
1 answer

Are there defined standards for argument sequence?

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 how-to (e.g. for certain languages or libraries) to…
wellnoidea
  • 31
  • 5
0
votes
1 answer

When is using a lot of parameters considered using too many parameters?

I do a lot of programming in my class. It's just my first semester, and most of my stuff is review. I've taken to using a verifyInput function to ensure that user inputs match certain criteria. Since I end up using verifyInput so much, I keep coming…
Ucenna
  • 1,302
0
votes
4 answers

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 } // more stuff } Say you might have several…
-1
votes
2 answers

How to minimize the code duplication?

I have the following code which I wrote, but there is so much of code duplication. I would like to minimize it but I am unable to come up with the ideas. Could anyone help me out with this? myFunc(r: Object): Object { if (condition) { …
ShellZero
  • 125