The python version seems buggy as fuck. Depending on which year you run it it's off by 1-3 days
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
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.
I did look up the help
for that function to make this meme but I must have missed that option. in my defense I've only been using Python for like 10 years
Never worked on Ruby, so I definitely cannot judge it, but that syntax looks so uncomfortable…
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.
Looks like one is defined as years and one as days. 10 years does not necessarily equal 365 times 10.
In fact, it would never equal 365 * 10 days.
And the best part is the Ruby way accounts for leap years.
Well, 365 * 10
certainly doesn't ;-)
I prefer the one on the left because it's evident it doesn't account for leap days, while I'd be questioning whether the one on the right does.
from datetime import datetime
from dateutil.relativedelta import relativedelta
print(datetime.now() + relativedelta(years=10)) # 2035-08-24 12:02:49.795177
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
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.
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.
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.
Yeah, you could very well argue that JS and others that use it for weird interpolated strings are the weird ones here.
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
"365*10"????
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.
How is this implemented? Is it just functions and the language assumes the first parameter is autofilled with variable.function syntax?
Ruby is object-oriented, modelled after Smalltalk mostly. So
irb(main):001:0> 10.class
=> Integer
So you'll just have implement the method "years" on the Integer (or something more generic like Numeric) class and then "ago" on whatever class the years method returned.
You might imagine that you can do something like 10.years().ago() in python but the parser prevents you:
>>> 10.years
File "<python-input-0>", line 1
10.years
^
SyntaxError: invalid decimal literal
Doesn't seem like it would have to prevent it, back in ruby:
irb(main):001:0> 10.0.class
=> Float
Ruby is a pretty cute language in my opinion, and I find it sad that python kinda drove over it.
That's just syntax.
>>> 10 .yearsTraceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'int' object has no attribute 'years'
Yeah, I figured there would be a workaround. Also
>>> (10).years()
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
(10).years()
^^^^^^^^^^
AttributeError: 'int' object has no attribute 'years'
But the other thing is also: can you add methods to the int class so that they're available everywhere? I suspect that you cannot in python, at least without significant hackery. And I also suspect that it's probably something they decided to prevent knowingly.