top 50 comments

sorted by: hot top controversial new old
[–] 45 points 1 year ago (5 children)

Never worked on Ruby, so I definitely cannot judge it, but that syntax looks so uncomfortable…

  • source
  • hideshow 5 child comments
  • [–] 21 points 1 year ago (4 children)

    It can be nice to read but try debugging something like this is a horrible experience.

    I had 5 years of ruby on rails experience before jobs decided on other Lang's. Its still not terrible persay but it hurts when you have multiple of these "smart" objects doing really silly things and debugging it all.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 32 points 1 year ago (9 children)

    And the best part is the Ruby way accounts for leap years.

  • source
  • hideshow 9 child comments
  • [–] 26 points 1 year ago (14 children)

    The python version seems buggy as fuck. Depending on which year you run it it's off by 1-3 days

  • source
  • hideshow 14 child comments
  • [–] 8 points 1 year ago (3 children)

    Python does have a year option that they are not using. Depending on the application I would use 365 for a year to get a consistent number of days.

  • source
  • parent
  • hideshow 3 child comments
  • load more comments (2 replies)
  • load more comments (10 replies)
    [–] 23 points 1 year ago (1 child)

    Looks like one is defined as years and one as days. 10 years does not necessarily equal 365 times 10.

  • source
  • hideshow 1 child comment
  • [–] 15 points 1 year ago* (last edited 1 year ago) (7 children)

    Edit:

    To clarify, I looked at existing online ruby code and gave it a small test for readability. It may be outdated, use uncommon syntax, bad practice or be full of individual developer quirks - I wouldn't know. I did that because I wanted to highlight some weaknesses of the language design that turned me away from ruby years ago. https://en.wikipedia.org/wiki/Principle_of_least_astonishment


    Yes, very nice. But here comes the ugly;

    [1,2,3].map(&:to_s)
    

    oh ok, a bit hieroglyphic, but I can figure it out, seems like '&' means element and ':' means what I do with it.

    files = `ls -1`
    

    Aaah so a backtick is for strings? WRONG!!! IT EXECUTES THE FUCKING COMMAND!!!

    ARGF.each { |line| puts line if /BEGIN/ .. /END/ }
    

    What the hell is | and / ? Oh but I guess .. is a range like in other languages, but what would be that range??? WRONG! I!!T'S A FLIP FLOP!!!

    %w{a b c}     # array of strings
    %i[foo bar]   # array of symbols
    %r{https?://\w+}  # regex
    %x(ls -1)     # run shell command
    

    Ah, just memorize which letter to use by heart and that % is for type and that [ = { sometimes. But { unequal to { other times.

    if line =~ /ERROR/
      warn $~.post_match
    end
    

    =~ neat!

    $~ dafuq???

    At this point I feel like ruby devs are just trolling us. There are always multiple ways to do the same thing. Every example from above also has a tidy and readable way to do it. But the alternative ways become progressively more shorthand, unreadable and unintuitive.

  • source
  • hideshow 7 child comments
  • [–] 21 points 1 year ago* (4 children)

    Aaah so a backtick is for strings? WRONG!!! IT EXECUTES THE FUCKING COMMAND!!!

    To be fair this is what they do in Perl and shell scripts (and in PHP too), so it's not unexpected behavior in that world.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 8 points 1 year ago* (last edited 1 year ago)

    I'm way happier debugging "200 char wide class name + 50 line of boilerplate" code written in java that verbosely and expressively does the same thing compared to deciphering single symbol hieroglyphs in shell esque scripts where I have to pay attention which way the ticks are pointing.

  • source
  • parent
  • [–] 4 points 1 year ago (1 child)

    Does Ruby require the use of [] and {} there? Because those %w/%i/etc things look like custom quoting operators and at least in Perl you can use any delimiter you want: qw(a b c) is a list of strings, but so are qw+a b c+ and qw;a b c;.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 13 points 1 year ago (4 children)

    crystal is another language that's apparently quite similar to ruby, with the difference of being compiled and staticly type-checked, and I just love it's ruby like syntax. I believe the equivalent code for this in crystal would be Time.local - 10.years

  • source
  • hideshow 4 child comments
  • load more comments (4 replies)
    [–] 12 points 1 year ago (1 child)
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    
    print(datetime.now() + relativedelta(years=10))  # 2035-08-24 12:02:49.795177
    
  • source
  • hideshow 1 child comment
  • load more comments (1 reply)
    [–] 9 points 1 year ago (2 children)
    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
    
  • source
  • hideshow 2 child comments
  • load more comments (2 replies)
    [–] 8 points 1 year ago (7 children)

    Ruby is awesome. Finding out that everything is an object, and because of that you can do things like in your example (10.whatever), is hilarious coming from other languages.

  • source
  • hideshow 7 child comments
  • [–] 5 points 1 year ago (5 children)

    By the way, it isn't actually necessary for everything to be an object to make this work. The language just has to define 10.whatever() to be syntactic sugar for whatever(10). Some languages, like Python and Rust, have an explicit self parameter on their methods to help illustrate this.

    But yeah, a bunch of languages decided to special-case their objects instead, for whatever reason.

  • source
  • parent
  • hideshow 5 child comments
  • this is very true but i gotta defend my object-oriented languages here (real object-oriented, not c++-style object-oriented). there's a lot of way cooler stuff you can do with ruby or groovy or smalltalk that you just can't do with rust, for example. objects aren't special cases, the entire system is supposed to be implementable in itself. obviously the machine code itself can't be objects but the good languages do their best to mask that.

  • source
  • parent
  • load more comments (1 reply)
    [–] 4 points 1 year ago (3 children)

    Does that work? Might be enough to convert me

  • source
  • hideshow 3 child comments
  • [–] 12 points 1 year ago* (1 child)

    I was on a project a while back that used Ruby, and what I concluded was that cute things like that look good at first glance if you're skim-reading some already-correct code, but are pretty much a net wash in terms of writing or debugging code.

    It's not unusual for people to think that code would be better if it scanned like regular English, but the problem is that English is woefully imprecise and doesn't always correlate to what kind of operations get run by the code, and so you still end up having to learn all that syntax and mentally process it like any other programming language anyway, but now you've also got a bunch of false friends tricking you into thinking they do one thing but actually they do another.

    (also, the bulk of the text in that python example is the import statement, which is like... ok so what, it's not like Ruby doesn't have its own dependency hell problems)

  • source
  • parent
  • hideshow 1 child comment
  • [–] [S] 6 points 1 year ago

    it works in Ruby on Rails but not in bare-naked Ruby, if that gives you a hint of how the language's architecture makes things easy for you and also might stab you in the back one day.

  • source
  • parent
  • load more comments
    view more: next ›