-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/time: Time module for stl #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
make semicolons optional
update docs and styles
use string interpolation
HTTP, hashes, QOL stuff
experimental jit, number fix, remove old var/dynamic, move to compile-time
…hClockNative and sleepNative
stl/time.gem
Outdated
| @@ -0,0 +1,105 @@ | |||
| module TIME | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get this renamed Time to maintain consistency with Math? (HTTP is only capitalized due to it being an acronym)
stl/time.gem
Outdated
| @@ -0,0 +1,105 @@ | |||
| module TIME | |||
| def now() int | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only other thing: can we shift this down to 2-space tabs?
|
i actually really like this! it's also a great foundational start to other libs in the future such as random numbers and cryptography, so it's a really solid addition to the codebase just see the other comments re: formatting and i'll get this merged; static functions et al. can be added later and then this can be built out even further after that point. i'd say it's about as production-ready as it can be, given the current state of the language |
|
ah, the build CI's failing |
|
Let me check that out ! |
|
Wait, not done yet haha |
|
I believe it should be fixed now |
|
Okay, just moving an include statement out of a function and it's done :0 |
Hey!
I’ve been experimenting with a basic time module, and while the goal was to build something practical, it also gave me the opportunity to reflect on some of the key features that I believe could significantly enhance the language at this stage of development.
This pull request is far from production-ready, it’s more of a conceptual proposal and discussion starter.
Key Observations and Suggestions
Support for typed class arguments or instanceof
One of the most urgent features, in my opinion, is the ability to either:
• enforce type-safe method arguments within classes (preferably), or
• introduce something like JavaScript’s instanceof.
For example, in the Duration class, being able to write methods that safely accept another Duration instance would improve clarity and eliminate the need for manual runtime type checks — which feels at odds with the statically typed nature of the language.
Proper error handling
This is foundational. Right now, functions like elapsed() have to return nil on invalid input, but ideally, we’d want a way to raise and handle meaningful errors. I probably don’t need to justify this one 😄
Static methods in classes
Many languages support static methods for two main reasons:
• Alternate constructors (from_seconds, from_millis, etc.)
• Utility functions related to a class, but not tied to instance data
While the first use case can often be handled via class inheritance, the second could bring real value. It’s not strictly necessary, but would definitely improve ergonomics.
Operator overloading for class types
Adding support for defining basic arithmetic and comparison operators would avoid a lot of boilerplate in classes like Duration, and make code involving them far more expressive and natural.
Looking forward to your thoughts! Just let me know which direction or feature you’d like me to focus on.
Thank you for work !