• Omega
    link
    fedilink
    1220 days ago

    Using ruby felt weird, it felt like it shouldn’t work but it does.

  • @etchinghillside@reddthat.com
    link
    fedilink
    23
    edit-2
    20 days ago

    LLM is saying this is a feature of Rails and not particularly Ruby.

    I was surprised Python didn’t have a years parameter but learned about

    relativedelta(years=10)

    • Noxy
      link
      fedilink
      English
      119 days ago

      LLM is saying…

      Stop. Nothing at all past those three words is worth a damn.

        • Noxy
          link
          fedilink
          English
          118 days ago

          You didn’t seem to be ashamed of admitting to asking an LLM a question as if it was helpful, wise, or respectable for you to have done. You should be.

          • @etchinghillside@reddthat.com
            link
            fedilink
            -118 days ago

            This is a poor perspective to have on things towards a stranger on the internet. I hope you’re just having a bad day and that things get better.

      • mesa
        link
        fedilink
        English
        220 days ago

        That’s what I end up seeing for most ruby only scripts. It works!

    • mesa
      link
      fedilink
      English
      3020 days ago

      Yeah its a rails only thing. Rubys biggest issue is its much too intelligent for its own good. Its implicit rather than pythons explicit. Most of the time. That and it’s hard to find out where Ruby starts and rails ends.

      That being said I made a ton of good money on rails back about 15 or so years ago. Still excellent for starting out.

      • @tyler@programming.dev
        link
        fedilink
        118 days ago

        Ruby’s biggest issue is rails. Ruby is such a beautiful and highly functional language and yet everyone’s experience with it is rails’ horrific metaprogramming magic. I’ve had numerous people tell me they hate Ruby, and yet when I dig deeper I find out that they don’t actually understand where Ruby ends and rails starts and all of their problems lies on rails side. The majority of people I’ve shown that have come to actually like Ruby where they hated it before.

    • @immutable@lemmy.zip
      link
      fedilink
      2
      edit-2
      20 days ago

      Rails, ActiveSupport I believe, adds this to integers.

      But I think one of the interesting things about it is the open nature of classes in ruby.

      The thing that makes it possible is that you can open classes in user space and just add stuff to them. It’s a neat feature that few languages have.

      The feature, like most features, has pros and cons. On the pro side it makes making DSLs and helpers like this pretty trivial. You can make really expressive ideas and apis because you can change how things you didn’t write work.

      On the con side, it’s harder to discover and the methods of an object being the result of runtime mixins can make things hard to reason about.

      Having worked in both python and ruby and now elixir for the past couple of years, it’s interesting to see how the languages are similar and different.

      There’s an elegant beauty to ruby’s everything is an object and all method calls are messages concept. Python has always struck me as less elegant but the upside is that it can model different ideas in different ways and doesn’t have to try to make them all look like the one central idea.

      Even though I find the model behind ruby more pleasing to think about, I tend to enjoy python more due to it being more explicit and easier to reason about. Although that’s pretty subjective.

      In any case I think the language feature of open classes is a fascinating one and one of the really different parts of ruby that really distinguishes it from python, for better or worse.

  • @friend_of_satan@lemmy.world
    link
    fedilink
    English
    17
    edit-2
    20 days ago

    This implies that integers in ROR are complex objects with properties that would be unhelpful in the majority of scenarios. Is that right?

    • @myotheraccount@lemmy.world
      link
      fedilink
      1620 days ago

      Integers are just integers in ruby, with no structure backing them. They behave like objects, but only in some respects. You can call methods on them, but you can’t extend individual numbers with properties for example (which would require them to have structure).

  • @Unpigged@lemmy.dbzer0.com
    link
    fedilink
    519 days ago

    I miss Ruby DSLs so much. Python is bland. It’s on purpose, I know and even appreciate it.

    Yet I feel like Ruby syntax magic compared to Python blandness is like comparing a steaming plate of beautiful aromatic curry to plain rice.

  • @_stranger_@lemmy.world
    link
    fedilink
    34
    edit-2
    20 days ago

    Ok, everyone who’s ever had to use datetime hates it, but not because it’s insufficient, but because international date/time is such a nightmare that the library must be complicated enough to support all the edge cases I’m convinced that library has a function for traveling trough time.

    For years I’ve wrapped datetime with custom functions that do exactly and only what I want to mitigate its all-plumbing-zero-porcelain approach to the problem.

      • Alaknár
        link
        fedilink
        English
        119 days ago

        This is exactly why I love PowerShell.

        Need the [DateTime] object from 10 years ago? No biggie, just chuck (Get-Date).AddYears(-10) down your console.

        Need it in a specific timezone? That one’s trickier, but since PowerShell can do .Net, run this:

        $TargetDateTime = (Get-Date).AddYears(-10)
        $TargetTimeZone = "India Standard Time"
        $tz = [TimeZoneInfo]::FindSystemTimeZoneById($TargetTimeZone)
        $utcOffset = $tz.GetUtcOffset($TargetDateTime)
        [DateTimeOffset]::new($TargetDateTime.Ticks, $utcOffset)
        

        And you get a DateTimeOffset object, which is this beauty:

        DateTime           : 25/08/2015 23:15:14
        UtcDateTime        : 25/08/2015 17:45:14
        LocalDateTime      : 25/08/2015 19:45:14
        Date               : 25/08/2015 00:00:00
        Day                : 25
        DayOfWeek          : Tuesday
        DayOfYear          : 237
        Hour               : 23
        Millisecond        : 421
        Microsecond        : 428
        Nanosecond         : 600
        Minute             : 15
        Month              : 8
        Offset             : 05:30:00
        TotalOffsetMinutes : 330
        Second             : 14
        Ticks              : 635761413144214286
        UtcTicks           : 635761215144214286
        TimeOfDay          : 23:15:14.4214286
        Year               : 2015
        

        DateTime is the time in your target timezone, UtcDateTime is, well, the UTC time, and LocalDateTime is the time on host you ran the commands on.

  • Victor
    link
    fedilink
    9
    edit-2
    20 days ago

    I’m gonna be honest, I never was drawn to python. I’ve been a professional developer for about a decade, and I’ve written all of one (1) python programs that I can remember (for my own personal use, mind).

    • @addie@feddit.uk
      link
      fedilink
      1320 days ago

      What you can achieve in a couple of pages of Python can be pretty spectacular. It’s also mostly very easy-to-read, with the possible exception of class inheritance, which is confusing mess.

      If you need to write more than a couple of pages, then its lack of types becomes a hindrance to me - doing refactors when functions can take basically any arguments is quite painful, for instance. Not requiring any particular structure is great, up until you start to struggle with lack of structure.

      Ideal programming language for when you’re wanting to do something that would be a bit too unwieldy for a shell script. It also makes network requests and json parsing very straightforward, so it’s great for interacting with REST APIs and writing simple microservices. Fast to write and runs quite quickly, so a good choice for Advent Of Code-like tasks. Would probably choose a different language for larger projects or when working in a team, though.

      • Victor
        link
        fedilink
        320 days ago

        I like Fish Shell better than python, not gonna lie. Easier to read and write. Especially if you already live in the terminal.

  • @ArcaneSlime@lemmy.dbzer0.com
    link
    fedilink
    2
    edit-2
    18 days ago

    There’s two of these threads?! Well ok here’s the same comment.

    10.years.ago
    On.a.cold.dark.night
    There.was.someone.killed
    'Neath.the.town.hall.lights
    There.were.few.at.the.scene
    Though.they.all.agreed
    That.the.slayer.who.ran
    Looked.a.lot.like.me
    
  • @bleistift2@sopuli.xyz
    link
    fedilink
    English
    1820 days ago

    Fuck that. I once used a constraint solver in python where you could += a constraint to a problem. This is completely un-discoverable. In any sane language you can use IntelliSense to find that you can problem.add(constraint) and be done with it without ever touching a manual. Overloaded operators are cool, but a menace.

    And while I’m ranting: Angular’s new addRouting(), withThingA(), withThingB() is complete horseshit, too. The old way of doing addRouter({ and letting the IDE tell you what you could to with the router was so much clearer!

    • @marcos@lemmy.world
      link
      fedilink
      020 days ago

      Any good inline help would run dir into your variable and discover it overloads that operator. It’s a fault of your tools.

    • @_stranger_@lemmy.world
      link
      fedilink
      3
      edit-2
      20 days ago

      I’ll take overloaded operators over overloaded functions any day of the week, and I also hate overloaded operators.

      Python’s optional typing has come a very long way in the past few years, you might be able to mitigate this with some creative application of typing.

      Edit: I read your post closer, I’m not sure typing would help with the overloaded operator issue and now I have something fun to try out later 😁