Hacker News new | comments | show | ask | jobs | submit login

I don't find writing JavaScript to be that hard. I don't get all of these compilers like this one, CoffeeScript, and TypeScript. Are people really that lazy that they can't spend the couple days it takes to learn the syntax and gotchas of JavaScript?



I'm working with a singlepage webapp that consists of ~1.5MLOC serverside(+other) and an additional ~100KLOC of javascript (not including libraries).

Refactoring and maintaining consistency are the two big problems we have with Javascript. It's easy enough to write javascript that works and does what we need it to do. The challenges come in when you start having separate components that need to interoperate.

eshint/jshint etc take you only so far (preventing you from dumping things into the global scope, avoiding typos). AMD etc can take you a bit further with async loading, and give a better [more consistent] pattern for exporting things than saying to devs "just put your stuff in an IIFE". FB Flow looks helpful, but it's trying to solve a difficult problem, and unfortunately doesn't work so well with our code thanks to ONE bad decision made a long time ago to rely on declaration hoisting ("unreachable code" :( ).

Anyways, knowing that your code isn't going to work before you start spinning up the application saves a lot of time.

Knowing that you can rename a method/function and have no undefined errors come out of it is great. Being able to look up usages of a method across the entire codebase is also useful. Eventually if Microsoft decide to spend resources on it, TypeScript might get CodeLens (which is on its own all manner of cool+useful).

Having class syntax means that you don't need to worry about external consumers accessing properties that they shouldn't be (+gets rid of silly conventions like underscore private members/methods).

JS is a great language, and it's powerful, but when you're writing large quantities of stuff, sometimes you need structure. Particularly when it's a large team and there are people of wildly varying experience, ranging from near-zero JS experience to people who have used it for a decade or more.


Unit tests fix the changing methods issue as well as making sure it will run when you run it. Types don't save you from that anymore then JSLint would as both can have logic errors.

Browserify can help with breaking your code down into smaller reusable modules for the client side and node you want to make your modules as small as possible? From the sounds of it you fell into the one big huge application that does everything problem instead of breaking it up. The same issues would have happen if you would have done that in any other language.

Varying experience doesn't mean you can give them TypeScript or CoffeeScript and not mess something up. You should still put code reviews and training in place though I do agree JavaScript lets you shoot yourself in the foot much easier.

You can hide variables through closures and sorry not a fan of getters and setters, I feel they are a anti-pattern (http://www.yegor256.com/2014/09/16/getters-and-setters-are-e...).

The one thing that would be nice would be knowing where your code is called. Though if you are using NPM and Browserify then that can be easier as well. I agree though that the tools are not as nice as Visual Studios find callers and the intellisense isn't that good ether but I am willing to trade them for the flexibility of not having to declare types and the simplicity of not having to work around types with generics, interfaces, and casting.

So I think there is structure in Javascript you just have to learn the best ways of implementing it. Yes Javascript makes it a little easier to shoot yourself in the foot but you can still do it with CoffeeScript, TypeScript, or even in C# and Java, we learn from our mistakes. I fell to be successful in Javascript you really need to keep it small and re-factor often but that really is the same in all languages.


TypeScript is different from CoffeeScript, it's not a new language. It's superset of JS, and it almost is JS, only ES6. So that's the direction where JS is going.


Each of your points is valid.

We have unit tests (fewer on the client than server though), CI that runs integration tests, automated UI tests and other stuff - but that's all much slower than "VS tells me that my code's broken so I should fix it before starting to debug". We'll catch bugs with TS or JS, it's just how long it takes to catch them that's the issue.

Modules aren't so much an issue for us (we don't have a big ball of mud IMO), it's how these modules talk to one another. This is not a problem that we experience in our serverside code because we have powerful tools (in terms of the IDE) that largely stop us from doing dumb things. We refactor a lot, and historically doing this in js has been a massive pain (ie there are no GOOD automated tools for refactoring that I'm aware of). If you use C# and move a method, you expect everything to keep working, but you don't have that same expectation when refactoring javascript. If your app is structured correctly, you do get that with TypeScript.

Same with reviews and training - we have both, but our team isn't big enough to have people dedicated to each area. We mostly hire C# devs, for better or worse, and want them to be as productive per hour as possible. Having it harder to shoot yourself in the foot means fewer feet shot over time, regardless of the team and their skillset.

