-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix Time.new and Time.utc #6118
Conversation
This is not a real fix, but rather a naive workaround. The real issue is that the return value of |
I think all of the API methods that accept So 👍 to this PR. @r00ster91 Thank you! |
@asterite Well, in this case shouldn't it rather be |
@Sija No, |
Changing unspecific And after all, this PR won't fix the core issue that |
Yeah, it could probably be done in a separate PR, thought it can be done before 0.25.0 because it will be shipped along the new feature. But even if the automatic cast feature is not shipped (which won't happen), using |
I don't understand the idea of using signed number instead of unsigned where is doesn't make sense to have negative numbers. |
@bew I don't think unsigned numbers exist to represent non-negative integer numbers, but just for their math properties (that they wrap, etc.). Here's one explanation of why it's a bad idea to use unsigned integers: http://www.aristeia.com/Papers/C++ReportColumns/sep95.pdf I also remember someone "important" said that confusing unsigned numbers with non-negative numbers is bad, but I can't find it... |
Very interesting, thank you. |
The main point is that subtracting two unsigned values It has nothing to do with implicit conversions. |
Plus, there isn't really a benefit of using unsigned integers. They are not faster (in LLVM and in the computer they are represented with the same datatype). So "because it can never be negative" is not a good reason to use unsigned integers. In fact, Java doesn't have unsigned integers and 3 billion devices run Java. |
This is unsatisfying. I'm not against restricting the arguments to Now the two constructors restrict the date fields to |
I can send a PR to change But I don't understand. This is an improvement over the old code. It might not fix all problems, but that's how we move in Crystal, fixing things slowly. |
I agree with @asterite here. Let's make things work first 👍 |
@asterite Sure, it's an improvement. But it also creates new needs for improvement that could have been avoided right away with almost no extra effort. |
I think that the direction we want to move in is having more type annotations. The way I view it is that this change would have been incorporated in a later change sooner or later anyway. |
In fact, I wanted to open an issue or a discussion about you (community) showing examples of methods where you wouldn't know what type annotation to use. Everyone say "but then you won't be able to be as expressive", but I really want to see those examples. Because otherwise, let's type everything and make the compiler incremental and fast. |
@asterite it's not about not knowing the type, it's about not having to write down the type that we know in our head. And it's about not having to rename a bajillion things when we rename a type and such. I don't want Go with Ruby syntax I want Crystal, and Crystal is beautiful to me. |
It's of no use if it's just in your head. Programming is not a solo thing. I want Go with Ruby syntax, blocks and macros 😢 |
@asterite then go write it. It'll be a lot easier to write something like that from scratch and not call it crystal than to start from crystal. |
@asterite Interesting, Maybe we can do some kind of pre-compilation from an untyped (inferred) codebase to generate all typed code, just like This way we can deliver shards with faster compile times, keeping the main codebase clean (without too much types), just like WDYT? 😅 |
So, normal untyped (inferred) code would still compile slow without incremental compilation And, new code (generated/all typed) code would have fast compilation with incremental builds WDYT? |
The main use-case would be fast compile times on big projects with many shards ✨ |
@faustinoaq we'd still have to modify the compiler to take advantage of type restrictions to reduce compilation time in the first case. And if we could do that, we've solved the whole problem already. You've essentially just reformulated and restarted the existing problem. |
@asterite in src/string/builder.cr:19: no overload matches 'GC.malloc_atomic' with type UInt32
Overloads are:
- GC.malloc_atomic(size : Int32)
- GC.malloc_atomic(size : LibC::SizeT)
@buffer = GC.malloc_atomic(capacity.to_u32).as(UInt8*)
^~~~~~~~~~~~~
Makefile:121: recipe for target '.build/crystal' failed
make: *** [.build/crystal] Error 1 if I should make it an Union: |
|
@Grabli66 discovered a bug in
Time.new
.When you do for example this:
then you get this:
instead of:
It's probably because of an overflow internally.
I fixed this by restricting
year
,month
andday
ofTime.new
andTime.utc
toInt32
.