Ask HN: If I only learn one static typed language, which one should I learn?

35 points by zappo2938 ↗ HN
I am proficient with PHP and Node.js. Which static language would be most useful to learn?

66 comments

[ 3.5 ms ] story [ 136 ms ] thread
I'd suggest you check out both Golang and Rust. Being comfortable with both won't hurt - but if you had to choose just one, I'd say play with them both and then make an informed choice.
Assuming you are in web development, I would say Java. People have strong opinions regarding languages. Java may sound relatively old school, but it is in use in many places, and once you are familiar with one language, it is comparatively easier to pick others.
What are your goals?

If your goal is getting a job, looking around in your technical and geographical area and see which languages are used most, which pay the most, which will result in the most interesting jobs.

If your goal is purely educational, try Haskell: you'll learn about functional programming and use a much more powerful typing system than most languages provide.

What are you trying to achieve?

Change the way you think about programming problems: Haskell

Enterprise Development: Java. Maybe Scala?

Apple Ecosystem: Swift (and actually, it seems like a kind-of pleasant language for general server-side use).

Low-level: C++. Or maybe Rust (although not yet given that a serious whirl)

Edit: oh, if you're broadly happy with JS, Typescript is worth a look and might (depending on your circumstances) be something you can start using day-to-day fairly easily.

(comment deleted)
C# is definitely more prevalent than Scala in Enterprise environment. In my experience even between Java and C# it's close to a 55/45 split in Java's favor. Most of the OG Enterprise jobs that people think of like banking will be Java, most of the rest will be C#.
Yes, absolutely, I had meant to mention that one but got distracted. Although it does rather collapse with Java in my mind.
Plus, since 1 or 2 more won't hurt, you can give F# a try for the ML goodness. This may help a progression towards Haskell - found it much easier to grok once I had a bit more playtime with other functional languages.

I personally think, given Node and PHP proficiency, a static functional language may provide more growth in skill. It's a new paradigm as well as typing discipline.

I haven't had a need for it yet professionally but there are a good number of blog posts I've seen extolling the virtues of doing your unit tests in F# (even for a C# application).
I found Golang a pleasure to learn and use. Its minimalism allowed me to pick it up fairly quickly, and features like its baked in documentation allow you to build your libraries as a seeming extension of the language.
If I only learn one right now will I regret choosing Golang over Java?
Golang is focused on scaling/concurrency, is very compact and fairly quick to learn. You can compile a single binary and deploy it anywhere. You can build a web server in a few lines of code. It's really strong for processing tons of requests, web API's and backend code.

Java requires a whole app server which is more of a pain to setup. (generally speaking for web dev, think Tomcat, JBoss). It's way more verbose and you really need to rely on the power of an IDE to help code for you, importing class libraries, etc.

Spend a few hours with each, they're very different. Coming from Node/PHP you should be able to pickup Golang faster.

In the JVM ecosystem you can use Jetty and have a simple embedded App Server. No need to install or configure Tomcat/JBoss, etc.

Spring Boot and Dropwizard makes this dead simple, a single .jar file with everything you need to run your app.

I can set up a basic Tomcat instance, ready for a deployment, in a couple minutes. Weblogic or JBoss is more pain but you don't necessarily need that.
Java definitely does not require an app server.

I'd also submit that few concurrency libraries are as battle-hardened as java.util.concurrent.* at this point.

I think it really depends on what you want to build with it.

Are you planning on making an IOS app?

Do you want to make a back end server?

I picked up Go for my side project for the server side, and it has been a great learning experience.

I think if I were to do a mobile app, I might try Swift.

Practically speaking, Java or C#, purely for the job prospects.

C / C++ if you're looking for something with wide applicability to learning other languages more quickly.

> C / C++ if you're looking for something with wide applicability to learning other languages more quickly.

I came here looking for this. I learned C as my first language [1]. And I learned an immense amount about how things like memory management and type casting and things like that work. It is a foundation that has helped me learn other languages much more quickly.

Although the question is for learning "only one" and I'm not sure C or C++ is a great "only" static typed language.

[1] using "Sams Teach Yourself C in 24 Hours" which I got in an actual bookstore and came with a copy of the Borland C compiler :)... ah the memories.

C was my first "real" language (BASIC was the one before it). I learned using the great C for Dummies by Dan Gookin[1], which at the time consisted of two massive volumes comprising over 1000 pages. Good times.

Nowadays most of my work is PHP and Node.js, but if you know C, you will have no problems learning PHP.

1. https://www.amazon.com/All-One-Desk-Reference-Dummies/dp/076...

PHP is a very close cousin of C. Up until it became Object Oriented it was pretty much a cross between C and Perl.
If you want to really focus on the frontend, I suggest Typescript.

If you want to focus on backend technologies, I suggest Java.

If you have other goals, I think there are a lot of other great answers. :)

Typescript is not, strictly speaking, statically typed.
Honest question, why would you rather choose Java over C#?
C# is a much better language and has better stewardship but Java has extremely broad usage.

Plus, speaking from personal experience, learning Java first and then learning C# is probably going to be a positive experience, whereas doing it the other way around feels like going back ten years in time.