Getters/setters was an unclear use of term "properties" on my behalf (which actually referred mostly exclusively to methods). Regardless of my personal opinions on getter/setter methods/closures etc, we have established patterns that will take a while to change. The problem is there, and so tooling that helps reduce what breaks when we make changes is a big plus. We don't have a robust message bus in the application, so there's a lot of crosstalk (that's a refactoring area).

And, overall, TS is a superset of javascript so you can always just write JS if that's what you've gotta do.

I guess that my overall point is that javascript is a great language (well, it's ok), but that tools like TypeScript just make things "better" for the average developer working on a large-scale system. JS is an organically grown language, and it shows in a number of places. You can do some super-cool things with it, sure, but for a lot of uses it's a worthwhile tradeoff to write something in a slightly-more-strongly-typed way.

We're about 10% new code, 90% refactoring and updating (though that's a guess, I haven't looked at the stats lately). For us, JS is more painful to maintain than C#. From what we've seen, TypeScript will give us significant benefits on that 90%.


All awesome points, I'll have to take a second look at TypeScript. Thanks for the points back.


I don't think laziness or a lack of desire to learn java script is the driving force for these projects. Rather, its simply for people who prefer a facade of strong types over their java script.


What do strong types get you? Being I write a bunch of C# at work and almost all JavaScript at home I find types very limiting, so I still don't get why?


When I implement a type zoo that models the problem I am solving I do not need to spend as much time reasoning about the semantics (with a good IDE) and the compiler warns me if I've done something odd and won't run the program if I've done something wrong.

With a strong typesystem I can first figure out what I need to do, then write it (like a fews of hundreds of lines), compile it and be fairly confident that the program runs almost correctly. Static typesystem does not help with the bugs that have to do with bugs in algorithms (wrong iteration order etc.) but it let's me concentrate on those parts mostly.

Static typing also functions as a self documentation - I see the intended program flow from the type signatures and do not need other means necessarily to figure out what the program flow is.

To me types are like lego bricks and dynamic languages are like ducktape - both have their uses.


I just find them hand holding and limiting.


Well said!

I love it when I can get the computer to hold my hand and limit my actions. Personally I feel the limits of my cognition and enjoy when the computer assists in proofing the correctness of my programs.

That way I can be more sure I don't do anything that breaks the program logic and that developers that come after me remain within the boundaries of correctness when modifying my code. Types don't help in design but they help in forming a coherent whole.

I've figured out there are two constraint systems I can use to effectively write correct programs. One of them is a typesystem and the second is set theory.

Granted, the most mainstream statically typed languages come with so much syntactical baggage and lack type hinting (C++, Java, C#) that they can effectively hide the elegance of types as a problem modeling tool.

Types can be used just as a non-value adding anal-retentive bureaucratic baggage but that's not how they should be used.

I'm professionally mostly a C++ programmer but did not really 'get it' until I familiarized myself with functional languages (Ocaml, F#) which helped me understand how to actually leverage a typesystem to help me write correct code instead of 'just using typedeclarations because the compiler is too stupid to figure out what I want to do'. To be precise, the languages themselves did not really teach me that much but the learning materials I used with those language did.

When I need to do something small data processing in a jiffy I usually pick Python. For small programs few-liners in dynamic languages are usually a win.


>One of them is a typesystem and the second is set theory.

What do you mean with set theory? I'm asking because languages like Ceylon and Whiley have union and intersection types which are basicially set theory.


Sorry, that was a bit odd way of putting it, perhaps.

What I mean that I first model a particular problem on pen and paper as a group of set operations and identities and then implement that using container operations. I.e. a set as a container, or a particular subset of the elements in the container. I totally depends on the program whether that simplifies things or not.

But for instance, I usually find that rather than adding lots of state variables to entities I model state as those objects belonging to various sets. I.e. store object Id in a list pertaining to a particular property.

This way subsystems can be implemented in a non-invasive, and extensible way. The set operators (union, difference etc.) do not need to be implemented explicitly, rather just figure out what is the most simple isomorphic routine to compute the output for that particular operation.


I find Typescript catches all sorts of typos that get missed in pure JS because I don't have 100% code coverage tests. Sure a JSLinter might catch some of those, but it won't find mis-spelled method names.

Other benefits include not having to remember the 'interesting' rules around 'this' in pure JS (though that occassionally slips through in libraries that use it). Having saner (to my eyes) syntax for modules and encapsulation. And having intellisense support in Visual Studio reduces the effort of writing the code.


Both great points!


> all JavaScript at home

Every language works pretty well for solo personal projects. It's when you scale up to dozens of team members and millions of lines of code that some things don't work as well.


I'm sorry, are you hoping I provide an all encompassing answer that convinces you of its usefulness? I can't provide that. Like I said, its simply a matter of personal preference. You find types limiting, others find them helpful.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: