Hello. New to Crystal and the community. Just wrote a longer intro post.
I am a long time Pharo user and reasonably new to statically compiled languages. I have some experience with Nim, but not extensively.
I am porting an application to Crystal and doing some things I have not done before. I write programs for me and not professionally. I am porting the app and learning Crystal at the same time.
While I have believed in the idea of writing tests. I have never put in the effort to do so. So, while porting my app to Crystal I have decided to attempt to learn Crystal and do things in a better manner, do things the right way.
So I started off with a file with no dependencies on any other part of the app. I have completed that port. But now I decided I am going to write the spec for the this file. All is going fine. I am getting educated.
But then I write a test for next method in the file and I get a runtime error that I do not know why it is runtime and not compile time.
# Returns the {Sunday 21:00UTC. Friday 21:59.999UTC} of the last complete trading week.
def last_trading_weekends()
weekspan = Time::Span.new(days: 7)
open_sunday, close_friday = trading_weekends(Time.utc)
if open_sunday <= dt <= close_friday
open_sunday -= weekspan
close_friday -= weekspan
end
{open_sunday, close_friday}
end
$ crystal spec spec/core_time_spec.cr
Showing last frame. Use --error-trace for full trace.
In src/core/core_time.cr:39:23
39 | if open_sunday <= dt <= close_friday
^-
Error: undefined local variable or method 'dt' for top-level
The error is simple. I copied and pasted code and didn’t make the adjustments of a variable now longer being passed in.
I was just curious as to why this isn’t caught in the editor or the compiler. I thought this was one of the advantages of a statically compiled langauge. In Pharo I would have been able to save the method with this error. I suspect that it should be caught but for some reason it is not.
I am using Codium (VS Code) on MXLinux. The experience is currently primitive but doable.
Thanks.
Jimmie