Nepedia
Back to Discover
Fluent Reader
💻

Function (computer programming)

technology Maturity 7-9 Next article →

A function is a very useful tool in computer programming. It is a small unit of software logic that can be called many times. You might hear it called a procedure, a method, or a subroutine. These names often depend on which programming language is being used. For example, Java and C# call them "methods" when they are inside classes. Using functions helps programmers break a huge, hard job into smaller chunks. This makes the work easier to manage and helps the software run better.

Functions work by following a specific set of steps. When a programmer calls a function, the computer jumps to that specific logic. The function has a well-formed interface, which is like a set of rules for how to use it. It performs its task and then returns to where it left off. Many modern computers use a special way to manage this called a call stack. A stack is a way to organize data in a specific order. Every time a function starts, it creates a stack frame. This frame holds the function's own private data and its return address.

Many brilliant people helped develop these ideas over many years. John Mauchly and Kay McNulty worked on subroutines for the ENIAC computer. They used these tools to help calculate missile trajectories during World War II. Alan Turing also discussed these ideas in a 1945 paper. He even invented the idea of a return address stack. Later, Maurice Wilkes, David Wheeler, and Stanley Gill are credited with formally inventing the "closed subroutine." This concept helped make computing much more organized and efficient.

Early computers had very little memory to work with. Because of this, programmers used subroutines to save space. Many machines used punched paper tapes to hold instructions. A programmer could keep a subroutine on its own separate piece of tape. They called these collections of tapes a subroutine library. In 1958, the IBM FORTRAN II compiler was released. This was one of the first languages to support user-written subroutines. Other early languages like ALGOL 58 also supported this type of programming.

Today, functions are part of almost everything we do with technology. You can think of a function like a recipe in a cookbook. Instead of writing out how to crack an egg every time, you just follow the "crack egg" step. This saves time and prevents mistakes. In modern machines, special instructions help these calls happen very fast. Some machines, like the IBM System/360, use specific registers to handle these tasks. This allows for very deep levels of nesting, where one function calls another.

435 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.