Ask HN: Fed up with Ruby/Rails; what language should I learn?
So I'm looking for something new. I've done Java development on-and-off professionally for about 4 years. While I love the static typing and simplicity of Java, it's too verbose. I always end up writing a lot of boilerplate code, and I absolutely hate Java projects' XML-centric configuration.
All this lead me to start playing around with Elixir in the last month since that seems to be the new hotness, but so far it's really chafing for me. Simple things like loops and encapsulation seem incredibly complicated. Something as simple as setting a value in a two-dimensional array becomes:
new_row = array
|> Enum.at(row)
|> List.delete_at(column)
|> List.insert_at(column, new_value)
new_array = array
|> List.delete_at(row)
|> List.insert_at(row, new_row)
I'm finding myself passing tons of variables into short methods because there aren't any objects to hold ivars. No doubt some of these difficulties are due to the fact that I don't have much FP experience, so I'm wondering if I should persevere or try something else.On the other hand I've heard some really good things about Scala — that it offers Java's benefits around type while being more concise and readable. I've also heard that Scala has some great capabilities around FP and concurrency.
TL;DR Should I learn Scala, Elixir or some other language I haven't considered?
22 comments
[ 234 ms ] story [ 937 ms ] threadedit: The point I'm trying to make is that you should be asking for suggestions about languages and frameworks, not just languages. Whether or not you have issues with MRI, you're going to have to deal with your new language's ecosystem, not just its runtime.
In terms of maintainability, I've found that unless you're one of Ruby's "gurus" or know all the best practices around the language, it's far too easy for the average developer to write code that will be difficult to maintain long-term.
Do you want to learn the language for fun, or to improve your career prospects in the near term.
What languages are used in the jobs you would like to get?
For example for me I want to get into high frequency trading or prop trading. I know C#, and I am very busy with a family. Therefore as much as I love Haskell, I am going to stick to C# and learn more deeply about multithreading and sockets, how to build muilithreaded systems like servers, exchanges etc. in C#. Then I will be in a good position to apply for those jobs.
For you the answer may be different.
If you don't know the answer, maybe 'spike' a few languages. By spike I mean try out for 6 months in your spare time.
Haskell is a good one, but with FP you can't give up the fight easily. It is possible to get your head around but it takes time, patience and passion.
Once you learn FP, then your brain is upgraded. It is like running a marathon, if you can run a marathon then a 10 mile run becomes something you do to unwind and relax. 10 miles is hard for most people but easy for the marathon runner.
Similarly learning Haskell, type theory etc. will make other formerly hard stuff in Ruby, Java, etc. will now seem easy because you are smarter. This is my experience anyway.
Older: C, Python, Scheme, Lua, Lisp, Haskell, Clojure, C#, and Scala.
Newer languages/frameworks look great when you run through tutorials, but you're going to have issues once you need to do more complicated stuff. Very new frameworks are unlikely to have much documentation and discussions, which means that at some point, you're probably going to need cross your fingers and hope someone replies to your questions or dig into source code yourself. There's nothing wrong with this, it's just the cost of using something that isn't old and popular.
Maintainability for large projects and bad performance are an issue in whatever language or framework you use. A lot of the problems are avoidable once you move past relying on the magic of your web framework and understand how all the stuff you're using works under the covers. After playing with a few languages and frameworks, I'd say it's really useful to just choose one to become an expert in. Being an expert in one and knowing how to mitigate all the warts will help you infinitely when you do eventually move to something new. I think it's much more valuable to be an expert in one stack and intermediate in two than to be intermediate in 20 stacks.
If you have something you really want to build and are already comfortable with Java, I'd suggest just sticking with Java. Newer frameworks like SpringBoot or Play! remove a lot of the XML, if that's your primary complaint. Verbosity... well, every language is going to have something that doesn't match your personal aesthetics. A lot of the really verbose Java can be avoided by changing up your coding style.
If you're just going for self-enrichment, sticking with an FP until you're comfortable with it is great. Just be aware that you may never use the language/framework as an employee. But you'll definitely get huge benefits in your overall skills by learning an FP.
I think this might be a bit of a benefit. I've been messing around with clojure/clojurescript in my free time and playing with a lot of libraries that while reliable are certainly less documented than say Rails or Django. It's actually been a really positive experience since it does force you to either dig through all the relevant source code or go have conversations with members of the language's community. Going to the source is just good exercise and also helps avoid the feeling of encountering magic. Talking with other developers using or making the libraries I've found I end up having more conversations about how things should or could be done (and why). At work or when talking about older stacks there is usually a Right Way(tm) that has been found and accepted and so the why or [sh|c]ould conversations have already been had and are academic at best and crying over spilt milk at worst.
In elixir, data is immutable and hence you can't simply modify data like in non functional programming languages and that leads to complexity when you don't think in terms of functional programming. And regarding the code you posted, I would suggest using maps, then you can access values as
and set values using the put_in macro as I would suggest using elixir + Phoenix framework. It should also be mentioned that given your RoR background, you will feel comfortable using Phoenix and elixir. Performance will not be an issue compared to RoR.Perhaps focus on your goals: whatever makes you happiest or wealthiest or most creative or marketable (with the understanding that this may be cyclical).
Traverse nested structures with `get_in`, `update_in`, `put_in`, and `get_and_update_in`.
Double down and stick with elixir. Any FP principles you learn there will help you should you decide to learn another FP language.
If you would like to stick with a dynamic language I would suggest Python. Django is there if you absolutely need it but there are a wide range of of smaller frameworks available for smaller more focused projects (Falcon, Bottle, Flask).
I used to be a Java programmer and fell in love with Scala and functional programming. Scala helped me do things that I couldn't do so easily in Java in a more explicit way. However, I found doing web development with Scala to be more cumbersome than helpful but was still a great learning experience for FP in general.
Since late 2015, I've been all-in on Elixir. Elixir does everything I wanted to Scala, specifically pattern matching everywhere and how powerful it is. Since Elixir uses BEAM, it's incredibly lightweight but can scale without any configuration. The community around Elixir is fantastic and helpful and everyone is growing together.
Brian Cardarella (well known in the Elixir community) gave a conference talk at Rails Conf about switching from Rails to Phoenix (Elixir's goto for web) and that may be a good start to empower you to make a decision: https://www.youtube.com/watch?v=OxhTQdcieQE.
A great resource for learning Elixir if you choose that route is Programming Elixir 1.2 by Dave Thomas. It's a great book for beginners and can help with you understand Elixir semantics and functional programming.
> Simple things like loops and encapsulation seem incredibly complicated. Something as simple as setting a value in a two-dimensional array...
- Elixir doesn't have loops. You use recursion.
- Elixir only has modules for organisation, and modules are just functions. It's just functions functions functions all the way down. You can nest modules in modules and so on, that's how you would achieve encapsulation.
- Further to that, you'd generally use processes for holding state, but those processes are also just functions, nothing special or different. See http://ferd.ca/the-zen-of-erlang.html- Use maps, not lists, to emulate a 2d array. Lists are not designed to do what you're trying to do there. As you've found out, it becomes incredibly ungainly. Daniel Berkompas wrote a post on this exact thing recently: http://blog.danielberkompas.com/2016/04/23/multidimensional-...
I would stay stick with it. If you shifted across to Scala and tried to do things in the way I think you're doing them atm, you might as well be writing Java: changing to Scala won't make it any easier to adapt to a functional style.