- cross-posted to:
- programmerhumor@lemmy.ml
- cross-posted to:
- programmerhumor@lemmy.ml
Yukihiro “Matz” Matsumoto has often said that he is “trying to make Ruby natural, not simple,” in a way that mirrors life.
The Python won’t give an accurate date here because it doesn’t take into account leap years.
timedelta
marks time in days, seconds, and microseconds. It doesn’t take leap years into account because the concept of years is irrelevant totimedelta
. If you need to account for leap years, you need a different API.You can subtract two dates and get the exact time difference.
365.25*10 would at least get you closer.
The comparison is somewhat awkward, because the rails example presumably produces a date, while the python one is referring to an interval of time.
Just from the meme it’s not obvious which was the actual intended use, so labeling either as inaccurate requires us to make assumptions.Personally, the concept of “10 years ago” is a bit nebulous to me. If today is February 29th, is ten years ago March 1st? Doesn’t seem right. Or particularly useful.
yeah, that’s pretty much why timedelta doesn’t have the concept of months or years, just days and smaller units. I like it better this way.
Ruby should add 10.years.ago.today
Because what’s accurate here depends on the context, and the Python example doesn’t hide that from the programmer.
The same dilemma goes for month calculations: does “3 months ago” mean 90 days ago, 91.3 days ago, this many days into the target month, or this many days from the target month’s end (e.g. to account for 28, 29, 30, and 31-day months)?
Does the Ruby version do that though?
I haven’t got it installed to check, but seeing constants like SECONDS_PER_YEAR in the documentation makes me think it’s just as bad if not worse.
https://api.rubyonrails.org/classes/ActiveSupport/Duration.html
People still use ruby?
The handful of us have moved onto Crystal Lang. It’s a statically type checked and compiled dialect of Ruby. Crystal is fun to write code, but the compiler is slower (compared to go-lang/rust)… because… well it’s a ruby dialect (with DSL’s)… and the 3rd party libraries are limited.
This type checking, is it at run time?
I had a coworker choose RoR for a major project despite the fact that he didn’t know it, nobody on his team knew it, nobody at our company knew it, and nobody in the entire state knew it. It ended as one would expect, after three years and millions of dollars spent, with the only revenue it generated being $50K from the original client that had to be refunded to avoid a lawsuit.
Yes
Not people who are employed. 😇
I guess I’m the only one then
And I’m the only one too!
You probably use it everyday and didn’t know it https://github.blog/engineering/architecture-optimization/building-github-with-ruby-and-rails/
That explains a lot about how GitHub works… or doesn’t.
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.
Complicated or not, the interfaces suck. And dont have to. And that’s the problem.
exactly why I wrap the parts I need, it’s like git, tons of power, zero help.
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, andLocalDateTime
is the time on host you ran the commands on.
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 canproblem.
…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 doingaddRouter({
and letting the IDE tell you what you could to with the router was so much clearer!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 😁
Any good inline help would run dir into your variable and discover it overloads that operator. It’s a fault of your tools.
This implies that integers in ROR are complex objects with properties that would be unhelpful in the majority of scenarios. Is that right?
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).
Using ruby felt weird, it felt like it shouldn’t work but it does.
365.25, surely
Never use numbers when calculating dates. Use the data formats and constants the calendar library provides.
365.2425
didn’t we gain or lose 0.00000001ish of a day recently? Like from tonga exploding or antarctica melting or something i can’t remember.
That kind of thing happens surprisingly often.
Sure, if you want things at midday instead of midnight.
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).
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.
I like Fish Shell better than python, not gonna lie. Easier to read and write. Especially if you already live in the terminal.
Python is more system agnostic though.
Lucky for me I control all the machines I write scripts for. So far…
I’m surprised this post hasn’t summoned perl devs yet… 🤨
How are the dataframe libraries on Ruby?
Removed by mod
are you ok?
💀
ahahaha oh come on, the comment was clearly a joke. To be honest, I’d be far more interested in gothly serious sam on the left.