I personally learned Java before C#, and totally agree with that sentiment :D
Way more mature for linux, with all Microsoft efforts, C# still has a long way to catch up on that platform. Also, your Java skills will be transferable to Android.
You will maximize your job opportunities with Java.
You could try Flow (https://flow.org) as you're already familiar with JavaScript. I've been using it after primarily using static languages and it's been great so far.
Go with Swift, it can be used everywhere and it is in high demand right now. Server, desktop, mobile, watch, tv, you name it.

Kotlin comes in second place if you like Android and their mobile ecosystem.

c# is really slick. It really is java without the suck, and with dotnet core / roslyn / azure / asp.net, it's increasingly viable as a cross-platform and web language (with the caveat that the only decent native UI toolkit is windows only). AWS lambdas support C#, as does Unity for game development.
I second this. The whole .Net ecosystem is built really well on object-oriented design principles and I've learned a ton about how DI/IoC and SRP/ISP designs get implemented since switching to C#. Additionally Code Contracts are really fun to experiment with to help you be more thoughtful in learning design by contract. If design skills are important C# is a great language to use for it. The only thing that bothered me at first when I switched to C# was the use of PascalCase member methods, outside of that one nitpick I've been very satisfied, C# is a solid language.
Java, especially with the astounding improvements in JDK 1.8, and the new JEE specifications like CDI, and some of the incredible things coming out in JDK 1.9.

Great language that has stood the test of time and runs on Windows, Linux, OSX, and sometimes Android and IOS.

OCaml or Haskell. They will teach you concepts you can take back into PHP or Node.js to make your code better. And in my frank, unbiased opinion: sound type systems and pure functional programming is the future of the industry.

If you're a pragmatist it's still a good choice. You can bring FP concepts to C, Java, whatever later on too.

> They will teach you concepts you can take back into PHP or Node.js

Curious what these are. The only thing I retain back in dynamically-typed land is "argh I wish this was statically typed!"

I've worked with functions in JavaScript that change functionality radically depending on whether you pass an integer or an object.

I thought this was the way of the world until I got deeper into typed languages, where you learn why not doing that is good. Type envy still stings though.

> I've worked with functions in JavaScript that change functionality radically depending on whether you pass an integer or an object. > I thought this was the way of the world until I got deeper into typed languages, where you learn why not doing that is good. Type envy still stings though.

This is just polymorphism, isn't it? Why is this not a good thing?

In small doses it's fine, but 2000 line functions whose branches have nothing to do with each other is hard to fit in one's head.

The great thing about statically-typed languages is that they help you write your software instead of giving you a blowtorch and saying "have fun". I know a lot of people find that a bit patronizing, but I'm not one to turn down help (especially from a bot that won't call me on it later).

I'm not sure I follow. I don't find "2000-line functions whose branches ..." to be a requirement for polymorphism.

I'm also not against static typing, but I am against thinking it's a silver bullet. Consider this: `function inc(x: number): number { return x - 1; }`. It passes the type checker, but the blow torch still burned you.

A monad is a mathematical abstraction. There's nothing special about Haskell that makes it work with monads. They work great in Javascript, C, Python... the syntax of those languages don't make it terribly easy to work with them but it's still available. You have to be disciplined since you don't have the type system checking your work for you but you still get the benefits of the abstraction.

I'm presently trying to make this a little better in my own team's codebase by trying to introduce Flow [0]. There are a lack of definitions for the monadic libraries we use which I'm presently remedying. It's not pretty -- and my kingdom for OCaml or GHC! -- but it's better than not having it.

Knowing the fundamentals will help you learn to structure code and think clearly about abstractions. It's the difference between merely using something and understanding how it works. In the latter case you have the power to exploit it.

(comment deleted)
The syntactic sugar is perhaps what's special. Code without that isn't so pretty. I do find it impressive, however, because it's based on an abstract, wide-ranging and extremely useful concept that can actually be expressed in the language without it. It follows the pattern that much syntactic sugar we take for granted has followed e.g a while loop is sugar on top of jumps and branching.
For what purpose? My favourite language is haskell, but it may or may not be suited to your goals. It sure as hell won't get you a job easy.
I currently use Go, but recently have found C# to be very nice to work with.
I would raise a humble Kotlin instead of Java for backend and Android work. It is quite simpler than Java and allows a little bit of functional coding, while also being fully interoperable with it.
That's a context-dependent question. If you want to do systems-level stuff that's safe, concurrent, and fast, then learn Rust! I'm having lots of fun with Rust. :-)

If you don't want some of those attributes, then Rust probably isn't the best answer for you.

If you're interested in iOS/Cocoa development, Swift is a top-notch statically typed language with lots of paradigm flexibility. Unfortunately, it isn't used as much outside of that domain.
Most useful in what context?

If you want to pick up a language as quick as possible then C# or Java. Either choice is fine.

C# has a lot of potential in the future now Microsoft are making it more open with multi-platform .NET but it is still a way off IMHO.

Java is used everywhere and while it isn't all that "cool" it does work well, is easy to write, debug and maintain. Plus I actually quite like JavaFX. It allows me to make a nice looking UI very easily. As great as C#/.NET is you can't use C# for any decent GUI stuff outside of Windows just yet.

If you want to get a job then look at what jobs in your area are using.

Swift is a fantastic language with an excellent type system. It can go all the way from writing scripts to building a whole OS and it's about as performance as C/C++. Plus you have a great app ecosystem to build apps for, iOS, TVOS, etc... but it's also open source.
Another vote for Typescript here. For one because it's a really nice modern type system that doesn't get in your way too much. Also because if you're already familiar with node, you'll be able to focus on the language rather than new libraries/tooling/ecosystem.
Elm, it's a lot simpler than any other statically typed language, and compiles to JS. You can run it on node.js with various tricks.
Useful for writing front-ends? Typescript.

Useful for writing back-ends? Java. (Maybe Go.)

Useful for learning about type theory? Haskell.