-
-
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
Optional strict mode for Crystal #4603
Comments
Closing as duplicate of #900. This is the exact opposite of crystal goals: not having to bother with types (much). |
Ok @ysbaddaden 😅 Do you know if exist some way to implement this using a shard or macros? |
Well, you can use the parser, and from there check wheher as a type definition. But I really don't see the point. What I would like, however, is a tool to printout inferred types. Something similar to |
Yes, this is a better option. I had not thought!, Thanks you @ysbaddaden 👍 |
Reddit link is about completely different suggestion - don't enforce types declaration, enforce variable declaration (differentiate it from variable assignment, but still let it be untyped). Personally i would like such feature, but yes, perhaps it's too late and it just don't fit in a language. |
Hi, @ysbaddaden ! I use Is some slow in my computer 😅 (Old Intel Celeron) but works! |
Hi people! 😄
@asterite I'm working with crystal code programmed by others developers, I think would be very useful to have optionally a
--strict
flag that allow to check that all types need to be explicit.I got this idea because working with TypeScript projects is very awesome, not because the syntax but because Types help a lot when you need understand the type that a function needs to return by example.
I'm not saying to make types mandatory but something like
use strict
in JavaScript, Also don't need to addvar
orlet
orconst
keywords, instead when use--strict
flag crystal checks that variables have typed specified:Crystal normal mode
crystal build myprogram.cr
Crystal strict mode optional
crystal build --strict myprogram.cr
Then you try again with type specified
crystal build --strict myprogram.cr
:All ok!
I really like type inference and write code without types but sometimes is useful to have Types in complex projects. The
--strict
mode proposal is not mandatory, just an tool to help to the programmer to remember where a type is missed. In fact the--strict
mode could live insidecrystal tool strict
or something similar allowing to checkstrict
mode in some files only checking that all code have types.I know that crystal is strict about types but I'm saying that
--strict
flag do compiler just more strict 😅Extract from Reddit by @RX14 :
Yes, but I would wish don't wait until compile time to know what type a function must return.
Please let me now your opinions 😄
Reference: #900 and Reddit
The text was updated successfully, but these errors were encountered: