8 ms·
I wrote a Ruby extension in Zig
- nathell 4y agoIn the same vein, although way outdated: Ruby extensions in D https://tomash.wrug.eu/blog/2009/03/03/rudy-ruby-native-extensions-in-d-programming-language/ https://tomash.wrug.eu/blog/2009/03/03/rudy-ruby-native-exte...
- habibur 4y ago> Fortunately, a few weeks ago an issue I’ve been tracking for about 3 years was resolved. Zig now can export functions with variable arguments. The key part. It wasn't possible to write Ruby extensions in Zig until a few weeks back. Now you can. > I have a story of rewriting part of our production code as Rust extension, which turned out to be 3-4 times faster, but we ditched it anyway, because maintenance cost would be too high. My solution to this problem is to stick with C. Your code won't get obsolete. Most people are still using C99, and not much has changed in 20 years, even in recent versions.
- ajkjk 4y agoBut sticking with C is exactly what we don't want... hence entertaining alternatives. Right?
- nindalf 4y agoThose who think C is inherently good can’t be convinced otherwise. Any argument will be dismissed with “programmers need do be better”. Any assertion will be dismissed as subjective, lacking data. Any data backed study from Microsoft [1] or Google [2], [3] will be dismissed as Big Tech hiring mediocre programmers. There will be vague references to “just use the right sanitizers”. Ultimately we need to recognise that for some people, language is a core part of their identity. At that point criticising “their” language hurts them. If we’re talking to someone who feels this way, it’s best to politely say “is that so?” and gently disengage. I know it’s tempting to think that we could show them just one compelling data point that will change their minds. But that’s not any more possible than convincing someone to stop believing in religion by pointing out factual inconsistencies in scripture. If you tell a committed Christian that Jesus couldn’t have been born in 0AD because Herod died in 4BC and the census they were travelling for happened in 7AD … is that going to make them reconsider everything about their religion? No, they’ll dismiss this as a minor issue that can be worked around. Same with $language programmers. 1 - https://msrc-blog.microsoft.com/2019/07/16/a-proactive-approach-to-more-secure-code/ https://msrc-blog.microsoft.com/2019/07/16/a-proactive-appro... 2 - https://www.chromium.org/Home/chromium-security/memory-safety/ https://www.chromium.org/Home/chromium-security/memory-safet... 3 - https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html https://security.googleblog.com/2022/12/memory-safe-language...
- peoplefromibiza 4y ago> Those who think C is inherently good can’t be convinced otherwise opposite is also true "those who think C is inherently not good [...]" > Any data backed study from Microsoft [1] or Google [2], [3] will be dismissed as Big Tech hiring mediocre programmers. They aren't being dismissed, but criticized when used to promote other languages. Those studies are partial and about a different topic. They are are about bugs in millions lines of code bloated products, written in C++. Not counting the actual implementation "bugs", like the browser X leaking details about users to make fingerprinting easier and then sell ads. You know why those companies are worried about memory safety and nothing else? Because it's the way people can circumvent the so called "features" and "protections" they implement. Here we are talking about Ruby extensions in C, which is a completely different domain, involving completely different tradeoffs. The author confess he's not a great Rust programmer yet, so probably using Rust over a language he knows better, just because Google said it, it's not the best of choices. Just think about the fact that the Ruby interpreter itself is written in C. Think about the fact that a bug in path traversal or input sanitization is at least an order of magnitude easier to exploit and usually more dangerous than a double free. > If you tell a committed Christian that Jesus couldn’t have been born in 0AD because Herod died in 4BC and the census they were travelling for happened in 7AD as a non believer, that is the least problematic issue about Christianity. dates are conventions, we are not actually leaving in 2022, would you change your calendar because dating is completely made up? also: Jesus does not exists nor can do anything for you, C does.
- nindalf 4y agoOh, is that so?
- peoplefromibiza 4y agoyes.
- jeltz 4y agoAs a C programmer I am baffled by your attitude. Do you feel so threatened by people creating new programming languages? Personally I love that people are working on projects like Zig which try to be a better C. Rust is also an interesting project which has had a lot of positive effects on programming and programming language design, but it is not a perfect replacement for C and more of a better C++. While some "innovation" actually make things worse I see a lot of interesting ideas coming from both Rust and Zig. > The author confess he's not a great Rust programmer yet, so probably using Rust over a language he knows better, just because Google said it, it's not the best of choices. He used Zig, not Rust.
- awestroke 4y agoBut I don't like C. I like modern systems languages.
- pjmlp 4y agoC was already dated when compared with languages like Modula-2 from 1978, modern system languages are kind of catching up with how the world used to look like outside Bell Labs walls.
- deleted 4y ago[deleted]
- faraaz98 4y agoIt's been really interesting to see a Ruby article on the HN frontpage almost every week. I wonder what's causing that?
- fredrikholm 4y agoRails 7 and Ruby 3.X releases most likely. I've noticed the same thing.
- deleted 4y ago[deleted]
- awesomegoat_com 4y agoI think it is people that left ruby coming back after seeing the alternatives. :-) I view ruby ecosystem as totally different philosophy system anti-ethical to many others seen in the engineering realm. This may be my personal poorly-educated view, but I cannot shake it. Most of the good engineering practices are based on the orthogonal cartesian view of the world, where ego of the creator wants to believe the that all the corner-cases will be ultimately handled. And we just need time to add this or that component. That leads to increasing complexity and it is a vicious circle because all the abstractions are leaky. While in the ruby community, I don't see above described philosophy to be as strong as it is in other language ecosystems.
- ilyazub 4y agoThis is a very interesting point of view. Can you describe it more in detail or share links to read about the topic "orthogonal cartesian view of the world vs others"? Thank you!
- awesomegoat_com 4y agoI don't think I have any links. It is just something I am noticing after 13 some years in big tech. And unfortunately, I don't think I can "describe it in detail" as that's what the ego wants. That's the whole point, the ego wants to hear the details and then argue with the details. Details often times make a lot of sense, while the end result does not. The U.S. Tax Code is 6,871 pages. When you include the federal tax regulations and the official tax guidance, the number of pages raises to approximately 75,000. Every single word has to be there, because it is solving some corner case. Imagine, a json parsing library 50k LOC in C++ that can be cross compiled on most of the platforms. Every single LOC (line of code) needs to be there. These are creations of the ego (and orthogonal cartesian view). That's the dominant ideology in our world, it works very very well. PS: Everybody knows, you could just parse your little json with `strnstr()`, and somehow we believe that amending cmake anytime it breaks is more meaningful than having spaghetti code calling strnstr that just magically works.
- renox 4y agoFrom the article > D also has a @nogc mode, but it feels like giving up on 60% of the language’s power. Without the GC, D has exactly the same 'power' as Zig have.. I feel that the poster is a bit misleading: he chose Zig instead of D because Zig, being newer, is more fashionable, not because of an imaginary technical reason. If there's a technical reason, it's not written in the article.
- djha-skin 4y agoIt's not really technical though is it? It's the community around D, the micro design decisions. If everything online presupposes you're using garbage collection most of the time, if everything in the language also makes that supposition sure possible to still go against the grain but it does feel like you're going against the grain. Feel and community support is as important as anything else in a language decision.
- faraaz98 4y agohttps://ziglang.org/learn/why_zig_rust_d_cpp/ https://ziglang.org/learn/why_zig_rust_d_cpp/
- peoplefromibiza 4y agohonestly this does not contradict the claim that D is equally powerful, if not more powerful, than Zig. It is, at least, more battle tested.
- henry_viii 4y agoSome of the arguments listed in the page are misleading: > Zig is a programming language, but it also ships with a package manager Which is not true: https://github.com/ziglang/zig/issues/943 https://github.com/ziglang/zig/issues/943 > Zig has no macros and no metaprogramming Literally from Zig's homepage (https://ziglang.org/ https://ziglang.org/): "Comptime - a fresh approach to metaprogramming" The rest of the arguments are very weak in my opinion.
- G4E 4y ago
- Tomte 4y agoPeople, add RSS feeds to your weblogs!
- deleted 4y ago[deleted]
- awesomegoat_com 4y ago:-) For too long, I too have been bothered by amazing writers not having RSS. So, I ended up hacking my own reader, that can parse almost any page and turn it into a stream of logical items. It is interesting how many web resources lack efficient delivery mechanism.
- masklinn 4y ago> I can use Rust, but I have never been on good terms with Rust. I have a story of rewriting part of our production code as Rust extension, which turned out to be 3-4 times faster, but we ditched it anyway, because maintenance cost would be too high That would be an interesting tale, especially in light of helix / ruru / magnus (why so many?) (and I don't know how they compare to pyo3 in terms of ease of use). I can see it if they used "raw" rb_sys though, that seems... not much of an improvement over C unless the API is really small and you can quickly bail out to safe Rust: https://briankung.dev/2022/02/02/writing-a-rust-gem-from-scratch/ https://briankung.dev/2022/02/02/writing-a-rust-gem-from-scr...
- ilyt 4y agoI'd imagine the story is just "we don't really write that much in Rust so going back after a break is a PITA"
- masklinn 4y agoI would assume they don't "really write that much in Zig" either (and Rust would be much easier to maintain for Rubyists) so anything but a statically typed pseudo-ruby (something like cython) would fail the test.
- nine_k 4y agoYou mean, Crystal?
- npn 4y agoYou can't use Crystal to write ruby extensions, because it has a huge runtime and a big GC. You can call Ruby script in Crystal though. [0] And I think Zig would be easier to maintain compare to Rust because it is a simpler language. Sure there is a lot of breaking changes, but it's not much of trouble for a language that can be read in one afternoon (referring to the single page document). [0]: https://github.com/Anyolite/anyolite https://github.com/Anyolite/anyolite
- ilyt 4y agoAnd Ruby code deployment story got another nightmare to tell! Not only now you require GCC and a bunch of -dev pages just to install the gems, now entirely different language toolset
- aserafini 4y agoIt’s also possible to write Python extensions in Zig: https://github.com/adamserafini/zaml https://github.com/adamserafini/zaml
- 1f60c 4y agoHow do y’all find out how to do things in Zig? The documentation as it currently exists is very brain dumpy (which makes sense, as the language is still young), so it’s hard for me to find exactly what I’m looking for.
- deleted 4y ago[deleted]
- modernerd 4y agoThe Zig Programming Language Discord has a zig-help channel that's pretty responsive if you're ok with Discord. The archive is searchable. https://github.com/ziglang/zig/wiki/Community#discord-english https://github.com/ziglang/zig/wiki/Community#discord-englis.... GitHub's code search beta is a good way to find out how other people are doing things with Zig, if you have access to it. For example: https://cs.github.com/?scopeName=All+repos&scope=&q=http+path%3A*.zig https://cs.github.com/?scopeName=All+repos&scope=&q=http+pat... Some less-known walkthroughs for those new to Zig but comfortable in other languages: - A half-hour to learn Zig: https://gist.github.com/ityonemo/769532c2017ed9143f3571e5ac104e50 https://gist.github.com/ityonemo/769532c2017ed9143f3571e5ac1... - Zig Crash Course: https://ikrima.dev/dev-notes/zig/zig-crash-course/ https://ikrima.dev/dev-notes/zig/zig-crash-course/ You can also see how other people have solved problems you might have: https://github.com/catdevnull/awesome-zig https://github.com/catdevnull/awesome-zig
- 1f60c 4y agoThank you! Note that improvements from GitHub Code Search have been integrated into the main website, which means you can do something like this: https://github.com/search?q=lang%3AZig%20%2F%22https%3F%3A%5C%2F%5C%2F%2F&type=code https://github.com/search?q=lang%3AZig%20%2F%22https%3F%3A%5...
- jeltz 4y agoI read the source code for the standard library.
- jcmoyer 4y ago
- ClawsOnPaws 4y agoSomeone please explain. There are a lot of people who hate on Zig in this thread and say "why not Rust". Then someone comes in and says "Hey, I like C" and gets summarily attacked for that opinion. But it's the same in Rust threads, too. Someone always comes in and says "Ugh, not another Rust thread". And it's been getting worse. It's to the point where I usually don't even bother reading the comments on programming language specific submissions anymore. It's highly predictable and it's quite tiring to read. Everyone who does that is saying "My language is better than yours", and in the same breath criticizing someone else for thinking that, in fact, their language is better. When we all know neither is. It's different tradeoffs, different concepts from different times perhaps, or just different goals. So what if someone wants to use Zig for their native Ruby modules? So what if someone wants to write their Python extension in Rust? So what if someone doesn't mind D's GC? Instead of immediately attacking them for their choice of language, or excusing it by saying "Those people can't be helped", maybe we can listen instead. Saying someone's a lost cause is never nice. And maybe you'll realize that you have a bias too. And that people might disagree with it. We'll get nowhere if we just scoff at everybody. There are good projects made in all kinds of different programming languages, and nobody is lesser for choosing a different one than you'd want them to. Instead of a nice discussion about native ruby modules or addons and a healthy discussion about doing that in Zig, or Rust, or C, or Crystal, or whatever, it's just about the languages themselves again and how people are wrong for using them.
- still_grokking 4y agoSorry, but hard no. Not everything in life is relative. There are objectively better programming languages than others. Like there are objectively better vehicles than others… The blind Rust fanboyism reached crazy levels by now; and Zig isn't a bad language. (It's actually even quite nice for what it is). But there are very valid rational reasons to prefer one over the other. Zig is a new language that repeats 50 year old mistakes. That's a very valid reason to criticize it. No memory safety is a big NO in the year 2022! Over 70% of all software malfunctions—and what's even more important, almost 100% of all severe security issues—are a direct result of missing memory safety. Even this one prominent stubborn and arrogant C dude realized that memory safety is an absolute requirement for a new language. That's saying a lot! Still I recommend Zig to C die-hards. Because it's a slight improvement, and those folks will stick to C anyway otherwise. But anybody who isn't married to C, and is still mentally flexible enough, should look for a better language instead. As there are not much C contenders, especially safe and modern ones, the most valid choice right now in that field is Rust. Love it or hate it. It's like that. (And this does not change even in the light of the fact that Rust is currently overpraised by a large margin, and for a lot of "rewrite it in Rust" projects just using a GC language would be a more sane approach. Also there a niches where C can't be replaced by anything for the time being. But that are quite small niches, and they will likely become even smaller over time).
- bnt 4y agoNoob question: why isn’t Rails a native extension? Would that make it quicker?
- envp 4y agoI’d bet that’s unlikely. A lot of if Rail’s power comes from the meta progamming (convention over configuration, was it?) which would be needlessly hard in extension land. Extensions shine brightest on CPU bound workloads by doing away with a lot of the intermediate Object allocs/frees. The gains tend to not be worth the investment in IO bound settings. This doesn’t mean Rails won’t benefit from extensions.