17 ms·
Ruby 3.2.0 is from another dimension
- vishald 4y agoSweet changes. Nice to see Ruby run on a browser.
- schneems 4y agoI added the syntax error detection in 3.2. I hope it’s helpful!
- dluan 4y agoyou rule
- caseyf 4y agoAmazing thank you
- ElCapitanMarkla 4y agoThat's awesome, thanks.
- sadiqmmm 4y agoYou're amazing bro.
- nextaccountic 4y agoAbout the regex speedup, it looks like Ruby 3.2 is now doing this https://swtch.com/~rsc/regexp/regexp1.html https://swtch.com/~rsc/regexp/regexp1.html
- xrayarx 4y agoAccording to their ticket https://bugs.ruby-lang.org/issues/19104 https://bugs.ruby-lang.org/issues/19104 they are using memoization to defeat regular expression denial of service (ReDoS)
- rurban 4y agoSame trick as perl5 changed to recently. Not related to re2 at all.
- burntsushi 4y agoYes, but there is an interesting clarification here. RE2 has used the "caching" approach documented in the Ruby bug ticket linked for quite some time (since its birth?): https://github.com/google/re2/blob/954656f47fe8fb505d4818da1e128417a79ea500/re2/bitstate.cc#L144-L145 https://github.com/google/re2/blob/954656f47fe8fb505d4818da1... It is mentioned only briefly in Cox's article on regex matching in the wild. Look for the word "bitstate": https://swtch.com/~rsc/regexp/regexp3.html https://swtch.com/~rsc/regexp/regexp3.html I didn't know Perl had implemented this trick too. The paper[1] cited in the Ruby bug ticket was published very recently. When I first read the Ruby bug ticket, I immediately wondered how they sidestepped the memory use problem. The paper's abstract seems to suggest there is some technique for doing so, as it rebuffs the idea of doing "full" memoization. Alas, I do not have access the paper. (Which is fucking ridiculous.) [1]: https://ieeexplore.ieee.org/abstract/document/9519427 https://ieeexplore.ieee.org/abstract/document/9519427
- duckerude 4y agoOne of the authors mirrored the paper: https://fservant.github.io/papers/DavisServantLee-SelectiveMemo-IEEE-SP21.pdf https://fservant.github.io/papers/DavisServantLee-SelectiveM...
- burntsushi 4y agoThanks!
- burntsushi 4y agoOK, now that I have access to the paper, it does very briefly acknowledge RE2: > while caching is used to accelerate backtracking in Perl and a rare path in RE2. Although I wouldn't call it rare. It's probably used every time one wants capturing groups and the regex isn't one pass (pretty common) and the input isn't too big (like, say, a line in a log file). The actual part of the paper that contains the key contribution (memoization but with less space) is fairly dense and I don't have the time right now to look more closely. But it looks like it might be applicable to RE2, Go's regexp package and Rust's regex crate. All three already use already use bounded backtracking (i.e., "full caching"), but if the space usage could be cut back, then it would increase the opportunity of using the bounded backtracker. Namely, all three put a bound on `size(regex) * size(haystack)`. If the search needs something bigger than that bound, then the backtracker isn't used. But if memory usage were instead much less than `size(regex) * size(haystack)`, then the backtracker could be used more often. (Which is a good thing since it's generally faster than a full Thompson NFA simulation.)
- revskill 4y agoYeah, now i can confidently use this to check a string is float def is_float?(fl) fl =~ /(^(\d+)(\.)?(\d+)?)|(^(\d+)?(\.)(\d+))/ end
- geysersam 4y agoForgot the minus sign! Doesn't Ruby allow scientific notation for floats?
- camgunz 4y agoFloats are pretty hard, especially if you're accepting exponentiation: - 1.4 - -1.4 - .4 - -.4 - 1. - -1. ... plus exponents, also you don't need a decimal point if there's an exponent Won't Ruby parse a string into a float? I would just use that and check for an error unless your requirements are different.
- Rafert 4y ago`Float(str, exception: false)` returns either float or nil.
- pwdisswordfish9 4y agoWhat does that pattern match that the following simplification doesn't? /(^(\d+)(\.)?(\d+)?)|(^(\.)(\d+))/
- revskill 4y agoWhat's status of static typing checking ?
- i_v 4y agoSorbet[1] is currently the most robust tooling available. It has a few rough edges and limitations but it otherwise works great for 90% of use cases. [1]: https://sorbet.org https://sorbet.org
- aledalgrande 4y agoAdd tapioca and it's much smoother
- _joel 4y agoOh lovely, there's this morning wasted :)
- berkes 4y agoBut Sorbet is also not part of the language, not part of the std-lib, and AFAIK there aren't plans to make it that.
- janus 4y agoProgress is really good, in this RubyKaigi talk there’s a great demo showcasing the official rbs with vscode integration https://youtu.be/4E4TRgMDYqo https://youtu.be/4E4TRgMDYqo
- Alifatisk 4y agoRBS is still suggested, but have you tried the Contracts gem?
- Fire-Dragon-DoL 4y agoA disaster so far. We tried using Sorbet for a component and we hit ab edgecase where we had to completely remove it. There is a lot of undocumented stuff, conflict between the right tooling and specifically for Sorbet, the lack of structural typing for a language like Ruby (you know, duck typing), makes it very unsuitable, nowhere near Typescript. When we tested, there was barely an experimental type checker for RBS, that was 1 year ago. Overall, we tried, had to bail out and stick to YARD. Horrible experience.
- igravious 4y agoSo great to see Ruby continuing to get so much love and attention after all these years <3 edit: thank you to everyone involved
- joren- 4y agoPerhaps the official release info is of more interest. This blog post is quite 'inspired' by it. It does mention the source but I do not see the added value of the blog post over the official release info: https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-released/ https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-rele...
- rjh29 4y agoThanks. I didn't read the article because it sounded clickbaity. Official release is much better.
- Rafert 4y agoAgreed. The author is surprised by a major Ruby release on Christmas day (tradition for many years) and uses a lot of superlatives for no reason.
- michaelcampbell 4y agoThis is his style; most of his articles are like this I've found.
- pmontra 4y agoThis https://github.com/ruby/ruby/pull/5407 https://github.com/ruby/ruby/pull/5407 is how to run Ruby with WASI.
- tomstuart 4y agoWhile the original Wasm PR description is a useful historical snapshot of the cross-build instructions, the copy in the official documentation is being updated over time: https://github.com/ruby/ruby/blob/master/wasm/README.md https://github.com/ruby/ruby/blob/master/wasm/README.md
- michaelteter 4y agoRuby is my favorite language, and often it is a joy to use because of its combined attributes of brevity, expressive power, and feature consistency. It's disappointing that there are so many more jobs for another popular language - one that lacks the elegance and consistency but which has a larger ecosystem. As far as I know, the only well known reason for a company to choose Ruby is if they want Rails (and obviously if the founding team already knows/likes Ruby). But that other language also has a popular (and comparatively clumsy) web framework plus well known modules for all the fantasy capabilities that startups dream of... you know, the AI/ML "not sure how we will use it but we know it will be great, and it's good for marketing". Sadly, I don't expect this situation to reverse in the future. Maybe like blockchain, once the AI/ML fantasy hype dies down the other comparatively-unpleasant language will lose general appeal and Ruby will gain more attention. Edit - also, the domain squatters "rubylang.org" should lose their domain. There is no legitimate excuse for having this domain which redirects to a general garbage site.
- goodoldneon 4y agoDoes Ruby still not allow type annotations in the same file as your code? Last time I checked, you had to put them in separate .rbs files. That’s a dealbreaker for me
- ric2b 4y agoYou can with a third party library, Sorbet. It's not the nicest experience due to not being native but it works much better than you'd expect without being native.
- ergonaught 4y agoI chose python over ruby eons ago because, for whatever reason, ruby reminded me of perl (not a good thing). Something about the syntax turned me off. Rust has similar problems for me.
- cutler 4y agoFor me the continuity with Perl was the main attraction.
- est 4y ago> because it indicates very precisely where the end is likely to be missing Which means the `end` keyword can be elimilated all together :D
- Alifatisk 4y agoThat would be really interesting to see
- Asooka 4y agoAh, automatic "end" insertion, like JavaScript's automatic semicolon insertion?
- ljm 4y agothis would be close to making whitespace in Ruby significant, which would be unpleasant. Ruby already gives you plenty of options to write code without an 'end' keyword.
- ciconia 4y agoRuby 3.2.0 does provide a significant performance boost, around 10%-20% across a bunch of my projects. Pretty sweet!
- stanislavb 4y agoThat's with YJIT, I guess? Also, have you noticed any memory issues?
- jorge-d 4y agoAre those projects of yours using Rails ?
- alanh 4y agoAnnoying to use acronym "WASI" and assume that everyone knows what it means. Apparently it’s Web Assembly System Interface. But what does that mean? To quote from https://github.com/WebAssembly/WASI https://github.com/WebAssembly/WASI: > The WebAssembly System Interface is not a monolithic standard system interface, but is instead a modular collection of standardized APIs. None of the APIs are required to be implemented to have a compliant runtime. Instead, host environments can choose which APIs make sense for their use cases. Uhh… OK, I guess. So it’s a collection of APIs to allow Web Assembly programs to make system calls? Why not just say that? Edit: The official release notes do not make this mistake. https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-released/ https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-rele...
- capableweb 4y agoOther accronyms that people outside of the intended audience might not know about: - JIT - "just-in-time" compilation - YJIT - "Yet Another Ruby JIT" - Regex - "regular expression" / sometimes "rational expression"
- kgeist 4y ago>The new JIT compiler based on ground breaking Basic Block Versioning already gives some exciting results >This novel approach lazily generates type-specialized versions of basic blocks on-the-fly while propagating context-dependent type information. Does anyone know how it is different from tracing JIT compilers?
- linguistics__ 4y agoJIT compilation is done lazily on a per basic block level (so you only JIT blocks you're about to run). It keeps track of statically known information for specific basic-blocks and specializes different versions of basic blocks based on this. So if you're coming from an if-statement checking the type of X, into a new basic block, then the JIT specializes the block based on the knowledge that X indeed has said type (so it can specialize operations or skip future checks). I can highly recommend watching their presentation on it: https://www.youtube.com/watch?v=PFb5wNj2ztM https://www.youtube.com/watch?v=PFb5wNj2ztM
- kgeist 4y agoThank you, they explain the difference from tracing JITs starting from 11:00
- deleted 4y ago[deleted]
- linguistics__ 4y agoIf you're curious about how their YJIT, with it's lazy basic block versioning, works then I can highly recommend watching their presentation on it: https://www.youtube.com/watch?v=PFb5wNj2ztM https://www.youtube.com/watch?v=PFb5wNj2ztM
- cutler 4y agoDo these YJIT improvements come at the cost of significantly increased memory usage?
- byroot 4y agoYes, like all JITs by definition. The actual memory increase depends heavily on the app size so I could quote some figures but it would likely be irrelevant to you.
- jeltz 4y agoNo, that is not per definition. While the JITing uses memory a JIT can remove unnecessary allocations from the JITed code and in theory reduce memory usage. But in practice you should expect higher memory use.
- cutler 4y agoSo not much to shout about given that Ruby's memory usage isn't great to begin with?
- byroot 4y agoDepends what you are after and what you are constrained by. Some people might be struggling with memory usage and may not see it as worth it, but for others who may have some extra RAM sitting around, it might come as a free perf increase. As for memory usage, proper use of CoW can reduce it dramatically: https://github.com/Shopify/pitchfork/blob/master/benchmark/README.md https://github.com/Shopify/pitchfork/blob/master/benchmark/R...
- scotty79 4y agoRecently I learned of existance of language named toit https://toitlang.org/ https://toitlang.org/ It's dedicated for esp32 programming but it has semantics very similar to Ruby and Python while syntactically it is incredibly simple and clean.
- Alifatisk 4y ago41% faster code execution?! That’s incredible.
- TylerE 4y agoAny recommendations for (Rails-oriented) tutorials that are current (e.g. Rails 7/Ruby 3). Haven't touched either since like Ruby 1.8/Rails 3
- gls2ro 4y agoI cannot recommend something specific but I recommend this website https://rubyandrails.info https://rubyandrails.info (no affiliation) that has a lot of categories and among those one easy to follow free course could be this one https://rubyandrails.info/youtubes/creatorplatform-xyz https://rubyandrails.info/youtubes/creatorplatform-xyz In case you want to stay up to date with what is happening in Ruby world I am curating a free weekly newsletter at https://newsletter.shortruby.com https://newsletter.shortruby.com (I took a two weeks vacation but will be back soon with new editions).
- bernardv 4y agoLove both languages. However, by the time I discovered Ruby, around 2010, I had already invested a lot of time in Python - and the Python ecosystem was already leaps and bounds ahead when it came to numerical and analysis-related libraries. But Ruby had an elegance to it and expressiveness which was a welcome change from Python and other commonly-used languages at the time. I think a lot of people had similar experiences but were already invested in a tool which came with a large collection of ready-made and tested add-ons.
- BuckRogers 4y agoThis whole thread consists of Python vs Ruby discussion. I abandoned both when .NET 5+ was released. C# on Linux makes me happiest.
- stiltzkin 4y agoThis always has been from the beginning of HN, good history threads with many good points.
- claudiug 4y agohow many jobs are using .net + c# on linux, and not some enterprises legacy software? where i live, Germany, is java .net and 99% are enterprises old managers with old software :(
- BuckRogers 4y agoIt doesn't matter, you still want to adopt the best platform.
- Alifatisk 4y agoThere are two things I see Python being better at. - Static typing We have RBS but that is written to a separate file, the only thing I see being close is the Contracts gem - Lots of first class scientific libraries and other cool libs http://sciruby.com http://sciruby.com is working towards lowering that barrier
- aae42 4y agoWasi support goes a long way to making ruby apps truly portable... There's the potential for these to become better than docker style containers
- hbarka 4y agoDoing an image search for Yui Naruse what is going on Google?
- willcodeforfoo 4y agoJust some anecdata but I'm not seeing such dramatic improvements with YJIT, actually in my limited testing it's much slower... Ruby 3.2.0, on a M1 MacBook Pro hitting a simple healthcheck route in a production Rails 6.1 app with wrk (`wrk -c8 -t8 -d30s http://localhost:3000/healthcheck http://localhost:3000/healthcheck`): - 423 reqs/second with JIT disabled (using 229MB of RAM) - 74 reqs/second running with `RUBYOPT="--yjit"` (using 385 MB of RAM) I must be doing something wrong?
- claudiug 4y agodid u check to see ruby is with YJIT enabled? RubyVM::YJIT.enabled? RubyVM::YJIT.runtime_stats