News for hackers. Stuff that matters.
Re:Ruby 2.6 by ajmurmann on Monday December 24, 2018 @10:39AM (#18752583)
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.
Re:Ruby 2.6 by yxhuvud on Monday December 24, 2018 @10:40AM (#18752593)
Try Crystal and you get the joy of Ruby enumerables together with a static type system.
Re:Ruby 2.6 by briandear on Monday December 24, 2018 @12:49PM (#18753241)
Crystal 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!
Re:Ruby 2.6 by pkulak on Monday December 24, 2018 @01:21PM (#18753423)
Kotlin 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.
Re:Ruby 2.6 by kodablah on Monday December 24, 2018 @01:41PM (#18753548)
While 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.
Re:Ruby 2.6 by buckysock on Monday December 24, 2018 @07:52PM (#18755166)
What do you use Coroutines in a static language like Java, for ?
Re:Ruby 2.6 by pkulak on Monday December 24, 2018 @10:58PM (#18755817)
Everywhere I used to use CompleteableFutures, except without ending up with completely unmaintainable code.

https://github.com/Kotlin/kotlinx.coroutines/blob/master/cor...

Re:Ruby 2.6 by buckysock on Tuesday December 25, 2018 @10:01PM (#18760191)
Very interesting, thanks!
Re:Ruby 2.6 by owens99 on Monday December 24, 2018 @01:17PM (#18753388)
Interesting. What’s your opinions on Crystal right now as a substitute for Ruby? Is there a good stack like Rails for Crystal?
Re:Ruby 2.6 by G4BB3R on Monday December 24, 2018 @03:27PM (#18754110)
Take a look at Lucky framework!

https://luckyframework.org

Re:Ruby 2.6 by yxhuvud on Monday December 24, 2018 @03:55PM (#18754219)
Quite immature, especially when it comes to community and library support.

But dang it's nice to do stuff in it.

Re:Ruby 2.6 by Thaxll on Monday December 24, 2018 @03:50PM (#18754206)
Crystal is definitely not production ready, I mean a language without thread support...
Re:Ruby 2.6 by proyb2 on Monday December 24, 2018 @07:13PM (#18755025)
Yeah, it’s only now MT schedulers is work in progress to bring multithread fibers to Crystal

https://github.com/crystal-lang/crystal/pull/7214

Re:Ruby 2.6 by buckysock on Monday December 24, 2018 @07:46PM (#18755137)
Thread support in interpreted languages isn’t that parallel to begin with.
Re:Ruby 2.6 by jashmatthews on Monday December 24, 2018 @07:56PM (#18755181)
JRuby threads are fully parallel and in production use today. CRuby's GIL is an implementation choice rather a property of dynamic/interpreted languages.
Re:Ruby 2.6 by viraptor on Tuesday December 25, 2018 @08:00AM (#18757236)
Is 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.
Re:Ruby 2.6 by pjmlp on Tuesday December 25, 2018 @08:25AM (#18757309)
It is a choice to keep backwards compatibility with the C extensions API.

The GIL would be quite easy to replace otherwise.

Re:Ruby 2.6 by jashmatthews on Wednesday December 26, 2018 @01:19AM (#18760914)
> It is a choice to keep backwards compatibility with the C extensions API.

IIUC for CRuby it's mostly about how to keep the VM simple. Koichi Sasada is working on an ownership based model like Erlang has, which sidesteps a bunch of theses issues.

Re:Ruby 2.6 by buckysock on Tuesday December 25, 2018 @06:26AM (#18757012)
I’m wondering.. what is the effect of letting the JVM handle synchronization then ? Wouldn’t they still need to synchronize within JvM ?
Re:Ruby 2.6 by hota_mazi on Monday December 24, 2018 @03:21PM (#18754076)
Try 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.

Re:Ruby 2.6 by ekvintroj on Monday December 24, 2018 @01:02PM (#18753304)
You should try smalltalk :)
Re:Ruby 2.6 by DevKoala on Monday December 24, 2018 @01:09PM (#18753345)
My 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.
Re:Ruby 2.6 by astazangasta on Monday December 24, 2018 @11:50AM (#18752938)
Can 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.
Re:Ruby 2.6 by tyre on Monday December 24, 2018 @12:33PM (#18753159)
Not 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.

Re:Ruby 2.6 by ken on Monday December 24, 2018 @01:58PM (#18753652)
There'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.

Re:Ruby 2.6 by akjha on Tuesday December 25, 2018 @03:10AM (#18756523)
"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.

Re:Ruby 2.6 by jashmatthews on Wednesday December 26, 2018 @05:25AM (#18761519)
You can prevent nil errors using contracts like in Eiffel and Clojure.
Re:Ruby 2.6 by QuinnWilton on Monday December 24, 2018 @05:51PM (#18754717)
I can't type up a full answer right now, but for me, a strong type system is about being able to model my domain and bake all of my assumptions about that domain into the types I define.

It's a lot easier for me to reason about and avoid edge cases when I can (more or less) verify at compile time that invalid states are impossible.

This is about more than just catching null values, and also encompasses things like mutually exclusive fields, and access control.

If you're interested, I gave a talk once that dives into these ideas more effectively than I can express in this comment: https://github.com/ShaneWilton/programming-with-types-talk/b...

Re:Ruby 2.6 by tanin on Monday December 24, 2018 @01:10PM (#18753350)
For a non-strong-typed language, it's difficult to dive into the code after you haven't work on that codebase for a while.

We were on a really old Mongoid (or carrierwave, or some other gem, can't remember), It was difficult to find the right methods to use and etc.

I understand it was our own fault not to write comprehensive tests or keep all gems up-to-date.

But a dynamic typing language is a lot more "punitive" when we aren't writing perfect code, using perfect design, and/or exercising perfect engineering practices.

Re:Ruby 2.6 by Redoubts on Monday December 24, 2018 @01:34PM (#18753504)
Languages without ADTs and Optionals just feel impoverished.
Re:Ruby 2.6 by yxhuvud on Monday December 24, 2018 @04:00PM (#18754242)
Languages without full blown union types feel so impoverished. With good language typing support (including flow typing), optionals feel quite redundant.
Re:Ruby 2.6 by int_19h on Tuesday December 25, 2018 @06:10AM (#18756975)
But optionals are just a union type (T | None).
Re:Ruby 2.6 by pjmlp on Tuesday December 25, 2018 @08:28AM (#18757321)
Languages without dependent types feel that something is still missing.
Re:Ruby 2.6 by empath75 on Monday December 24, 2018 @12:20PM (#18753082)
Fewer run time errors. Easier testing, among other things.
Re:Ruby 2.6 by karmakaze on Monday December 24, 2018 @01:54PM (#18753621)
The === for Range and Datetime serves as a one example, with a good type system they wouldn't be directly comparable.
Re:Ruby 2.6 by ilrwbwrkhv on Monday December 24, 2018 @12:25PM (#18753107)
what bout clojure?
Re:Ruby 2.6 by anothergoogler on Monday December 24, 2018 @01:13PM (#18753369)
Clojure'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

Good luck with Clojure: https://clojure.github.io/clojure/clojure.core-api.html

Re:Ruby 2.6 by intertextuality on Monday December 24, 2018 @03:58PM (#18754240)
https://clojuredocs.org/ is what I always used. I dislike ruby's docs actually. Rust and Crystal have better UX design for their docs.
Re:Ruby 2.6 by slifin on Monday December 24, 2018 @02:10PM (#18753707)
Re:Ruby 2.6 by anothergoogler on Monday December 24, 2018 @04:28PM (#18754367)
I'm talking about the flat namespace.
Re:Ruby 2.6 by gleenn on Monday December 24, 2018 @07:06PM (#18754996)
While 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.
Re:Ruby 2.6 by smnplk on Monday December 24, 2018 @08:57PM (#18755399)
Oh boy, you are in for some treat if you try Clojure. But be warned, love for Ruby will be gone.
Re:Ruby 2.6 by abecedarius on Monday December 24, 2018 @01:13PM (#18753370)
Can 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...
Re:Ruby 2.6 by ajmurmann on Monday December 24, 2018 @03:44PM (#18754176)
It'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 "!"
Re:Ruby 2.6 by mmahemoff on Monday December 24, 2018 @04:01PM (#18754250)
Also, chaining is extremely concise. e.g. "products.map(&:cost).sort.last"
Re:Ruby 2.6 by klohto on Tuesday December 25, 2018 @06:12AM (#18756982)
I 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.

Re:Ruby 2.6 by viraptor on Tuesday December 25, 2018 @08:05AM (#18757251)
I think you need `products.sort_by(&:cost).last.cost` for the same result.
Re:Ruby 2.6 by klohto on Tuesday December 25, 2018 @10:20AM (#18757700)
You’re correct!
Re:Ruby 2.6 by zem on Monday December 24, 2018 @03:49PM (#18754202)
one 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.
Re:Ruby 2.6 by oweiler on Monday December 24, 2018 @04:28PM (#18754359)
Groovy. Probably because Groovy borrowed quite a lot from Ruby.
Re:Ruby 2.6 by vorg on Monday December 24, 2018 @05:09PM (#18754553)
Apache 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.
Re:Ruby 2.6 by zmmmmm on Tuesday December 25, 2018 @05:10PM (#18759396)
Definitely. 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).
Re:Ruby 2.6 by _hardwaregeek on Monday December 24, 2018 @01:47PM (#18753582)
The 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.
Re:Ruby 2.6 by mikekchar on Monday December 24, 2018 @02:00PM (#18753660)

    head, *tail = *list
Has worked since 1.8. Don't ask me how I know that :-P
Re:Ruby 2.6 by _hardwaregeek on Monday December 24, 2018 @02:34PM (#18753837)
Damn, I should have remembered that. Especially considering I had a project where I had to trawl through the ruby parser including multiple assignment rules.
Re:Ruby 2.6 by mikekchar on Monday December 24, 2018 @03:06PM (#18753990)
To 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.
Re:Ruby 2.6 by akira2501 on Monday December 24, 2018 @03:18PM (#18754062)
> 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.

Re:Ruby 2.6 by mikekchar on Monday December 24, 2018 @05:09PM (#18754547)
Wow. You're right. I'm not sure how I got that wrong. I'm sure I tried it. Thanks for correcting me!
Re:Ruby 2.6 by cpursley on Monday December 24, 2018 @03:18PM (#18754063)
There's always Elixir :)
Re:Ruby 2.6 by throwaway20148 on Monday December 24, 2018 @02:01PM (#18753669)
How is this different than splatting (my lisp is not so great.)?

https://repl.it/repls/EcstaticLamePaint