Live data from Hacker News

Do I not like Ruby anymore? (2024)

sgt.hootr.club

21–30 of 184 posts

Re: Do I not like Ruby anymore? (2024)

#21

This post reminds me of something. During my first Introduction to Programming course at university, I was taught Java. One thing that I found very troubling is that it wasn't easy, or possible in many cases, to change the programming language. Sure, you can write new functions or methods or classes, but I can't change the keyword for an if-statement. I also remember the TA saying "why would you want that?" I caught…

> I also remember the TA saying "why would you want that?" Is a typical response of someone without the background and without the imagination. It may well be, that doing Java-only for too long robs one of both. An alternative response could have been: "What a fascinating idea! How would you apply that? / What would you do with that?" I am happy for you, that you found the exceptions and that your picture of the comp…

So your suggestion to the TA is to ask literally the exact same question but slightly different?

Re: Do I not like Ruby anymore? (2024)

#22

It's the never ending "end"s that bother me about Ruby. class Mess def chaos(x) if x > 0 [1,2,3].each do |i| case i when 1 if i.odd? puts "odd" else puts "even" end when 2 begin puts "trying" rescue puts "failed" end else puts "other" end end else puts "negative" end end end Clear away all those ends and the program logic pops out. Much fresher! class Mess: def chaos(self, x): if x > 0: for i in [1, 2, 3]: match i: c…

[deleted]

Re: Do I not like Ruby anymore? (2024)

#23

This post reminds me of something. During my first Introduction to Programming course at university, I was taught Java. One thing that I found very troubling is that it wasn't easy, or possible in many cases, to change the programming language. Sure, you can write new functions or methods or classes, but I can't change the keyword for an if-statement. I also remember the TA saying "why would you want that?" I caught…

Too much change isn't good though. There's value in consistent basics. I've seen people doing things like: #define BEGIN { #define END } because they liked Pascal, and that way lies madness.

> that way lies madness.

Flashbacks to scala operator PTSD.

No. I don't want to use ++^^%% operator! I am not a number! I'm a man!

Re: Do I not like Ruby anymore? (2024)

#26

It's the never ending "end"s that bother me about Ruby. class Mess def chaos(x) if x > 0 [1,2,3].each do |i| case i when 1 if i.odd? puts "odd" else puts "even" end when 2 begin puts "trying" rescue puts "failed" end else puts "other" end end else puts "negative" end end end Clear away all those ends and the program logic pops out. Much fresher! class Mess: def chaos(self, x): if x > 0: for i in [1, 2, 3]: match i: c…

The indent in your Ruby code is a bit weird. It should be like this

    class Mess
      def chaos(x)
        if x > 0
          [1, 2, 3].each do |i|
            case i
            when 1
              if i.odd?
                puts "odd"
              else
                puts "even"
              end
            when 2
              begin
                puts "trying"
              rescue
                puts "failed"
              end
            else
              puts "other"
            end
          end
        else
          puts "negative"
        end
      end
    end

I would have done it this way instead

    class Mess
      def chaos(x)
        if x > 0
          [1, 2, 3].each do |i|
            case i
            when 1
              puts i.odd? ? "odd" : "even"
            when 2
              puts "trying"
            else
              puts "other"
            end
          end
        else
          puts "negative"
        end
      end
    end
Or if you allow me to create a separate private method

    class Mess
      def chaos(x)
        return puts "negative" unless x > 0
    
        [1, 2, 3].each { |i| handle_item(i) }
      end

      private
      def handle_item(i)
        case i
        when 1 then puts(i.odd? ? "odd" : "even")
        when 2 then puts "trying"
        else        puts "other"
        end
      end
    end

Re: Do I not like Ruby anymore? (2024)

#27
post #11

Back when autocompletion and stuff were only available in Visual Studio/Xcode/Other bug IDEs, I was forced to use Ruby and fell in love with it. It didn't matter what I used as my editor was Sublime. But when VSCode came and language features became democratized, I never touched a type-less language again. Why should someone opt for a language with absolutely no features where one can have autocompletion, typecheckin…

This was always true, to be honest. Statically typed languages have always been better. Free IDEs such as Eclipse have been available for a long time. Good JVM languages such as Scala have been available for a long time.

If only the Ruby ecosystem had adopted Scala instead of Ruby, with cutesy books and eccentric underscored personalities, history might have been different.

Re: Do I not like Ruby anymore? (2024)

#28

I was a full-time Rubyist for a long time. I started the UK's first dedicated Ruby on Rails consultancy in 2006 before Rails was even v1.0 (IIRC the first apps I shipped back then were 0.8.6). I stuck around through the hype chain, and then started to help one employer break up a RoR monolith into micro services and adopt Java and Go (this was a mistake - we should have crafted the monolith better). I've built 4 star…

I've been on a similar journey. I was deep into rails early in my career. Then I moved on, especially liking typescript. I thought I wouldn't go back. But you don't always get the choice, a great job came up and it was a rails app. I found joy in it again - and I'm still there nearly 10 years on. Ruby feels like how OOP should be, it's so very easy to implement patterns that other languages make verbose and horrible. I'm guilty of a lot of metaprogramming, hope you forgive me, I am over 40. I think it can be an undervalued super power of the language: something isn't working or you need deeper insight, just break into the innards of any library you're using and insert logging and/or your own code.

Anyway, that said, for new personal projects I like typescript and rust. But recently I needed to stick an admin interface on such a project and rails shines there, you can get something good and secure stood up with less code and faff than anything else. In today's world of LLMs that is helpful too, rails is concise and old and has lots of open source projects to pull from, so AI breezes through it.

Re: Do I not like Ruby anymore? (2024)

#29
post #20

Earlier quoted context omitted.

Doesn't Ruby essentially already have namespaces, in terms of having modules? If one has proper modules, why would one ever need an alternative, weaker, concept for referring to things?

To make sure code loaded from gems doesn’t shadow the namespace of the application.

Right. Today Ruby has essentially a global namespace, where every defined module/class/const is put in the same "global dumping ground" and can override/"monkey patch" each other.

Ruby 3.5 will introduce a new language keyword "namespace" that scopes behavior to that namespace.

  class Foo
    def foo; puts "foo"; end
  end

  namespace Bar
    class Foo
      def foo; puts "bar"; end
    end

    Foo.new.foo #=> "bar"
  end

  Foo.new.foo #=> "foo"
Fun times.

This is intended for isolated code loading similar to "modules" in Python or ES6, but I am worried it will be abused badly. I'm also unsure whether they will add a "use Namespace" construct...

See here: https://bugs.ruby-lang.org/issues/21311

Re: Do I not like Ruby anymore? (2024)

#30
I'm a python developer, and a big fan of the features with gradual typing etc. This article really highlights for me though, how python has very much changed from the language it was even 5 years ago.

Initially, the celebrated feature of python was that it allowed easy and fast development for newcomers. There was a joke a long the lines, "I learned python, it was a great weekend".

As much as I like python's type system (and wouldn't want to see them ever go way!), part of me wonders if moving into a world where hello-world can look like this, is a world where python is no longer the "lean in a weekend" language:

     from typing import Annotated
     import typer
     
     app = typer.Typer()
     
     @app.command()
     def main(
          name: Annotated[str, typer.Option("--name", "-n")],
     ) -> None:
         """Prints out 'HELLO {name}!!' (name upper cased) to the console"""
         print(f"HELLO {name:upper}!!")
     
     if __name__ == "__name__":
         app()
(obviously the example is silly, and I know this is a lot more than you need to do, hopefully you get my point though!)
Post reply on HN