Is it normal to save functions in array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it normal to save functions in array?

14th Sep 2018, 11:13 PM
Saint
Saint - avatar
3 Answers
+ 2
I guess you should specify the language or otherwise it would be too broad to answer. Generally it's uncommon as the purpose of an array is to allow an index-based iteration of same type of data while function encourage code reuse without duplicating similar logic. I'm not aware of the benefit of combining the two and perhaps it's only useful in a very specific scenario.
14th Sep 2018, 11:46 PM
Zephyr Koo
Zephyr Koo - avatar
+ 1
Array is a list of things. Function is a group of commands that can be executed when you call it (use its function name). So, surely you can store functions' names (or pointers) in an array. It is normal. In the subscription model where several client objects register with a server object in order to receive notifications from the server object when some event happens, server object keeps a list (or array) of callback functions of the clients, and execute all of those functions.
15th Sep 2018, 12:03 AM
Rocky Lee
Rocky Lee - avatar
0
Something in the water this week? https://www.sololearn.com/discuss/1499970/?ref=app
15th Sep 2018, 3:14 AM
Janningā­
Janningā­ - avatar