Programming Functions and why are they so special

799 views

I’m still trying to wrap my ahead around this concept.

I’ve done basic maths, so I know that f(x) = x is like a function, but I can’t find an intuitive way of explaining why some functions don’t have to return values. In addition, what separates functions from just lines of code?

In: Technology

12 Answers

Anonymous 0 Comments

> but I can’t find an intuitive way of explaining why some functions don’t have to return values

There are lots of other things they could be doing where you don’t necessarily need an output, such as displaying something for the user. I guess in that situation it could still be returning a bool or int to let you know it succeeded or failed, but that’s not always necessary.

> what separates functions from just lines of code?

Technically nothing, but in practice the difference is re-usability. If you’re writing the same lines of code over and over and over you should be putting them in a function. Not only does it keep for file size smaller (which is a big deal in some environments like web development), but then if you have to change that code later you only have to change one place instead of all of them.

You are viewing 1 out of 12 answers, click here to view all answers.