A VSCode extension to understand function parameters (#note)

I’m super happy with my VSCode setup, and that’s why I rarely install new extensions these days (find a list of my installed extension in my dotfiles). I found out about the Inline Parameters VSCode extension today, and it was worth…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I'm super happy with my VSCode setup, and that's why I rarely install new extensions these days (find a list of my installed extension in my dotfiles). I found out about the Inline Parameters VSCode extension today, and it was worth an install!

The challenge of function parameters

I'm always in favor of avoiding more than three function parameters or single boolean function parameters. If you're not following such rules, code becomes hard to follow and function call hard to understand.

Consider the following example:

function doSomething(isGreat, doLater, cleanUpAfterwards) {
  console.log(isGreat, doLater, cleanUpAfterwards);
}

// uff, that's hard to understand ...
doSomething(true, false, true);

At first sight, the doSomething function definition might not look too bad, but when you discover a doSomething call there is no way to understand what this function is doing and what these arguments mean. You have to navigate to the function definition to find out what's going on. That's not great!

That's why I'm always favoring an options object when a function needs various parameters. It's more characters to type, but improves readability tremendously.

function doSomething(options) {
  const {isGreat, doLater, cleanUpAfterwards} = options;
  console.log(isGreat, doLater, cleanUpAfterwards);
}

// Ahh, that's way better!
doSomething({
  isGreat: true,
  doLater: true,
  cleanUpAfterwards: true
});

Unfortunately, you'll discover messy function definitions all the time, but you can't refactor and change function definitions all the time. This situation is when VSCode tooling can help!

Let tooling make code easier to understand

The Inline parameters VSCode extension annotates the function arguments with their parameters names.

The extension inlines parameter names such as isGreat and doLater.

It inlines parameter names for native DOM methods, too. ?

Great stuff! I can't wait to write some code with this new extension!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2021-07-24T22:00:00+00:00) A VSCode extension to understand function parameters (#note). Retrieved from https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/

MLA
" » A VSCode extension to understand function parameters (#note)." Stefan Judis | Sciencx - Saturday July 24, 2021, https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/
HARVARD
Stefan Judis | Sciencx Saturday July 24, 2021 » A VSCode extension to understand function parameters (#note)., viewed ,<https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/>
VANCOUVER
Stefan Judis | Sciencx - » A VSCode extension to understand function parameters (#note). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/
CHICAGO
" » A VSCode extension to understand function parameters (#note)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/
IEEE
" » A VSCode extension to understand function parameters (#note)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/. [Accessed: ]
rf:citation
» A VSCode extension to understand function parameters (#note) | Stefan Judis | Sciencx | https://www.scien.cx/2021/07/24/a-vscode-extension-to-understand-function-parameters-note/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.