question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query regarding coding paradigm used in this library.

See original GitHub issue

Why in the code string concatenation is used to create the function? I can see, this approach is being followed in almost every file. Why shouldn’t it be written as a normal function? For example like this in HookCodeFactory .

switch(this.options.type) { case "sync": return new Function(this.args(), "\"use strict\";\n" + this.header() + this.content({ onError: err => throw ${err};\n, onResult: result => return ${result};\n, onDone: () => "", rethrowIfPossible: true }));

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
ooflorentcommented, May 29, 2018

Sure! Let’s consider the following functions; they are really simple hook factory implementations:

const f = (...fns) => (...args) => {
  for (const fn of fns) {
    fn(...args)
  }
}

const g = (a, b, c) => (x, y) => {
  a(x, y)
  b(x, y)
  c(x, y)
}

Both functions achieve the same thing but g is more specific. While f accepts any number of callbacks and applies any number of arguments on them, g takes 3 callbacks and calls them using 2 arguments. Because g is specialised for this use case, it will perform much better than f.

Keep in mind that tapable is used by webpack. The created hooks can hold dozens of callbacks with multiple arguments depending on the event. Specialised functions like g could not realistically be used to cover all callsites. This is the reason why hooks are generated: this way it is possible to define a specialised version where loops are unrolled to improve performances.

3reactions
ooflorentcommented, Nov 2, 2018

Here is a good explanation: What’s up with monomorphism?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Programming Paradigms – Paradigm Examples for Beginners
Each paradigm consists of certain structures, features, and opinions about how common programming problems should be tackled. The question ...
Read more >
Programming Paradigms in Python - GeeksforGeeks
Paradigm can also be termed as a method to solve some problems or do some tasks. A programming paradigm is an approach to...
Read more >
Perceiving Python programming paradigms - Opensource.com
Python supports imperative, functional, procedural, and object-oriented programming; here are tips on choosing the right one for a specific use ...
Read more >
fogfish/datalog: simplified query engine based on ... - GitHub
Datalog is a query language based on the logic programming paradigm. The library is designed to formalize relation of n-ary streams.
Read more >
Power Query M Primer (Part 5): Paradigm | Ben Gribaudo
But why would someone write needless code? Applied Steps list showing first step selected. For one, how about testing? In the GUI query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found