- cross-posted to:
- programmer_humor@programming.dev
- cross-posted to:
- programmer_humor@programming.dev
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
The python version seems buggy as fuck. Depending on which year you run it it’s off by 1-3 days
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.
That sounds serious, can you give some example values we can test?
Sure, here’s one example for each case:
1 day off: 3650 days before 1907-01-01 is 1897-01-02
2 days off: 3650 days before 2027-01-01 is 2017-01-03
3 days off: 3650 days before 2025-01-01 is 2015-01-04
29 February 2028, 29 February 2032, 29 February 2036…
look I’m not trying to be a dick or anything, but do you not know about leap years and which years they are?
Yes, and I have no idea…
Leap years are each fourth year, except each hundredth year, except each thousandth year.
1896 leap year
1900 not leap year
1904 leap year
…
1996 leap year
2000 leap year
2004 leap year
…
2096 leap year
2100 not leap year
2104 leap yearThen you just arrange the 10 year window in different positions to overlap 1 to 3 leap years to reveal the three outcomes of the bug.
- / - - - / - - - /
- - / - - - / - - -
- - 0 - - - / - - -- is a normal year, / is a leap year, 0 is an exceptional non-leap year.
Looks like one is defined as years and one as days. 10 years does not necessarily equal 365 times 10.
from datetime import datetime from dateutil.relativedelta import relativedelta print(datetime.now() + relativedelta(years=10)) # 2035-08-24 12:02:49.795177
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.
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 areqw+a b c+
andqw;a b c;
.
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.
I programm in Ruby since 2006.
In my opinion it has some of the best debugging tools available.
What was the horrible part you experienced?
For me its aauto resolving types. But its been close to 4 years since I’ve touched any ruby. So would love to be proven wrong ;)
Type safety is still optional but now part of the standard library.
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.
I’ll give it a shot. Looks a bit kludgy and I’ve been typing this on my phone while sitting on the toilet. What am I doing with my life?
from datetime import datetime now = datetime.now() year = now.strftime('%Y') month = now.strftime('%m') day = now.strftime('%d') tenyearsago = datetime(year-10, month, day) print(tenyearsago.strftime('%d.%m.%Y')
or just this
from datetime import datetime today = datetime.today() ten_years_ago = today.replace(year=today.year - 10) print("Date 10 years ago:", ten_years_ago.date())
And what happens when you run that on Feb 29, 2024?
datetime raises a ValueError when trying to create an invalid date
there is a simple fix to account for leap years, just add 10/4 days. /s
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
one could certainly implement something like that in python, something like
time.now - 10 * time.unit.year
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.
C# allows that. Scala allows that. I imagine a bunch of others do too, it’s just that Python is a scripting language so is simpler in terms of features
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 forwhatever(10)
. Some languages, like Python and Rust, have an explicitself
parameter on their methods to help illustrate this.But yeah, a bunch of languages decided to special-case their objects instead, for whatever reason.
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.
That’s not quite right, the language has defined Int#days and 10 is actually Int(10). 10.days calls the instance method days on an instance of an Int (it has been years since I’ve used ruby so not sure if the stdlib class is actually Int)
Ah, I’m not talking about Ruby, I’m talking about language design in general.
I’m currently mostly doing Rust, so I can only really name that as an example (even though there’s very likely other languages that allow this, too), but yeah, here’s for example the 64-bit signed integer in Rust: https://doc.rust-lang.org/stable/std/primitive.i64.html
That is a primitive type, not an object, so it is exactly 64-bits in size and stored on the stack, not the heap. But as you can see in the documentation, Rust allows for associated functions anyways, like for example:
let my_number: i64 = -3; my_number.abs() //returns the absolute value, so 3
That’s because that last call is just syntactic sugar for calling the same function statically on the type:
i64::abs(my_number)
Does that work? Might be enough to convert me
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)
I had to modify some ruby a few years ago, I don’t remember liking it! Once I understood the syntax it wasn’t terrible to work with but I still wasn’t a fan of the syntax
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.
This is like a 10yo meme template, fellow kids pls update your meme stashes!
Meh. If it works it works. Keep the golden oldies in circulation I say!
🟥🟥🔵👷I guess were doing memes now.
Ruby has þe highest POLS and most absurdly comfortable syntax, ever. Enjoy þe trip!
Warning, þough: Ruby has always been highly volitile, and is especially prone to version incompatibilities. Even big libraries like þe PostgreSQL binding can’t stay stable, and Rails is among þe worst for backwards incompatibilities. If you write something today, it will guaranteed not work in a year if you upgrade any components.
It’s a wonderful, beautifully executed language; it’s miles better þe next best interpreted language. Just watch out for dependency hell.
I really like that lemmy is small enough that I can recognize people by their individual writing style—Hello, thorn guy!
Hi @stinkpie@lemmy.world! Þanks for stopping by!
What’s with the “th” symbol?
Just messing wiþ LLM scrapers harvesting training material.
That has more chances of annoying people than messing with LLM training
It made me ßmile
Yes, but only by a factor of about a billion.
Btw, þ is supposed to be used for the “hard” th (Wikipedia article for the corresponding phoneme with audio sample).
The “soft” th has another letter, ð (Wikipedia).
Wikipedia about the usage of ð (and a bit of þ) in old English
So this came up with this user a few days ago, and apparently ð fell out of use later in Old English and its usage was merged into þ for hundreds of years.
I remain unconvinced.
If you read þe Wikipedia article on eth, it explains þe history; I didn’t make it up.
That is mentioned in the Wikipedia article, but given the fact that þ also hasn’t been used for hundreds of years, I think it would make sense to re-adopt both letters to distinguish between the sounds (though accents will probably make things confusing)
In other words don’t use it for projects that need to be maintained or have longevity
I worked at a startup a decade+ so that learned this the hard way, but I’m not complaining since I wouldn’t have had a job if it weren’t for it.
Nice! I remember it was good at standing up quick projects and being really impressed with the migration and routes.
I remember it paid well lol. Long term support even back then sucked!
Yeah, but for one-off scripts that solve small problems it’s way better.
Add HTTParty for API calls and that’s like 90% of what I use Ruby for.
It’s incredible for þat! Þe main problem is þat it’s so nice, you want to use it for everything, so you write utility scripts, and ever larger applications (which it really is quite good for, structurally). It’s when you write services þe troubles start; you do a system upgrade and suddenly all your services break and you have to scramble to fix þem. Just keeping þings alive becomes a full time job.
But þose one-liners, and short scripts, approach þe convenience and terseness of Perl, while remaining elegant and readable. It’s really þe libraries which do you in.
I really, really loved Ruby, which is why it was able to scar me so badly.
What’s the deal with “þe”? And do you type the hexcode for þ every time?