|
-
Mar 12th, 2018, 04:41 PM
#5
Re: Subroutine VS Function
It's a fun conversation, as hinted by so many people responding. I like to talk all computer sciencey.
Mathematically, a function is a formal definition of a thing that takes inputs and produces outputs. f(x) = x + 3 is a mathematical function. The name is "f of x", because mathemeticians have even fewer keystrokes to waste than programmers and don't like to use descriptive names for things. In English, that would read:
f of x is a function that returns the result of adding three to x.
So if I say "f(7)", I mean "10", because if 7 is x, and f(x) is x + 3, then f(7) = 7 + 3 = 10. Math.
Many programming languages call EVERYTHING functions because programming languages are based on math, and in math a function MUST return a value. Even if you write something goofy like f(x) = 7, that function returns 7. You can't write a function that returns nothing in math. It's impossible.
But in terms of what we do in programming, sometimes we want to "call something" without getting a value back. For example, closing a Window isn't an operation for which there is any sensible return value. So programming languages have to deviate from math in this respect. In a programming language, we can say f(x). That would mean "f of x is a function that returns no value".
C-style languages express this via the return type void. VB expresses this via the Sub/Function distinction. In VB:
- A Function is "a thing you can call that also returns a value".
- A Sub is "a thing you can call that does not return a value".
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|