8 ms·
Ruby used to be my most beloved language. I've since developed a strong appreciation for good type system. However, working with collections of any kind in Ruby
by ajmurmann 8y ago
Ruby used to be my most beloved language. I've since developed a strong appreciation for good type system. However, working with collections of any kind in Ruby is just such a joy. The methods around it are so well thought throug and make writing code a joy that in most other languages just would be tedious. On top of that the Ruby team is constantly working on making that aspect even better. I truly don't understand why it seems to me that no other language I use makes even an effort to provide something similar. Getting a map, a reduce and a filter function seems to be as far as most standard libraries are willing to go.
- yxhuvud 8y agoTry Crystal and you get the joy of Ruby enumerables together with a static type system.
- briandear 8y agoCrystal is nice, but my love affair with Swift is going strong. Not exactly Ruby syntax but pretty similar in terms of simplicity. I am a Rubyist who feels right at home with Swift. But for the new year, I definitely want to give Crystal a fair shot!
- pkulak 8y agoKotlin is my new love. Best collections library of any language I've used, great type system, coroutines are amazing, and all of it integrates perfectly with 25 years of rock-solid Java libraries.
- kodablah 8y agoWhile the collections library may be better than others, it has a great many warts, many of which aren't discoverable until you've used it a long time. Some of these warts are a result of JVM interop requirements. It's not just the collections library, while the language is great and better than others, there are mounds of bugs and poor design decisions.
- buckysock 8y agoWhat do you use Coroutines in a static language like Java, for ?
- pkulak 8y agoEverywhere I used to use CompleteableFutures, except without ending up with completely unmaintainable code. https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md https://github.com/Kotlin/kotlinx.coroutines/blob/master/cor...
- buckysock 8y agoVery interesting, thanks!
- owens99 8y agoInteresting. What’s your opinions on Crystal right now as a substitute for Ruby? Is there a good stack like Rails for Crystal?
- Thaxll 8y agoCrystal is definitely not production ready, I mean a language without thread support...
- proyb2 8y agoYeah, it’s only now MT schedulers is work in progress to bring multithread fibers to Crystal https://github.com/crystal-lang/crystal/pull/7214 https://github.com/crystal-lang/crystal/pull/7214
- buckysock 8y agoThread support in interpreted languages isn’t that parallel to begin with.
- jashmatthews 8y agoJRuby threads are fully parallel and in production use today. CRuby's GIL is an implementation choice rather a property of dynamic/interpreted languages.
- buckysock 8y agoI’m wondering.. what is the effect of letting the JVM handle synchronization then ? Wouldn’t they still need to synchronize within JvM ?
- viraptor 8y agoIs it really a "choice" if the alternative is really hard to achieve in practice? It's like calling python's GIL a choice... with numerous projects trying to get rid of it in various ways and never really succeeding to do it while keeping the single threaded performance and the extensions API.
- pjmlp 8y agoIt is a choice to keep backwards compatibility with the C extensions API. The GIL would be quite easy to replace otherwise.
- astazangasta 8y agoCan you comment on why a good type system became so important to you? I can understand the value in interfaces but not really in any other context.
- empath75 8y agoFewer run time errors. Easier testing, among other things.
- tyre 8y agoNot having `nil` is soooo nice. I can't count the number of `Runtime Error`s because some method isn't defined on `NilClass` that have blown things up in weird edge cases. Knowing exactly what types a method takes and the compiler catching incorrect uses before the code ever runs saves a lot of frustration. Another thing I've enjoyed in Rust include `match` clauses forcing me to define branches for any possibility, especially for `Result` structs. In ruby this isn't possible because anything can be anything.
- ken 8y agoThere's got to be more to it than "has / doesn't have nil". Lisp has nil, and I rarely if ever see an analogous error there, or even a type error. I have a hunch that single/static dispatch is what tends to cause more problems than merely the presence of nil. It's not nil, but how you use it.
- akjha 8y ago"It's not nil, but how you use it." Can you elaborate on how multi-dispatch reduces the issue of nil/null? I also use static type (typescript) to prevent issues with nil and would like to know how I can achieve the same in a dynamic language.
- jashmatthews 8y agoYou can prevent nil errors using contracts like in Eiffel and Clojure.
- ilrwbwrkhv 8y agowhat bout clojure?
- anothergoogler 8y agoClojure's stdlib is unintuitive, and `into` is the poster child. It's easy to find what's available in Ruby: https://ruby-doc.org/core-2.5.3/Enumerable.html https://ruby-doc.org/core-2.5.3/Enumerable.html Good luck with Clojure: https://clojure.github.io/clojure/clojure.core-api.html https://clojure.github.io/clojure/clojure.core-api.html
- slifin 8y agohttps://re-find.it https://re-find.it ?
- anothergoogler 8y agoI'm talking about the flat namespace.
- gleenn 8y agoWhile I understand the sentiment that all the functions aren't necessarily grouped as in OO languages, I think the Clojure functions are harder to group because they're more general. That's not necessarily the strongest argument, but it is so much more obvious in OO because you always have the object to group by compared to functional languages.
- intertextuality 8y agohttps://clojuredocs.org/ https://clojuredocs.org/ is what I always used. I dislike ruby's docs actually. Rust and Crystal have better UX design for their docs.
- ekvintroj 8y agoYou should try smalltalk :)
- DevKoala 8y agoMy thoughts exactly. I feel it isn’t the library, but the grammar, which is why the same feel cannot be replicated by other languages. Ruby is just easy on collections.
- abecedarius 8y agoCan you recommend a post/article explaining some of what makes Ruby's collections especially pleasant? Studying Ruby's stdlib design has been on my 'someday' list, but there's so much else there...
- ajmurmann 8y agoIt's mostly how complete the API is and how consistent. For example: * Hash#merge takes a block for conflict resolution. I use this all the time for aggregating counts. * #sample * #unique * Everything has a change in place option by appending "!"
- mmahemoff 8y agoAlso, chaining is extremely concise. e.g. "products.map(&:cost).sort.last"
- klohto 8y agoI couldn't resist... Your example could be improved by using "products.sort_by(&:cost).last" I try to not use map because often there are methods that already implement filtering. Gotta love Ruby readability.
- zem 8y agoone beautiful design decision ruby made really on was that every method would have the option to take a block of code when it was invoked. the code block gets passed to the method as a closure. this makes writing collection apis very pleasant, since so many of them involve passing in a single closure to operate on each element.
- _hardwaregeek 8y agoThe only collection I wish Ruby improved upon is a simple Lisp style linked list. Kind of amazed JS has an easier way to do cdr than Ruby: const list = [ 1, 3, 4, 2, 8, 5]; const [fst, ...snd] = list; But I suppose that's just a result of JS implementing pseudo-pattern matching.
- mikekchar 8y agohead, *tail = *list Has worked since 1.8. Don't ask me how I know that :-P
- _hardwaregeek 8y agoDamn, I should have remembered that. Especially considering I had a project where I had to trawl through the ruby parser including multiple assignment rules.
- mikekchar 8y agoTo be fair, I find the destructuring syntax strange in Ruby. For example, why do I need the splat on the list? It doesn't make sense to me. I'm sure there is a good reason buried in the implementation, but if I were to design the syntax, I don't think I would do it that way.
- akira2501 8y ago> For example, why do I need the splat on the list? You don't on the RHS, or rather, it's redundant in the given example. On the LHS you need it to prevent single element capture.. and within the ruby language, it's a fairly consistent sigil.
- mikekchar 8y agoWow. You're right. I'm not sure how I got that wrong. I'm sure I tried it. Thanks for correcting me!
- hota_mazi 8y agoTry Kotlin and its collections. I used to love Ruby too but the dynamic typing quickly became a deal breaker. So I set out to find a language that's as pleasant to use on a daily basis, with well designed libraries and collections, but also statically typed. Kotlin met all these requirements for me.
- oweiler 8y agoGroovy. Probably because Groovy borrowed quite a lot from Ruby.
- vorg 8y agoApache Groovy even borrowed its name from Ruby -- it's really Gruby, if you get what I mean. And of course Grails started off as a clone of Rails.
- zmmmmm 8y agoDefinitely. I dabbled in Ruby but kept coming back to Groovy because it had all the nice syntax of Ruby but all the advantages of the JVM, solid Java ecosystem / libraries and optional strong / static typing to apply when valuable (eg: defining interfaces or data types).
- smnplk 8y agoOh boy, you are in for some treat if you try Clojure. But be warned, love for Ruby will be gone.