English 中文(简体)
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...!).

问题回答

暂无回答




相关问题
XML-RPC Standard and XML Data Type

I was looking at XML-RPC for a project. And correct me if I m wrong, but it seems like XML-RPC has no XML datatype. Are you supposed to pass as a string? or something else? Am I missing something? ...

Is it exists any "rss hosting" with API for creating feeds

I am creating a desktop app that will create some reports. I want to export these reports as RSS or ATOM feeds. I can easily create feeds with Rome lib for Java. But I have no idea how to spread them. ...

Improving Q-Learning

I am currently using Q-Learning to try to teach a bot how to move in a room filled with walls/obstacles. It must start in any place in the room and get to the goal state(this might be, to the tile ...

High-traffic, Highly-secure web API, what language? [closed]

If you were planning on building a high-traffic, very secure site what language would you use? For example, if you were planning on say building an authorize.net-scale site, that had to handle tons ...

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 ...

热门标签