Live data from Hacker News

Ruby 2.6

anamaria.martinezgomez.name

111–120 of 164 posts

Re: Ruby 2.6

#111

Earlier quoted context omitted.

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.

Languages without ADTs and Optionals just feel impoverished.

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

#112

Earlier quoted context omitted.

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

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

Also, chaining is extremely concise. e.g. "products.map(&:cost).sort.last"

Re: Ruby 2.6

#113
post #68

I am always happy to unwrap my Christmas present from the Ruby team! Some questions about this release: - Are there any benchmarks for the new JIT? - Why was `(Date.today..(Date.today + 1)) === DateTime.now #=> true` false in Ruby 2.5? It seems correct that right now is between today and tomorrow. Is it because one is a Date and the other a DateTime?

> (Date.today..(Date.today + 1)) === DateTime.now #=> true It took me a minute to parse this. (I have never had this problem with Python or JS.)

Note that you would almost never use the === directly - usually it is done by invoking a case statement, so it would be like

  case DateTime.now
  when Date.today..(Date.today + 1)
    .. do something
  else
    .. or not
  end

Re: Ruby 2.6

#114

Earlier quoted context omitted.

In most real world applications, the cost of doing an in-memory data manipulation like this is negligible compared to I/O, waiting for the database etc. It's already the wrong language for someone who wants to squeeze out every CPU cycle, and imo it's a Good Thing for a language upgrade to embrace its strengths ie syntax sugar in the case of Ruby, as long as the perf hit isn't out of control. I'd agree developers sho…

I might be more receptive to this if this was added to all collections, then, rather than just arrays. (Maybe it was? I don’t write Ruby, so I don’t know for sure. Maybe Ruby doesn’t have a generic “collection” protocol?)

Interesting point. Ruby has an Enumerable module, but these methods were added only to Array. Since the main native collections (Set/Hash/Array) all support them now, they could probably be added to Enumerable in the future, with class-specific optimizations if necessary.

Re: Ruby 2.6

#115

What is the complexity of set operations on arrays? This seems a bit too much sugar to me, to the point where people will end up writing inefficient code because they will thing these methods are more performant than they really are. Usually, I like to see explicit conversions to sets to make the performance characteristics explicit.

Typically, they will be linear on the combined size of the arrays. - for example is implemented by putting all elements of the right side in a hash map and then iterating through the first one and deleting all that can be found in the hash.

Re: Ruby 2.6

#116
post #81
post #42

This will be fun. I’m glad we now have some performance improvements to some common methods. For those considering playing with Ruby, you should! One thing I’m surprised not many has mentioned what makes ruby unique and awesome, BLOCKS!

Aren't they like arrow functions in JavaScript?

A lot of this kind of stuff is more about language and standard lib culture than strict language features. Ex - Rust actually has exceptions, technically, in the form of Panics, and you can infact catch them. But the culture of Rust is strongly against using panics in that way. Basically never catch panics and only allow them to happen when you're okay with the whole program blowing up. Use Option and Result and check them if you care about your program not blowing up.

Similarly, Ruby has nice blocks, and many other languages have similar closure support. But Ruby's support is so built-in from day 1 and heavily used in the standard library and the general culture of Ruby gems. Many of the methods in Enumerable take blocks, making it easy to chain a bunch of functional stuff together, even without any support gems and from the earliest days of Ruby.

Re: Ruby 2.6

#117

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…

Groovy. Probably because Groovy borrowed quite a lot from Ruby.

Re: Ruby 2.6

#118
post #87

Earlier quoted context omitted.

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

https://re-find.it ?

I'm talking about the flat namespace.

Re: Ruby 2.6

#119
post #33

Earlier quoted context omitted.

Negative indices aren't magic. They follow the obvious wraparound (modular) pattern: Negative `i` indexes the element in array `a` located at `i % len(a)`. If they worked any other way it'd be madness.

I don't think you got that index calculation right. -1 in array of 5 elements is located at 5-1 == 4, not at 1%5 == 1.

I don't follow your point. We're concerned with the value of -1 % 5, not 1 % 5. There's no definition of the modulus operator on which -1 % 5 = 1.

Re: Ruby 2.6

#120

Earlier quoted context omitted.

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.

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

Wow. You're right. I'm not sure how I got that wrong. I'm sure I tried it. Thanks for correcting me!
Post reply on HN