Hacker News new | ask | show | jobs
by linkmotif 2939 days ago
ES6 is really nice but it’s still JavaScript so it’s untyped and therefore much less pleasant to work with at any kind of scale than, say, Java+IntelliJ which is like butter. Not sure which static typed languages will be WebAssembly-able, though? Go? Rust?
3 comments

JS isn't "untyped", it's dynamically typed. And this is absolutely not a problem at scale if your development practices are up to scratch - or at least, not a bigger problem than the myriad of other design tradeoffs that every major language has to deal with.

Static typing is massively overvalued. It has non-zero value, but it's a tradeoff with other things, and the amount of importance that people tend to place on it is absolutely out of proportion with the actual value it provides.

EDIT: This extends beyond just 'static typing', as well. The design of programming languages is an exercise in tradeoffs, and people rarely take the time to understand the tradeoffs introduced by their pet language feature, instead presenting it as some inherently ideal thing where any language that doesn't have it must therefore be bad.

> Static typing is massively overvalued

Are you serious? If you job involves using a scripting language in the browser, then at least have to decency to look into TypeScript. I converted to TypeScript after having worked on a code base in JavaScript and realized that just adapting one module to TypeScript, the conversion revealed stuff I had no idea it could have possibly slept thru jslint. I am talking major stuff like string to number and non-existent method calls. Ugh.

I used to think that until I tried Rust and found that, without effort, my programs never crashed or had runtime errors. This is possible to achieve in JavaScript, but I do now seriously miss having the compiler do all my safety checks for me!

I still like JS, but I do now appreciate some of the criticisms more.

As somebody who writes both JS and Rust: yes, Rust does prevent most runtime errors.

But this isn't without a cost; it's much more expensive to build abstractions in Rust than in JS (although still cheaper than in most languages), for example, and the strictness does create problems with interoperability ergonomics in some places, especially when working with multiple third-party dependencies.

This goes back to my earlier remark about tradeoffs; strictness is not without its costs. The tradeoffs may be worth it to you, or not, or only for some projects - but it means that it makes no sense to paint things like dynamic typing as inherently bad; it just makes different tradeoffs.

I do share your sentiment of missing such 'upfront error-reporting'; that's precisely why I'm working on better tooling for this, of which the variable-renaming is just one aspect :)

I’m not the best programmer but personally I avoid building abstractions as long as possible, deferring until the abstraction is as obvious as possible. The cost then becomes basically irrelevant because the value is so great. Writing JS even with ES6+ is really unpleasant for me. Abstractions or no asbractions, my mental capacity is quite limited compared to a compiler with 2 cores and 8GB of memory.
It's not scaling issue, it's a refactoring / maintenance issue. Weakly typed languages cost much more to maintain because you can't have good refactoring tools.

In a strongly typed language, if I want to rename a parameter that is used in 20 places, I can hit "Rename," rename it, and it will rename all 20 instances with perfect precision, and that's it. With weakly typed languages, you have to search and replace, which is much more prone to error. This is much more of an issue for JS applications that are much larger than just doing some stuff on a page.

I agree, it's a tradeoff. Many languages these days can do both. The best is strongly typed until you are dealing with JSON or something of that nature.

There is absolutely no reason why this wouldn't be possible in a dynamically typed language. I'm in the process of building such a tool for JS, in fact.

You don't need static typing to do codebase-wide renaming, it just makes it a little easier to build the refactoring tools, but since that is a one-time cost it's not really a particularly important factor in the language design. Other language design decisions have much more influence on this development cost, too, such as reassignability and scoping rules.

"Strong typing" is also something totally different from "static typing" - I'm not sure why you're bringing it up here. The two are not interchangeable terms.

EDIT: Actually, doesn't Webstorm already do such mass-renaming for JS?

EDIT 2: I also object to the use of the word 'refactoring' to refer exclusively to renaming variables. Proper refactoring involves much more work, most of which isn't automatable regardless of the language you're using.

> You don't need static typing to do codebase-wide renaming.

But you do. WebStorm isn’t magical. It can’t understand your untyped code like it can understand typed code.

The more I’m reading your comments on this thread the more I’m not sure you’ve ever used a static typed language with a good IDE. If I am correct, I think it makes more sense for you to try Java/IntelliJ and then weigh in on this subject. You may have a very different opinion.

It’s funny you mention JSON because when you deal with JSON is when you realize what really differentiates the two styles of language.
> JS isn't "untyped", it's dynamically typed

Yeah I mean of course it’s not untyped. What runtime doesn’t have types? C?

> Static typing is massively overvalued.

Have you every worked extensively with Java/IntelliJ or some other combo like C#/VS? It’s night and day compared to wading through the muck of an untyped codebase.

I can accept we might have different tastes, but whenever people say they advantage of static typing isn’t that great I assume they are either exceptionally gifted and don’t benefit much from a static language/compiler or are ignorant on the subject and don’t know better.

Its ugly but for global js variables I use Hungarian notation - eg `var gstrHomeUrl`.
You really shouldn't have global variables in the first place, and this misses the point entirely; the type of something isn't what's important, the semantic meaning of it is. The type can be mentally inferred from that.

Hungarian notation 'solves' a problem here that doesn't exist in the first place.

Try Groovy. All the verbosity of Java and all the type safety of JavaScript.
Apache Groovy's original use case was for scripting classes already written in Java, for stuff like testing and glue code. It added closures to Beanshell, which was the de facto language for scripting Java at the time.

New leadership, er, took over in late 2005 and re-oriented it as a DSL for Grails, and later Gradle. Grails has since died, with virtually no-one upgrading to version 3, or starting new projects in it. The Grails 2 plugin scene is dead. Many sites are converting their Gradle build scripts to Basel, so it's also starting a slow decline.

Around 2012, Groovy was repurposed again with static typing to compete with Java and Scala on Android. But it never succeeded, and the leadership was retrenched 3 yrs ago from VMWare and couldn't find anyone else to financially support them.

Groovy remains OK for scripting Java classes, but it's fast becoming irrelevant now that Java itself has lambdas and type inference.

As Scala and Clojure both have REPLs and now Java too[1] Groovy is totally irrelevant, but it still clings on in a few places.

[1] https://blogs.oracle.com/java/jshell-and-repl-in-java-9

Yeah with lambdas and local type inference in Java it’s less and less relevant but it’s still dynamic and that can be great for tests and little scripts with Grape. I really enjoy Grape despite using it so rarely that I always need to look up how to do things.
I find Spock to be highly enjoyable. It warms my heart.
Groovy is excellent. Highly enjoyable... it’s the real JavaScript. But I prefer Java for production code and Groovy for tests.
Rust already compiles to WebAssembly: https://github.com/rust-lang-nursery/rust-wasm

WebAssembly doesn't yet have garbage collection so Rust is currently the best choice targeting it, IMO.