-2

I recently moved from Java to JavaScript on Node.js. I was very excited, opened up my IntelliJ IDE for an existing Node.js project only to find I cannot know what the parameters I see functions receiving actually are except for their names (in java I could click the parameter type and see what it is..), I cannot use Ctrl-Alt-H in most cases in order to show call hierarchy, and found myself doing textual search all over the place wasting most of my time on an existing project, while in Java I could navigate easily with the help of the IDE and find almost everything I want to discover about the codebase in seconds, so possibly in Java there was more "ceremony" and writing the code was taking longer time, but now when I want to maintain it I could do that in seconds and find my way there in seconds.

Is it possible at all to maintain a large code base in JavaScript for code you did not write?

I'm really scared now this is what I'm going to do 100% of my time, maintaining Node.js projects, help me get out of the plain text search which wastes most of my time in trying to discover the flows inside the JavaScript project.

It's not code I wrote, I'm trying to maintain others code and it's super extremely difficult to understand the flows. (in Java I could easily find the flows with the help of the IDE)

4
  • 5
    Welcome to javascript world, with variables that are not statically typed so the IDE can't help you that much. IMO Javascript projects are by nature harder to maintain and nodejs just don' fit for very big apps. About how to maintain code, check the library used, read the starter tutorial on them and understand how they were used.
    – Walfrat
    CommentedJun 17, 2016 at 7:08
  • 1
  • 1
    There are extremely powerful IDEs for dynamic languages. See LispWorks, pretty much every Smalltalk IDE, or DrRacket for examples. Unfortunately, the ECMAScript community is still stuck in the 1970s when it comes to IDE features.CommentedJun 17, 2016 at 7:51
  • 2
    Related: programmers.stackexchange.com/a/221658/145776CommentedJun 17, 2016 at 11:06

1 Answer 1

2

If you do not mind recompiling your code, I recommend you to look at TypeScript, developed by Microsoft. It has a C#-like syntax and is a supertype to pure JavaScript, which TypeScript compiles to.

Other than that, in combination with modern JS many modern IDEs, I have had a great experience with WebStorm by JetBrains (though it is very likely other IDEs support it as well), analyze JSDoc provided to functions and give you auto-completion based on the types of parameters you defined.

class A { /** * @param {Number} value */ constructor(value) { this.value = value; } increaseValue() { ++this.value; } /** * @returns {Number} */ getValue() { return this.value; } } class B { /** * @param {A} instanceOfA */ constructor(instanceOfA) { // both increaseValue and getValue methods are available through // auto-completion in WebStorm instanceOfA.increaseValue(); this.value = instanceOfA.getValue(); } /** * @returns {Number} */ getValue() { return this.value; } } 

Obviously, this is not a fool-proof solution and will not give you compile-time checking like TypeScript does, but it is better than nothing and definitely increases readability.

2
  • that is cool so i could start annotating my legacy javascript code with jscode because i don't have actual types to start getting a few benefits (few.. :( ) of types into it with the help of intellij - that is cool i'll try and see how it goes. many thanks.
    – Jas
    CommentedJun 18, 2016 at 8:01
  • @Jas What you are actually doing is kind of like working with undocumented legacy code. The only way how to understand the code or to make it more readable is to go through it function by function and start refactoring it in a way that is easily understood, either by refactoring the functions directly, or using the JSDoc for example. I haven't worked with JavaScript a lot, but I have several years of PHP experience, where you also need to be very careful how to write your code or it becomes a mess.
    – Andy
    CommentedJun 18, 2016 at 8:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.