Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT NachrichtenPeloton has made a foldable (treadmill)(22.09.2026 um 13:00 Uhr)
IT NachrichtenPeloton has made a foldable (treadmill)(22.09.2026 um 13:00 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Do you remember what a Function is?

When one learns their first programming language and reaches a chapter titled functions, quite scary (or not so much) images from math classes may pop up in one's head in a form of curves on graphs or f(x)-notation expressions. By the end…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

When one learns their first programming language and reaches a chapter titled functions, quite scary (or not so much) images from math classes may pop up in one's head in a form of curves on graphs or f(x)-notation expressions. By the end on the chapter none of those things are encountered (phew) and the knowledge remained afterwards basically is: if you have a bunch of lines of code in your program which you predict to call more than once - consider wrapping it into a function and reuse.

Seems like it doesn't fully match with what we studied about functions at school.





Functions in mathematics



When people work with sets (collections of objects) they often need to define relations between members of given sets. The term function may be used to represent how one quantity depends on another. Or to show an assignment of one element of codomain Y to each element of domain X. Or it is a "rule" which maps elements from one set to elements from another set. Or, in other words, function is something that returns an output for each provided input. The key words here are sets and mapping.



You may recall a quadratic function f(x) = ax² + bx + c (where a, b, c are constants and a is not 0) and its graphical representation (parabola):





There is still a question why I needed this quadratic relations knowledge at school, but here are a few more questions one may have after reading the given definitions:




  • Are there functions without domains (arguments)?

    Yes, they are called constants (e.g., f(x) = 1; domain x is still a part of a function definition though, but it does not affect the result).


  • Are there functions without codomains (return value)?

    Yes, but a function with an empty codomain can only exist if its domain is also empty. Scenario with nonempty input and empty output is impossible!


  • Are there functions with multiple domains?

    Sure, they are called multivariable functions (e.g., adding numbers).


  • Are there functions which do not have outputs for every possible input?

    Yes, they are called partial functions (e.g., division by zero is undefined for real numbers).


  • Are there functions with side-effects?

    No, in mathematics functions are side-effects free!




It is a pretty general overview, there are of course a lot of other types and categories of functions. Let's now take a look at functions programmers write and how they are different (or not) from the definitions above.





Functions in computer science



In programming functions are heavily inspired by and derived from mathematical functions, and they may or may not follow its principles. Consider the code below:




  function fairCoffeePriceUSD(coffee: Coffee): number {
switch(coffee) {
case: Coffee.V60
return 1;
case: Coffee.BatchBrew
return 0.5;
default:
return 0.2
}
}

function processCoffeePayment(coffee: Coffee, card: Card): void {
const price = fairCoffeePriceUSD(coffee);
const res = card.makePayment(price);
console.log('payment result: ', res);
}






The first fairCoffeePriceUSD function maps coffee domain (enum Coffee) to prices codomain (type number) and nothing more.

The second processCoffeePayment function on the other hand breaks 2 important (mathematical) rules: it does not return any value accepting 2 arguments and it produces 2 side effects!






Outro



It is only one example but it suffices to conclude that computer science borrowed the name function (early computers were used primarily for scientific calculation) and extended its meaning to meet modern world needs (I can hardly imagine a side-effects free program).

Even though not all programming languages have this "misleading" function/func/fn keyword (most C family ones just use a return type before a name, others use def/define/defn), they still call it functions (methods in classes is an exception).

Functional programmers tend to call such non-pure functions procedures or subroutines though, try to stay true to mathematical principles of functions and handle effects on a "thin" layer outside, but this is another story...

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Do you remember what a Function is?

Thematisch verwandte Begriffe: remember, what, Function · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94493 | A vulnerability was detected in Gigatech PDV5701 1.0.31_240305_112640. T…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick