Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >

Questions tagged [functions]

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

Filter by
Sorted by
Tagged with
7 votes
8 answers
940 views

According to Is it wrong to use a boolean parameter to determine behavior?, I know using boolean parameters to decide the behaviour is bad, for example, when using boolean parameters as the following: ...
wcminipgasker2023's user avatar
2 votes
3 answers
2k views

Straight to the point, here's the original code: integer = input(...) size = len(integer) # Created three dicts for matching numbers as keys to corresponding words dic_ones = {...} dic_tens = {...} ...
Programmerthinker007's user avatar
9 votes
7 answers
3k views

For example, if the sleep time of a function would change after first execution but the output remains unchanged, e.g.: public static int myFunction(){ try { Thread.sleep(MyClass....
wcminipgasker2023's user avatar
7 votes
6 answers
1k views

I have a class that has a callback function that gets triggered on some event. The user of the class instance is expected to do stuff on the instance itself, inside this callback function. So I am ...
doca's user avatar
  • 255
17 votes
8 answers
5k views

When is it better to pass data to a function in a parameter, and when is it better for the function to just fetch the data itself? Here's some simplified examples in PowerShell: Option 1 (give the ...
Nova's user avatar
  • 181
0 votes
2 answers
349 views

I'm new to coding and am currently trying to learn C++ myself. I just learned about function parameters and pass by value vs pass by reference. Everywhere I read, they say that one of the reasons pass ...
Karanveer A's user avatar
6 votes
4 answers
3k views

Uncle Bob mentions in his book "Clean Code" that "[f]unctions should do one thing [...] only" and advocates that a method should stick to one abstraction level (I'd call it flight ...
Christian's user avatar
  • 171
-4 votes
1 answer
118 views

Courtesy link: What Are The Specific Meanings Of The Terms: Functions, Methods, Procedures, and Subroutines? What's the difference between a function and a method? In the linked question: function,...
Arunabh's user avatar
0 votes
1 answer
594 views

I've just accidentally came across this answer about inlined functions and I'd like to know how this affects call stack. But I can't add comments because I don't have enough rep so I decided to ask ...
b3rry's user avatar
  • 3
-1 votes
7 answers
730 views

Consider a class that follows the obfuscated function call anti-pattern. I've also seen these called "stupid classes". The definition of such a class is that it only has one public method ...
J. Mini's user avatar
  • 1,015
0 votes
0 answers
325 views

I have a question related to the best approach when resources are limited, such as on the Azure Function consumption plan. I have an IoT device, and the number of IoT devices is likely to increase to ...
user8400863's user avatar
-1 votes
1 answer
137 views

When writing code in a programming language that has the option of creating standalone functions vs. methods of a class or struct, what is the most relevant objectively-quantifiable reason to choose ...
MikeSchinkel's user avatar
0 votes
0 answers
149 views

From what I understand from this answer, it is not possible to use a typeddict and typechecking in a function. So for example, if one has a function: def some_func(some_int: int, some_dict:...
a.t.'s user avatar
  • 225
8 votes
5 answers
10k views

I wrote some script in Python that creates a giant 2D matrix (1000x1000 or bigger) and fills it with random numbers. And after that, it goes through every element of the matrix and changes the number ...
devdevdove's user avatar
2 votes
2 answers
262 views

I have an intuition, that I'd like to read what others have talked about. To me, it seems fairly intuitive that when you have a function which is called multiple times with the same arguments, it ...
Thiago Pereira Maia's user avatar
0 votes
2 answers
1k views

On Stack Overflow I frequently see questions with code in the following style: function funcName(parameter) { let variable = parameter; // rest of function uses variable rather than parameter } ...
Barmar's user avatar
  • 346
38 votes
10 answers
10k views

As has been covered to the point of parody, heavily object-oriented languages, such as C# or Java, tend to lack the feature of having functions as a primitive type. You can argue about whether or not ...
J. Mini's user avatar
  • 1,015
0 votes
2 answers
239 views

I read a lot of examples where I read code like this: def get_user_by_id(session, id) ... and the function that calls that function needs to create or get the DB session a pass to the function. the ...
Tlaloc-ES's user avatar
  • 387
10 votes
7 answers
2k views

I have a question regarding my general understanding of global state in software engineering. When I write an app I like to decompose it into little, manageable components and functions, that are ...
Angelica's user avatar
  • 109
3 votes
3 answers
351 views

I've just started dipping my feet into OOP. Is it considered bad practice to have classes that reference attributes that depend on another function being called and thus may not exist (version 1)? I'...
Tim Kirkwood's user avatar
21 votes
4 answers
6k views

When we have a math problem such as 3 + 5 + 2, we say that it is associative. We can choose which step to pick first: 3 + (5 + 2); we know that brackets affect the order in which the operations are ...
pro100tom's user avatar
  • 449
1 vote
1 answer
2k views

As suggested by Uncle Bob in his book "Clean Code", I am actively trying to keep my functions small and readable. However, I often encounter arguments drilling when I try to refractor a big ...
CheeseS's user avatar
  • 19
-2 votes
2 answers
150 views

Is there a name for a function that outputs more data than was put into it? For example: let's say I input a one byte value into the function and it returns a three byte value, is there a name for ...
SuperSim135's user avatar
2 votes
2 answers
628 views

For anything larger than a 64 bit integer, why would I want to pass by value? [Update] The question was closed, because it was not specific enough. One comment suggested that I specify a language. I ...
Mawg's user avatar
  • 4,308
-1 votes
2 answers
88 views

So far my weakest side has been proper code structuring and organization. I wanted to know how I can properly apply separation of concerns to the following code to make it more organized. I have a ...
Good guy's user avatar
0 votes
2 answers
155 views

Just say I have list APIs, and provide find() to search node. With this design if something went wrong during pre-conditions, client would have no idea about it because no status code provided. bool ...
Andy Lin's user avatar
  • 185
1 vote
2 answers
5k views

I have a single *.h file. This file contains a single (more to come) function declaration. Now the implementation of that file is very complex. the corresponding *.cpp contains several function ...
user avatar
4 votes
2 answers
2k views

I'm working to create a library in python that myself and a few colleagues will use. I'm struggling to conceptually understand how to best organize some code that feels like it doesn't cleanly fit ...
user avatar
2 votes
2 answers
1k views

Let's say I have a function in a class with the following signature: int fun(int x, int y,std::function<int(int, int)> funArg) The output depends on the operations done in funArg. My question ...
Wballer3's user avatar
13 votes
6 answers
12k views

In python I often see functions with a lot of arguments. For example: def translate(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p): // some code return(x, y, z) I like this pattern in some ...
P. Hopkinson's user avatar
-1 votes
1 answer
100 views

Backstory: I have subclasses that are supposed to override and define various functions, but not neccessarily all of them. They can't remain purely virtual though for obvious reasons, and so I am ...
Anon's user avatar
  • 3,649
1 vote
1 answer
667 views

I wonder if there is a naming convention or a best practice to name Java Classes when building AWS Lambda functions with Java for REST API? For example, if I have a Java project that contains Lambda ...
InterestedDev's user avatar
0 votes
2 answers
121 views

Here are a couple of examples in Python: clearly_even = 2 * get_integer() print(solve_for_any_integer(clearly_even)) def solve_for_any_integer(x): while x % 2 == 1: x = make_even_from_odd(x) ...
George Sovetov's user avatar
11 votes
5 answers
2k views

This doubt is about function doing one thing from Chapter 3: Functions of the book named Clean Code Here Uncle Bob is talking about this function: public static String renderPageWithSetupsAndTeardowns(...
The Chinky Sight's user avatar
2 votes
1 answer
310 views

I am trying to implement a basic bytecode VM, which I plan to target with a compiler. How can I implement the ability to call external C functions using the bytecode, i.e., call arbitrary functions in ...
Greatcode's user avatar
-1 votes
1 answer
94 views

While writing python code (I write python-selenium for GUI automation), I am facing situations wheer I have to deal with 5 widgets that do the same thing, just there xpath is differs by one term. # ...
Ulysses's user avatar
  • 101
10 votes
3 answers
7k views

I'm a beginner in C++, and I was wondering if it is best practice to define a member function directly in a class, such as: // something.hpp class C { inline int func() { return ... ; } } rather ...
Angel E.'s user avatar
  • 129
-2 votes
1 answer
189 views

So, let's say you've got a function foobar() which can function with a variable number of parameters inputted into it, and has different behavior for each of them. How do you get this to function ...
nick012000's user avatar
0 votes
2 answers
8k views

Is it usually recommended to define default values for Boolean arguments? I mean, is it usually recommended to define a function like this someFunction(a, b, x) { // a and b are strings, x is true ...
user90726's user avatar
  • 205
0 votes
2 answers
1k views

If I have a list of objects that need to have an operation performed on each, is there a best practice in abstracting the loop or not? Looping over list and call def func(item): some_op(item) ...
pstatix's user avatar
  • 1,047
8 votes
4 answers
3k views

I found in the catalog of Refactoring by Martin Fowler, with Kent Beck book that they mention Extract Function refactoring. It is a good practice to wrap your related code into local functions to ...
Raikish's user avatar
  • 189
-1 votes
3 answers
2k views

I was reading some C++ object-oriented programming notes that mentioned that we should avoid wrapping functions in classes if it is not required, since wrapping 'things' in classes would reduce ...
The Pointer's user avatar
0 votes
1 answer
566 views

I have a 'processing' function and a 'serializing' function. Currently the processor returns 4 different types of data structures to be serialized in different ways. Looking for the best practise on ...
Jamal Rahman's user avatar
0 votes
3 answers
390 views

In the book Clean Code, Robert C. Martin says that we should avoid polyadic functions (functions that contain four or more arguments). One of the solutions presented by him is the use of objects as ...
sartoz's user avatar
  • 103
4 votes
3 answers
355 views

I am wondering if it is good practice to name function which does the main logic "proceed" + "functionName". I would use that name if there are some checks(if-s, try-catches, etc.) ...
Jakov's user avatar
  • 151
0 votes
2 answers
819 views

I am writing a documentation for a programm where a function is defined and it is called three times. I call the definition of the function "function definition". But what is the correct ...
Harry Berry's user avatar
1 vote
4 answers
1k views

I have a function that repeatedly encodes Foos to string. I'm currently deciding between two ways to implement this: Return by value: std::string encode(const Foo& foo); void important_function() ...
cube's user avatar
  • 157
2 votes
1 answer
668 views

The program is written in JavaScript. To give you a rough idea what I am thinking of: function State() { return { color: 'green', size: 100, // ... there are other properties here } } ...
becomeocean's user avatar
0 votes
2 answers
421 views

C11 standard says 6.3.2.1 Lvalues, arrays, and function designators A function designator is an expression that has function type. Except when it is the operand of the sizeof operator, 65)...
Tim's user avatar
  • 5,555
1 vote
1 answer
471 views

There are many discussions related to whether it is better to have only one or multiple exit points per function, but it is not clear to me which statements can be considered as exit points: only ...
user90726's user avatar
  • 205

1
2 3 4 5
7