Questions tagged [functions]
Function is a block of code which performs a specific task.
326 questions
7votes
8answers
706views
Why is "one function do more than one thing" a disadvantage of "boolean parameter", but not in "polymorphism"?
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: ...
2votes
3answers
2kviews
Is refactoring scattered functions into a class always a good idea?
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 = {...} ...
9votes
7answers
3kviews
If the sleep time of a function at first time differs from the second time, but the output is the same, is it still a idempotent function?
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....
7votes
6answers
1kviews
Is a callback function with `this` as an argument a bad practice?
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 ...
17votes
8answers
5kviews
When should a function be given an argument vs getting the data itself?
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 ...
0votes
2answers
215views
Why do you need to use pass by reference in C++ to change the value of the arguments inside the function?
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 ...
6votes
4answers
3kviews
How do you honour the principle to only do "one thing" in a method in reactive streams?
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 ...
-4votes
1answer
98views
Is it possible a class method have the same name as an existing function? [closed]
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,...
0votes
1answer
488views
How do function inlining and Tail Call Optimization affect call stack?
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 ...
-1votes
7answers
674views
If you use Inversion of Control, what alternatives to obfuscated function calls exist?
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 ...
0votes
0answers
300views
C# Azure Function Durable Function Vs Batch Timer Trigger Function
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 ...
-1votes
1answer
107views
Most relevant objectively-quantifiable reason to choose to use an object method vs. a function that just accepts the object as a parameter? [closed]
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 ...
0votes
0answers
133views
Python Typechecking versus TypedDicts?
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:...
8votes
5answers
10kviews
Is code written inline faster than using function calls?
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 ...
2votes
2answers
245views
Should I abstract function calls with duplicate arguments?
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 ...