Programing Language: Function Dependency

By Xah Lee. Date:

xah's rumination extempore, episode 201407030022130700, Function dependency.

i haven't seen this in any lang. i want to jot this thought down quickly.

when you program, especially in functional programing, there's function dependency problem.

for example, when you define a function f, and it calls g, but g is in another lib, so typically you do:

require lib-g
defun f () {…}

the problem is, there is no explicit indication, to the programer's eye, or to the compiler engine, what are f's dependency. It's implicit.

functional programing is all about independent units.

this creates a problem. For example, when you refactor code, it's time consuming to move functions because for each you have to find their dependency, which lib they rely on. You have to do this carefully, else your code will break.

i haven't seen this resolved in any lang. Not in emacs lisp, python, perl, ruby, javascript, java, php. My guess is that it's not resolved in haskell or OCaml f# etc friends neither.

decade ago, when coding in Wolfram Language, i've tried to include function names in the function parameter. For example, defun f (x,y,z, g1,g2) where the g is any function this function depends on. i think i tried this for a while. The problem is, often a function depends on lots others, so this isn't sustainable.

has anyone seen this problem? does haskell or any fancy lang address this?

in summary, i think there's roughly 2 issues:

(1) i want be able to know all functions a given function depends on. Either manually but without needing to read the function body, or programatically as a feature of something they call reflection/introspection. For example, showDependency(f) and it output a list of all functions f depends on.

(2) the lib loading scheme needs a way to say which function are needing it. For example, in require libA, libB in all langs i know of, there is no way to know whether libA is actually used, or which function/code uses it, and what stuff is used in libA. Most lang provide some way to specify which function in libA to actually import, but that doesn't do much.

Jean-Philippe Paradis (http://www.hexstreamsoft.com/, https://twitter.com/HexstreamSoft) wrote to say that the Slime mode, a mode for emacs for interaction with Common Lisp, has a editor feature that lets one show a function's dependency. See: http://common-lisp.net/project/slime/doc/html/Cross_002dreference.html

(original post on Google Plus https://plus.google.com/+XahLee/posts/7weUSJpRDLv)

Programing Language Design