Hacker News new | comments | show | ask | jobs | submit login
Ask HN: If I only learn one static typed language, which one should I learn?
35 points by zappo2938 on Apr 20, 2017 | hide | past | web | favorite | 64 comments
I am proficient with PHP and Node.js. Which static language would be most useful to learn?

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.

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#.

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).

Yes, absolutely, I had meant to mention that one but got distracted. Although it does rather collapse with Java in my mind.

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.

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!"

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.

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.

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.

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. :)

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.

Typescript is not, strictly speaking, statically typed.

This really depends on the reason you want to learn.

For back-end development I would orient towards Golang. Its approach to concurrency makes efficiently utilizing multiple cores a breeze; something that is not quite so simple in Node/PHP. As well, it's common that you'll find yourself able to get more out of individual machines - this will allow you to get more money out of said machines and, as a second-order effect, can delay the onset of scaling concerns. As an aside, as a primarily JavaScript developer, I do have to admit Go has a very impressive stdlib.

For taming your tools but not changing ecosystems I would recommend looking into TypeScript. It just being a superset of JavaScript means you can do incremental adoption while still enjoying all of the JS knowledge you've built to date.

For learning new paradigms I would either recommend Haskell for a "strict functional" path or Rust for an "immutable/non-racy" approach. Both languages take the concepts to a pretty extreme level and may feel overwhelming at first, but they can be brought back to your existing back-end development skills to help enhance the maintainability of your code.

For something between concurrency and functional programming I would recommend Erlang/Elixir - though I do so only from recommendations and not from any meaningful experience with either. Might be up your alley and definitely worth at least considering for your "one language".

I've been doing this for 20 years and professionally used all the major languages and all the major paradigms.


C is high level assembler and manipulating assembly is the foundation of computer science.

What C provides over assembly is...type safety. Why is type safety useful and important? Bad assembly.

Why is a compiler useful and how do you use a compiler to prevent bugs? C compilers make understandable and idiomatic assembly and strong types make it easy to prevent lots of defects that are caused by imprecision and ambiguity.

From an employment perspective, data structures and many algorithms are easiest to grok and express with pointers. Most of the major programming companies will ask whiteboard questions in interviews and many of those questions test for proficiency with pointers.

Much of the key open source systems works are implemented in...C.

The other languages may give you a temporary advantage but I think only C gives a coder the foundational work for a long and successful programming career.

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.

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.

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.

You will maximize your job opportunities with Java.

Actually, I would suggest typescript and c# .

C# because I love it after experimenting with a lot of languages ( VB.net the first and c# second though, I'm a bit biased) and typescript because it will improve your current nodejs writing.

Both are closely aligned and I think it's perfect in your case. Start the next project with typescript and change to c# later for another project.

Also, there are a ton of projects to learn from. But other than that ( a lot of languages have great examples), there is a lot of employment in c# and it seems to be a sure bet future-wise.

Ps. CMS -> Umbraco. Webshop -> Merchello. It's like woocommerce and WordPress but easier and cleaner

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.

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.

Agreed. If your speciality is in DevOps, it's probably going to be golang for you. We wrote a blog post about it here: https://blog.bluematador.com/posts/mini-guide-google-golang-...

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.

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.

Useful for writing front-ends? Typescript.

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

Useful for learning about type theory? Haskell.

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.

C#. It's used from the web (ASP.NET) to gamedev (Unity), and has an excellent implementation of most mainstream view on statically, strongly typed OOP. In my opinion, the best language to write usual business logic heavy projects, that don't need dynamic metaprogramming trickery on one hand and manual memory and cpu cycle management on another.

There are many other languages that will teach you valuable things; buy if you're asking about one, or at least the first one, C# is definetly the best choice. When you'll come from it to Haskell or Rust, you will already be equipped with a habit for OOP and static typing, and will not face a frustrating cognitive overload.

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.

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.

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.

Practicality-wise, I'd suggest Javascript because you learn it once and you can use it for frontend (DOM, angular, react, etc) and backend (node.js), all of which are very popular and highly-demanded. For learning-wise, it's not the best language to learn about language concept though..

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.

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.

I would strongly recommend C. You will learn a lot about computers, rather than computer science.

If you want to stay in the computer science realm, I would recommend C#, C++, or Go. All three have the critical mass to be dominant languages in the next decade.

I'm not sure what CS means in this context but my experience has been that C is the language of choice when doing "real CS" - which I'd define as the analysis, use and invention of data structures and algorithms on Turing machines.

If you mean the engineering practice of turning specifications into machines then there are definitely better languages for that.

A lot of people here say C#. Well, that is a decent option, but I think F# is overall better (however, obviously C# have a bigger job market).

F# is similar to oCalm, still can do the things C# do, still you can use C#, still you are using .NET.

That is a lot of plus!

The main downside is the smaller job market.


BTW if you use PHP/JS, C# will not teach you much. Is also "OO" and much code around, specially old or coming from the corporate world is not eye opener.

PHP/Js are less well designed languages, that encourage and celebrate bad practices... but most decent developers learn to workaround that and coming to other languages will look at first like "same".

Require some study and effort to see how much C# is better.

In contrast, F#, Pascal, oCalm, Haskell, Rust, etc will open your mind and increase your skills, because will move you out the comfort zone.

I currently use Go, but recently have found C# to be very nice to work with.

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.

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.

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.

https://kotlinlang.org might be worth trying too

I am still facing dilemma Java vs C#. I have to say I like C# more but there seems to be many more Java jobs than C#.

There are so many jobs in both of them that if you're having trouble getting hired, you probably should learn a little bit more.

Right. But location matters and in smaller parts of the world it is difficult to be picky.

Go is fantastic

You Go

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.

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