Hacker News new | ask | show | jobs
by neves 3007 days ago
The Refactoring book in Javascript looks like an early April, 1st joke :-)

What I really miss is the integration with the automatic refactoring tools in our IDEs. How would I make a heavy refactoring if I already have a "extract method" in my interface? Would it be the same? Some of the refactorings are easier to automate so are more common in the IDEs. Would are better paths considering what is automated?

3 comments

Seems like JavaScript would make sense since there are so many young, inexperienced js developers that stand to potentially benefit from such a book.
Probably it makes sense because it is the most used lang in the world. Everybody has a interpreter on their computers. Also there are more people to buy the book.
I'm asking this from a position of massive ignorance (I'm mostly a backend dev who does the occasional website), but is there any type hinting tooling in the Javascript ecosystem? Python has PEP484 where you annotate types in either comments or docstrings, Ruby has YARD tags used similarly, and smart IDEs can pick up on these and offer decent refactoring tools.

But does anything similar exist in JS land?

TypeScript is fast becoming the go-to language for JavaScript with types.
They still didn't manage to put together a usable language. Just try to import your `Foo` class into `Bar` and your `Bar` class into `Foo`. BOOM! It will explode into your face. And this is just a basic thing which should work in a real language.
I will second this. I've seen some people choose FB's Flow as their type checker, but for me, I'm loving Typescript. It has minor problems when it has to use DefinitelyTyped and integrate with other frameworks, but those are minor in comparison to not having it.
Yes, there is JSDoc[1] which allows you to add type annotations in comments, that can then be used by some tool.

The VSCode editor is able to leverage the TypeScript engine even with vanilla JS to automatically infer types and also supports JSDoc. Basically you write vanilla JS, add JSDoc comments here and there when the inference doesn't work as you want and it gives you most benefits of a typed language, without tying yourself to a specific ecosystem (your teammates could be using something else entirely). It works pretty well.

[1] http://usejsdoc.org/

This is more what I was looking for; the others appear to be supersets of JS.
Flow does this very well. https://flow.org/
I honestly hoped that this was an April fool's joke.