Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Readability Suggestions #91

Open
nmccready opened this issue Nov 1, 2019 · 7 comments
Open

Code Readability Suggestions #91

nmccready opened this issue Nov 1, 2019 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@nmccready
Copy link

nmccready commented Nov 1, 2019

First off this project is really cool and I am trying to understand it and contribute to it.

However, I am finding the codebase significantly difficult to read.

This difficulty to me seems to extend from the heavy usage of arrays to be utilized later as function arguments.

Many of the array usage stems from entryPoint andproxyLambdaRequest which in turn get pumped into a zero-process. This process boils down to 8 function arguments. This would be a ton more readable if structuring and destructuring were used instead.

Areas where the code is very difficult to read for me begin in buildManifest.js.

Which has led to comments such as:

  // get all related files (imports/requires) of this lambda
  lambdas = lambdas.map(endpoint => {
    /*
      TRYING TO FIGURE THIS OUT
      endpoint at this moment is:
        [urlPath, relativeFilePath, lambdaType]
      to become:
        [urlPath, relativeFilePath, lambdaType, [relativeFilePath, ...dependencyTreePaths]]
    */
    endpoint.push(
      [endpoint[1]].concat(dependencyTree(endpoint[2], endpoint[1]))
    );
    return endpoint;
  });

Anyway, I don't mean to be critical I just want this to be easy to help out.

@nmccready
Copy link
Author

Also see here:

https://stackoverflow.com/questions/12826977/multiple-arguments-vs-options-object#answer-12827204

Also no more than 3 arguments is possible consideration when deciding to switch to options object arg.

https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)

@asadm
Copy link
Contributor

asadm commented Nov 1, 2019

I absolutely agree with this!
The project needs a cleanup. As you have found, the whole problem stems from the format of the internal manifest, which is full of arrays.
I would get to solving this and the resultant argument hell asap! (currently working on making the latest release stable)

In the meantime, if you feel like you can give it a shot please go ahead!

@nmccready
Copy link
Author

Ok, I have a PR coming soon with an additional way to deal with middlewares where most my issues stem from loading a middle ware that support dynamic swagger. Should make more sense in the PR. But I have a basic express example without zero which I would like to work with zero.

https://github.com/nmccready/swagger-express-ts-example

See how to use swagger-express-ts here .

Bottom line is the middleware needs to be loaded prior without a file based route. So I am trying to make this work dynamically by adding a middlewareHandler.

@nmccready
Copy link
Author

nmccready commented Nov 1, 2019

Another thing you might want to consider is adding lazy logging to your debug usage which would improve performance.

See:

❯ yarn bench-basic
yarn run v1.19.1
$ node benchmarks/utils/runbench basic
Running BASIC benchmark

benchBunyan*10000: 496.290ms
benchBole*10000: 391.516ms
benchDebug*10000: 265.778ms
benchDebugDisabled*10000: 15.453ms
benchDebugFab*10000: 321.426ms
benchDebugFabCb*10000: 211.910ms
benchDebugFabDisabled*10000: 15.509ms
benchDebugFabCbDisabled*10000: 11.169ms
benchLogLevel*10000: 354.771ms
benchPino*10000: 207.691ms
benchPinoExtreme*10000: 83.104ms
benchPinoNodeStream*10000: 165.529ms
benchBunyan*10000: 454.094ms
benchBole*10000: 197.889ms
benchDebug*10000: 233.785ms
benchDebugDisabled*10000: 16.748ms
benchDebugFab*10000: 221.447ms
benchDebugFabCb*10000: 360.479ms
benchDebugFabDisabled*10000: 8.201ms
benchDebugFabCbDisabled*10000: 8.417ms
benchLogLevel*10000: 245.009ms
benchPino*10000: 186.967ms
benchPinoExtreme*10000: 72.358ms
benchPinoNodeStream*10000: 157.134ms

Notice the Disabled levels. Thats with that log level off.

@asadm asadm added the help wanted Extra attention is needed label Nov 4, 2019
@asadm
Copy link
Contributor

asadm commented Nov 19, 2019

Thanks, I will check the debug module. As for the original issue, #94 and #97 should improve this.

@nmccready
Copy link
Author

#94 looks great

Not sure if I should dive into #97 yet for understanding. What's the intent for the emitter to improve ?

@asadm
Copy link
Contributor

asadm commented Nov 23, 2019

Previously, there was a callback hell between file watcher, manifest module and the router. Because on each file change we needed to generate a new manifest and then on a new manifest, we needed to tell the router to update itself (if any pages were added or removed etc).

With emitter model, we just pass these emitters and the module listens for events internally.

Would love you feedback on the updated structure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants