Skip to main content

How To Code? Types Of Functions In Programming

how to code: types of function in programing - img

Types Of Functions In Programming:

In previous post we briefly discussed what are functions in programming and how to use them  in a generic way. Here, you will learn what are different types of functions.
Functions are divided into two categories based on where their definition exists.
  1. Built in functions
  2. User define functions

1. Built-in Functions

Built-in functions are those which are already defined in a library. All you need to do is to import the library and call the function. There is no need to define and declare the required function.

Steps to use Built-in function:

Each and every language has a rich set of libraries developed for specific purposes. It is really hard to remember all of these libraries and functions and there is no need to remember at all. Here are listed some steps that I would suggest you to find a library and its functions for certain task.
  1. Understand both the problem and your solution
  2. Search a library suitable for your need
  3. Find your required function and read its documentation
  4. Use

2. User define functions

As the name suggests, user define functions are those which are defined by the user. 
A user define function is declared by the user (the developer) and the definition is written before a function call is made to it.

Types of Functions:

Recall the input/parameter and output/return from previous post. Based on these 2 features, functions are of 4 types:
  1. Functions with no input no output
  2. Functions with only input
  3. Functions with only output
  4. Functions with both input and output
types of functions in programming
Functions are like puzzle pieces. You can use it the way you want.

1. Functions with no input no output 

As far as I know, this type of function is used in very rare cases. It does not accept any input parameter and does not return any output value. But it does not mean it is useless. It depends upon your creativity how you use it.

How to use?

I use this type only when I need to display fix information for user or for debugging. It could also be used in combination with global variables which is considered the worst practice or with constants.

2. Functions with only input

Function with only input is declared and defined with a certain number of input parameters but no return value. It takes values from other scopes in the code but does not transfer the result to any other scope.

How to use?

The output value could be directly printed on screen, written to a file, stored in a reference parameter or passed to another function as input.
Again, it is your creativity how you use it.

3. Functions with only output

Functions with only output have only return value type and no input parameters. 

How to use? 

The input for this type of functions does not come from another scope. Either the global values or constant values are used (not recommended) or input is created by internal processing. For example input could be read from a file or any other function with a return value.

4. Functions with both input and output

It allows us to pass the parameters to the function while calling the function. This type of functions will return some value when it is called. Data Type of the return value depends on the return type of function declaration.

How to use?

This type of functions are fully dynamic functions which provide maximum control to the developer. It is most widely used type of function. Decoupling, one of the best programming practices is easily achieved using functions with both input and output.

Next: Function Overloading

Comments

Post a comment

Popular posts from this blog

Introduction to Data Science: What is Big Data?

What Is Big Data First, we will discuss how big data is evaluated step by step process. Evolution of Data How the data evolved and how the big data came. Nowadays the data have been evaluated from different sources like the evolution of technology, IoT(Internet of Things), Social media like Facebook, Instagram, Twitter, YouTube, many other sources the data has been created day by day. 1. Evolution of  Technology We will see how technology is evolved as we see from the below image at the earlier stages we have the landline phone but now we have smartphones of Android, IoS, and HongMeng Os (Huawei)  that are making our life smarter as well as our phone smarter. Apart from that, we have heavily built a desktop for processing of Mb's data that we were using a floppy you will remember how much data it can be stored after that hard disk has been introduced which can stored data in Tb. Now due to modern technology, we can be stored data in the cloud as well. Similarly, nowadays we noticed …

How Big Data Analytics Can Help You Improve And Grow Your Business?

Big Data Analytics There are certain problems that can only solve through big data. Here we discuss the field big data as "Big Data Analytics". The big data came into the picture we never thought how commodity hardware is used to store and manage the data which is reliable and feasible as compared to the costly sources. Now let us discuss a few examples of how big data analytics is useful nowadays. When you go to websites like Amazon, Youtube, Netflix, and any other websites actually they will provide some field in which recommend some product, videos, movies, and some songs for you. What do you think about how they do it? Basically what kind of data they generated on these kind websites. They make sure to analyze properly. The data generated is not small it is actually big data. Now they analysis these big data they make sure whatever you like and whatever you are the preferences accordingly they generate recommendations for you. If you go to Youtube you have noticed it kn…

AI Vs Machine Learning Vs Deep Learning

AI Vs Machine Learning Vs Deep Learning Artificial intelligence, deep learning and machine learning are often confused with each other. These terms are used interchangeably but do they do not refer to the same thing. These terms are closely related to each other which makes it difficult for beginners to spot differences among them. The reason I think of this puzzle is that AI is classified in many ways. It is divided into subfields with respect to the tasks AI is used for such as computer vision, natural language processing, forecasting and prediction, with respect to the type of approach used for learning and the type of data used. Subfields of Artificial Intelligence have much in common which makes it difficult for beginners to clearly differentiate among these areas. Different approaches of AI can process similar data to perform similar tasks. For example Deep learning and SVM both could be used for object detection task. Both have pros and cons. In some cases Machine Learning is …