Refactoring in Vim

I agree with the ‘Vim is not an IDE’ paradigm. But there are times when there isn’t an IDE. Here’s what I use in those situations: Disclaimer: The ubiquity of Language Server Protocol servers, linters and fixers since I wrote this have also brought some great refactoring capabilities to Vim (and other editors). IMO they … Read more

Using mixins vs components for code reuse in Facebook React

Update: this answer is outdated. Stay away from the mixins if you can. I warned you! Mixins Are Dead. Long Live Composition At first, I tried to use subcomponents for this and extract FormWidget and InputWidget. However, I abandoned this approach halfway because I wanted a better control over generated inputs and their state. Two … Read more

What’s the best way to refactor a method that has too many (6+) parameters?

I’m going to assume you mean C#. Some of these things apply to other languages, too. You have several options: switch from constructor to property setters. This can make code more readable, because it’s obvious to the reader which value corresponds to which parameters. Object Initializer syntax makes this look nice. It’s also simple to … Read more

When is a function too long? [closed]

Here is a list of red-flags (in no particular order) that could indicate that a function is too long: Deeply nested control structures: e.g. for-loops 3 levels deep or even just 2 levels deep with nested if-statements that have complex conditions. Too many state-defining parameters: By state-defining parameter, I mean a function parameter that guarantees … Read more

What is in your .vimrc? [closed]

You asked for it 🙂 “{{{Auto Commands ” Automatically cd into the directory that the file is in autocmd BufEnter * execute “chdir “.escape(expand(“%:p:h”), ‘ ‘) ” Remove any trailing whitespace that is in the file autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif ” Restore cursor position to where it was … Read more