gabotechs/dep-tree

How to define a dependency? - Proposal and a technique to trace control flow and data flow

imvetri opened this issue · 4 comments

Current project - it works well with dependency for a file defined.
Proposal - how to define code level dependencies? for example, consider below code

var a = Object.keys(b)

Here a is dependent on Object.keys(b), hence a.dependency becomes Object.keys(b)

This will help the project to scale across and within a code as well.

With that intention, how can I define individual dependency pattern?

Being able to form dependencies at the code level would definitely be very interesting, but it falls out of the dep-tree's vision scope.

That project sounds more suitable to be performed by some LSP tooling, as right now, dep-tree is relatively dumb regarding file parsing, mainly for performance and maintainability reasons.

I think the problem is simple, you are right about the computational performance.

Why I think it is simple because dependency in a file is just the assignment operator. Just one case. perhaps there are more than it?

p.s - please feel free to let me know if you are solving some other problem. I opened an issue not with regards to the project and its scope, opened issue to know your thoughts and ideas to solve interesting problem. The reason I'm looking for dependency graph for code level is because once we get a graph of codebase, then, code from one language and framework can be easily regenerated to another language and another framework.

Why I think it is simple because dependency in a file is just the assignment operator.

I would argue that there are more ways of making an entity in the codebase be dependant on another entity without assignment operators, for example:

function sayHello() {
  console.log('hello!')
}

function main() {
  console.log('start program')
  sayHello()
  console.log('end program')
}

In this code sample, function main depends on function sayHello in order to work properly, but there's no assignment operator. Catching this kind of relationships between code entities would require a full parsing on the languages and an analysis on their ASTs, so it might be a big challenge.

PD: I'm going to close this as it's more a discussion rather than an issue, but feel free to write your thoughts and continue the discussion here even if closed.

Catching this kind of relationships between code entities would require a full parsing on the languages and an analysis on their ASTs,

I disagree, because knowing about AST and language is making it look like a challenging problem. Ignorance is bliss.

function sayHello() {
  console.log('hello!')
}

function main() {
  console.log('start program')
  sayHello()
  console.log('end program')
}

This code can be rewritten as


function main() {
  console.log('start program')
  (function sayHello() {
    console.log('hello!')
  })()
  console.log('end program')
}

This code can be rewritten as


function main() {
  console.log('start program')
  console.log('hello!')
  console.log('end program')
}

In other words, flattening a function calls down to its implementation in the place of definition. This will help us to see the code from jumpy thoughts to linear thoughts. It may cause code duplication, and it will make us question that, and not chase it further, ignore the thought, lets duplicate and make it look a straight line for distraction free format.

I mean, this brings a pile of dependencies of files dumped. Even if it sounds too large, its not us who will be working, let the machine run.

Like you brought up, that other than assignment operator, function call are another case, and the case may keep going on, but it will not be infinite number of cases.