Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Which modern language does typing really well? I would love to try a language in which it isn't frustrating to work with types.

I use types at work in Typescript and Swift but honestly I'm not very convinced it's worth the hassle in most projects. I feel that if the build tool already can tell me what type I should be using, why do I need to pedantically add them everywhere?



I don't have a lot of experience with it and you would have to make the jump over to functional programming but I really like how Ocaml does types. It's all completely inferred by the compiler. This means you have to write very explicit code when it comes to casting--you can't even add an integer and a float without casting--but I don't think this is a bad thing. You can also explicitly type things if you want, and in that case it appears on its own line as opposed to mixed in with the function args. I vastly prefer this. I can't remember exactly what it looks like in Ocaml but in Elixir it looks like:

  @spec full_name(String.t, String.t) :: String.t 
  def full_name(first_name, last_name) do
    "#{first_name} #{last_name}"
  end
As someone who historically hasn't done any typing, I still find this a little noisy, but it lets me read the function as normal and can look at the spec only if there is any confusion.




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

Search: