The function is very probably the most common term that software tester will hear from developers. Let’s explain what is actually a function call and which bugs are commonly triggered by this program control. The post is aligned with the Black Box Software Testing Foundations course (BBST) designed by Rebecca Fiedler, Cem Kaner, and James Bach.
Function call was the first program control, where engineers tried to resolve the problem of code repetition. We first identified standard code with inputs and outputs, and then we put that code into function control. The function is also called a procedure or method. The program stores the current statement memory location and jumps to the memory location of function. When it is done with function statements, it reads the location of the last stored statement and jumps to that location.
Jump vocabulary was from the assembler world when there was actual command jump.
In the picture above, we have an example for the Elixir IO.inspect function call. Input is array [1,2,3], output is “before: [1,2,3]”
A function could have input and could return value(s). Just this freedom gives a broad spectrum of software bugs.
Common Software Bugs
- A function fails without notifying the caller what the failure reason is. This is the case when a function call ignores error value from other function calls. Note that systems calls are function calls.
- A function notifies the caller, but the caller ignores the error code. In my experience, this is the most common software bug with function calls. I created many such bugs 🙂
- Function changes a global variable, but the caller is not aware of that fact. To avoid such bugs, we invented functional programming languages, such as Elixir. In a functional programming language, it is not possible to modify global variables. This fact creates a lot of headaches for developers that arrive from object-oriented programming languages.
- Memory leak. The program needs to store its context before it enters the function, and this costs memory. In the recursive call, functional call itself. Without proper function exit conditions, we get a memory leak.