4 ms·
Well I never: today I learned about break expressions: nine = while 1 do break 9 end puts nine #=> “nine” I love Ruby. I am not sure how I feel about
by gorgoiler 5y ago
Well I never: today I learned about break expressions:
nine = while 1 do break 9 end
puts nine #=> “nine”
I love Ruby. I am not sure how I feel about this. It looks useful for the odd thing or two, maybe.
- tokamak-teapot 5y agoDoes nine really end up containing a string like that? I would have expected it to be the number 9.
- bornelsewhere 5y agoThe example is syntactically incorrect Crystal. Should be nine = while 1; break 9; end puts nine And yes, it prints "9".
- diragon 5y agoWhat is going on with the upvotes here? The incorrect comment by OP is upvoted, while this correct comment is downvoted.
- kawsper 5y agoirb(main):001:0> nine = while 1 do break 9 end => 9 irb(main):002:0> nine.class => Integer irb(main):003:0> puts nine 9 => nil puts might be calling .to_s on the variable, which is why you see a string, but the loop does return an integer.
- quesera 5y agoAnd just to be clear, to_s will return a string, but it will definitely not do the craziness of converting an integer into an English representation of the number! 9.to_s => "9"
- gorgoiler 5y agoSorry. Yes, you are correct. I over-edited my comment to fit a narrow screen, breaking the example.
- unixhero 5y agoRuby makes me want to become a programmer.
- TranquilMarmot 5y agoMy dislike for Ruby was one of the main reasons I left my last job... but I think that opinion will probably get an angry mob after me here on Hacker News haha. And honestly, it could have just been the way they were writing Ruby there that drove me to leave, but the language has left a sour taste in my mouth.
- pankajdoharey 5y agoWhat do you dislike about ruby and what do you prefer against it?
- TranquilMarmot 5y agoThere was too much "magic" going on. I could never figure out where variables or functions were coming from. Sometimes I would have to sit down with our local Ruby guru (a principal engineer who has been working with Ruby for years and years) and it would take us the better part of an afternoon to track down what a function call was doing. Again, that all could have been a side effect of horribly written Rails code where I was working. The Ruby guru I mention above would often lament about how bad our Ruby codebase was. To me, it just showed "wow it's really possible to write code this bad in this language" and left a sour taste in my mouth. I usually prefer TypeScript for scripting things. Being able to run it via node and in the browser is a killer feature and I have many small libraries I've written that I reuse in a lot of personal projects. Sometime I use Python but I'm not a huge fan of Python's version and dependency management. For anything that's not destined for the browser that require speed or a larger codebase (i.e. backend services) I don't think you can go wrong with the JVM. I prefer just plain Java, but also have used Scala and Kotlin extensively and they're all great for speed, collaboration, readability, testability, and have robust ecosystems.