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.

Best practice for wrapping function arguments

See original GitHub issue

Style guide should advise wrapping function arguments that go over maximum line length.

function someVeryLongFunctionName(someVeryLongArgumentName1, someVeryLongArgumentName2, someVeryLongArgumentName3) {
  // Function body
}

or:

function myFunction(someArg1, someArg2, someArg3, someArg4, someArg5, someArg6, someArg7, someArg8) {
  // Function body
}

Wrapped:

function myFunction(someArg1, someArg2, someArg3, someArg4,
                    someArg5, someArg6, someArg7, someArg8) {
  // Function body
}

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:11

github_iconTop GitHub Comments

31reactions
elliotchancecommented, Nov 9, 2015

Is there any word on this? Compared to alternative which is common in PHP’s PSR to chop down like:

function myFunction(
  someVeryLongArgumentName1,
  someVeryLongArgumentName2,
  someVeryLongArgumentName3
) {
  // Function body
}

It’s better for version control to have one argument per line (the same reason we have trailing commas), is easer to read and is more friendly with default arguments.

Thoughts?

3reactions
jakubbarczykcommented, Jan 2, 2019

I suggest watching any talk by Kevlin Henney related to code formatting, noise and style. May be an eye-opener to some developers out there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrapping function arguments? - c++ - Stack Overflow
Yes, it's better. You basically have a pack of variables that you need to manipulate together, and which have to be passed around...
Read more >
How to Correctly Wrap a JavaScript Function - TrackJS
Wrapping JavaScript functions lets you add common logic to functions you do not control, like native and ... How do we pass function...
Read more >
Strategies for parameter wrapping
Better typing; wrapping related parameters together into a single type can help clarify the meaning of the function.
Read more >
JavaScript Code Styling Best Practices — Functions ...
Line breaks between arguments of a function call are only needed if the expressions that we pass in are long. For instance, if...
Read more >
How to write bulletproof function wrappers in JavaScript
The solution: always pass an array of arguments to the wrapped function, matching the length of the arguments provided to the wrapper. If...
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