Def, Void, Function?
Recently, I've been learning different programming langages, and come across many different names to initalize a function construct.
For instance, ruby and python use the 开发者_运维知识库def keyword, and php and javascript use function, while VB uses void, etc.
My question is: What is the reasoning and differences between these different constructs and keywords?
C and all the many languages that copied from it don't use any keywords to declare a function -- you just to <returned type> <function name>(<arguments)
. void
is just the way to say "no type at all", i.e. what we used to call a "subroutine" or "procedure" (a "function" that doesn't return any value).
function
, as used in Javascript, is clearly a sharp and immediately obvious keyword, equally usable for both named and nameless functions. IMHO, the best of the bunch.
I don't know what Guido was thinking when he chose def
for named functions and lambda
for unnamed ones (the Netherlands, where he was born and raised and where he was living at the time, has many wonderful beers, of course;-). Ruby just adopted def
from Python, maybe just because it's short (but it has no sensible meaning or interpretation...!).
精彩评论