9 ms·
Ruby's exceptional creatures
- crystaln 3y ago[flagged]
- thih9 3y agoBoth have their benefits and drawbacks.
- postmodern_mod3 3y agoEven Haskell has exceptions. Even with Strong Typing and Functional Programming, things can go wrong, like network issues or your hard drive fills up.
- deleted 3y ago[deleted]
- 2024throwaway 3y ago[flagged]
- BalinKing 3y agoW.r.t. the edit, from the HN guidelines: > Please don't comment about the voting on comments. It never does any good, and it makes boring reading.
- verelo 3y agoAs someone with about 15 years of php under his belt, and now writing my second ruby app…i don’t know I’ll ever go back. It’s just so easy…
- 2024throwaway 3y agoIt’s easy indeed. Easy to make mistakes you don’t know were there until they bite you firmly in the arse. Again I’m not interested in how quickly you can create an app. I’m interested in your ability to maintain very complex business logic over the course of years. Working at a Ruby shop now, I can say with confidence I will never touch it again with however long of a pole I can find.
- loktarogar 3y ago> I’m interested in your ability to maintain very complex business logic over the course of years. I think this is a bit over the top. You can maintain complex business logic in any language (any language!) for decades with discipline and good software development processes. Ruby lets you do a lot that could bite you, but it's people who write code.
- RangerScience 3y ago> why If you have incorrect code and are happy programming, you fix your code. If you have correct code, but are unhappy programming, you do not fix your code. There is no correct code and Ruby prioritizes your happiness, so you get fixed code and happy programmers, instead of permanently broken code and unhappy programmers.
- nf3 3y agoReading your comment one would think Ruby is the only programming language with exceptions. In fact, lots of programming languages have them, even PHP. https://www.php.net/manual/en/language.exceptions.php https://www.php.net/manual/en/language.exceptions.php
- busterarm 3y agoIf I had a dollar for every time I forgot in PHP which Array methods are 'haystack, needle' and which are 'needle, haystack'.
- TobyTheDog123 3y agoExceptions are not the issue, Ruby's inherent "cleverness" is. Whatever problems the original commenter has with exceptions likely stems from this.
- pmontra 3y agoI agree that too much cleverness is unclever. Just don't use clever features and enjoy the rest of the language. Examples: In some other comments somebody wrote about method_missing and ActiveRecord callbacks. Days ago we had a post about a state machine gem. Leave method_missing to the inner workings of gems. Do not use it in your code. Even in gems, hide them well. Rails used to have auto-generated find_by_field1_and_field2 methods, by method_missing if I remember well. They eventually moved to where(field1: value1, field2: value2) and we are fine with that. ActiveRecord before and after filters are just callbacks like many libraries have, in any language. They need discipline because of the obvious problems we can run into if we add a ton of code to the callback system, possibly with side effects and multiple definitions of the same callbacks in classes derived from a common model. That's actually a very bad code smell (and a broken architecture?) and something that we could be tempted to do but we learn not to do. I use them very sparingly. The whole validation system is a particular case of before save callbacks. I think that every ORM for every language has got a validation system. Another case of callbacks are the ones for the state changes of finite state machines. We can define them with function pointers in C structs or with symbol names in Ruby, they are the same thing. The triggers for state changes: same thing. If I can choose I go with the more explicit alternative because... Finally I confess that I lose time when reading some new code bases to understand if some object.something is an attribute, a method, a state machine callback or something else auto-generated by some other gem. I think that LSP servers have a very bad time following those methods and probably none of them do. Maybe heuristic in IDEs can do something about it. If I feel that I would be in trouble there, I add a short comment explaining the origin of the method: "this is from gem XYZ", then the docs will explain how and why to the next developers. Maybe they will thank me.
- timeimp 3y agoI'm sure Shopify would like to have a word
- blast 3y agoStripe too
- deleted 3y ago[deleted]
- stevebmark 3y agoIt's painful to see method_missing called out as a first class solution in the first creature https://www.exceptionalcreatures.com/bestiary/NoMethodError.html#6-a-method-to-find-missing-methods https://www.exceptionalcreatures.com/bestiary/NoMethodError.... . "Practical Ruby" has three chapters dedicated to method_missing. "define_method" is more common these days and also painful to see. Ruby gets a lot of criticism for embracing magic and indirection ("Ruby, the bad parts of Perl"). It has some good parts (no function colors, for example), but the ecosystem is the biggest problem by promoting magic. method_missing is not a good part of Ruby, it's a very bad part that you should only use if you know it's bad _and_ you know you still have to use it. I wish all tutorials would say this. "You can do this with Ruby, but don't, because your coworkers debugging an outage for an hour will hate you once they find out the bug is caused by method_missing".
- p_l 3y agomethod_missing is a tiny offense compared to what was getting popular at one point - creating classes by forking metaclass and injecting methods into... without knowing you're doing so (something IIRC got lost between people there...) Result was objects that shared no structure, no field
- pantulis 3y agoDo you mean the class << self pattern?
- matheusmoreira 3y agoThat's what I thought as well. If someone's opening metaclasses to define singleton methods they probably know all about the Ruby object model. I don't see how it could be done "without knowing you're doing so".
- p_l 3y agoThe people who did it first did understand the meta model. Unfortunately some people started following without full understanding. I wasn't at forefront of things back then, so I only noticed when the people who did know better started to writing about abuse of this technique.
- typeofnandev 3y agoThis is so ruby
- TobyTheDog123 3y ago[flagged]
- crazydoggers 3y ago[flagged]
- nmjohn 3y ago> And please don’t reply. Respectfully, if you don't want discussion, why comment in the first place? Commenting telling someone not to comment and then ending in telling them not to bother replying is confusing behavior to me for a discussion forum.
- TobyTheDog123 3y ago[flagged]
- pvg 3y agoLanguage wars are one of the basic things to avoid starting and perpetuating in HN threads. As are meta comments about voting.
- deleted 3y ago[deleted]
- crazydoggers 3y agoAside from being cute, and maybe harking back to why’s guide; I like how this feels like it aids in understanding. Each illustration provides character that helps aid in memorizing or creating a mental landscape of the exceptions. Theres probably a lot of documentation that could be aided by illustrations like this along the lines of analogy and metaphor. Aside from making the process of reading documentation more fun, it probably helps differentiate long and complex documentation that otherwise might blur together.
- oh_sigh 3y agoI don't appreciate how it seems like an elaborate ad though: Every error has a link to the paid service they're selling , with the error/exception "Enemies" list as their product
- Spone 3y agoOn the contrary, I quite like how it's a very elaborate and useful ad. The link to the paid service is very discreet and the website provides real and free educational value even if you don't use their service.
- darkwater 3y agoWhy so? This is in my book the best form of advertising. It provides anyway something useful for the interested reader, while exposing the (alleged, at least) usefulness of their services. Much better this that a banner or a pop-up in some random website that tracked you down as a Ruby developer.
- Lutger 3y agoI don't appreciate it either, maybe I'm a bit dull. I feel tricked as it is unclear from a quick glance what I am looking at is really an advertisement, not a tutorial or some kind of reference. And as an advertisement, it may or may not be useful. At least the incentives are clearly there to present information in a way that benefits their funnel even if it doesn't benefit me as a developer. Even if its not a straight up lie, they will obviously not mention an alternative solution to their product and could very well be quite incomplete. For a reference, I want something I can trust to give information relevant to my purpose, something that is complete and valid. Not a playful hidden advertisement, funneling me into a single paid solution. Maybe this is why I prefer python, even after working with rails for many years. As I said, I might be a bit dull.
- booleandilemma 3y agoAs a non-ruby developer I see things like this and get jealous of ruby developers.
- herbst 3y agoI was developing mostly PHP, some bash, some Java and kinda liked ruby but could only partially feel it. Until I read "why's (poignant) Guide to Ruby", from start to end, I completely fell in love with programming. Everything before was just getting to this point. The documentation and community is what has drawn me into Ruby. The language and now very major ecosystem is why I still stay :) Hello Ruby by Linda Luikas is one of the sweetest 'programming books' I've ever seen.
- revskill 3y agoRuby is a good gateway to programming, better than C, C++, Java, Python,...
- p-e-w 3y agoBetter than Python? 15 years ago I would have agreed. Today, Python is a "gateway" to programming that is also the real thing. It's like one of those old languages designed for beginners to learn coding... and then you can continue to use the same language for your entire professional career as a software engineer, to build just about any production-ready application. Ruby is a beautiful language, but unless you are going to be working with Rails, it's not a very practical language to build something in. And I don't think telling a beginner "just learn Ruby for now, but once you're actually ready to write your first useful program, you're probably going to have to learn another language" is very motivating.
- sethherr 3y agoI love Ruby and write it professionally; unfortunately I agree - learning Python is more practical currently.
- realusername 3y agoThe biggest difference between both is mainly their machine learning story but if you don't intend to go in it (this is a very specific career choice), I'd say both are equally good options. I'd say both are pretty bad at performance critical tasks or UI stuff where usually you would use neither of those.
- newaccount74 3y agoPython is so much bigger than Ruby. It's not just machine learning. There's also numpy and Jupyter for the scientific community, which are huge. There's arcade for making 2D games. There's Micropython for microcontrollers. There are async database drivers and web frameworks. There's interop for many other programming languages, and it's really easy to make a distributable package with Python runtime included. And that's just what I can recall of the top of my head as someone whose primary language is not Python.
- iammiles 3y agoThis is absolutely delightful! The Ruby community seems to punch above its weight when it comes to producing fun, joyful documentation.
- cHaOs667 3y agoDamn, this page reminds me how much I miss working with Ruby every day :/
- wscourge 3y agoThis is excellent. I proudly wear Honeybadger's swag exactly because of things like this.
- stympy 3y agoYou just made my day! Thanks!
- deleted 3y ago[deleted]
- CatchSwitch 3y agoI don't know what it is about Ruby that turns every HN thread that mentions it into a flame war about how it's not the perfect language. People don't do this with other languages. What gives?
- Joker_vD 3y agoUm, they do. Have you been in any of the Rust threads?
- UncleMeat 3y agoI think python is the only language where the inevitable flamewar isn't about the language itself (it is instead about static vs dynamic typing). Java might be in this list too (usually the war is about OOP in general, but there's plenty of criticism levied at Java itself). Discussions about C devolve into a religious war about simplicity and portability vs safety and an inadequate standard library. Discussions about C++ devolve into a religious war about memory safety, bloat, developer competency, UB, and more. Discussions about Haskell devolve into a religious war about powerful type systems and language constructs vs performance concerns, development complexity, and "endofunctors, lol." Discussions about JS devolve into a religious war about npm, web dev in general, "== vs === lol" and more. Discussions about Rust... oh boy. In my experience, most discussions of specific components of languages inevitably spill into these broad and neverending religious wars.
- fredrikholm 3y agoOh! I want to play too! Discussions about Go devolve into a religious war about simplicity and portability vs "the creators of the language said its only for dum dums and it shows", "it took them 10+ years to get generics", and more. Discussion about Zig devolve into a religious war about living in a universe where C exists and not wanting to write it versus "there's too many C-likes", "why isn't this Rust", and more. Discussions about Erlang devolve into a religious war about standing up fault tolerant and scalable distributed systems, Joe was the nicest guy ever vs "you can do that in X all you have to do is Y". Discussions about Elixir devolve into a religious war about Erlang and Ruby's love child, José Valim is the nicest guy ever versus "you can do that in X all you have to do is Y", "but what about types" and more. Discussions about Clojure devolve into a religious war about people writing impressive programs in their spare time, "I actually get paid to write Clojure" versus "does anyone actually get paid to write Clojure". Discussions about Elm devolve into a religious war about type safety and staying sane versus Richard Feldman lost his temper once, the 0.19 release and "everyone has Stockholm syndrome over there". Discussions about V devolve into a religious war about "this is not a scam" versus "this is a scam". Discussions about Nim generally don't, or the language creator is going off on D-forums / Twitter / X again.
- 03b8 3y agoRuby has a Cinematic Universe now? Nice.