You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I miss the possibility of using Bools and Enums (instead of resorting to empty types for signature decoration) in generic parametrizations, would be well considered in tandem with #934.
With "generic parametrizations" I refer to what Crystal calls "type vars" and "free vars".
I often use booleans in C++ templated classes for costly verification code: allowing noobs, and prototyping concepts, using classes in a clean simple fashion without risk of errors, while allowing pros/performance critical code to use them at a finer granular level without integrity checks. In some cases there's just a small part of the class that might have three or more variations depending on requirement, and then enum is nice (NoBeltsCommonCalc| BeltsOnCommonCalc|BeltsOnAdaptiveCalc).
In embedded real-time coding this is a definite must, though I know that such targets are far from an aim of Crystal (though a lovely thought). With that parenthesis aside: it's obviously good for high-performance code on more capable architectures too.
Pseudo Crystal:
classFoo(T, UseCheck=true)
@x : T=T.new(0)
defdo_stuff(x : T) : NilifUseCheckif x >9
com.log_fatal "Serious breach of confidence in Foo#do_stuff dude!"
x =T.new(0) # hopefully save nuclear power plant from blowing upendend@x= x
endend
a =Foo(QU8_56).new
a.do_stuff QU8_56.new(10) # Lucky me the system was speced to have power enough for safety checks - just a couple of hours of city-wide black out.
b =Foo(QU8_56, false).new # I'll use it responsibly - no room for checks on this EMF-safe lo-fi arch!
a.do_stuff QU8_56.new(10) # Not! Well, no need to resign: the world just blew up!
The text was updated successfully, but these errors were encountered:
I miss the possibility of using Bools and Enums (instead of resorting to empty types for signature decoration) in generic parametrizations, would be well considered in tandem with #934.
With "generic parametrizations" I refer to what Crystal calls "type vars" and "free vars".
I often use booleans in C++ templated classes for costly verification code: allowing noobs, and prototyping concepts, using classes in a clean simple fashion without risk of errors, while allowing pros/performance critical code to use them at a finer granular level without integrity checks. In some cases there's just a small part of the class that might have three or more variations depending on requirement, and then enum is nice (
NoBeltsCommonCalc
|BeltsOnCommonCalc
|BeltsOnAdaptiveCalc
).In embedded real-time coding this is a definite must, though I know that such targets are far from an aim of Crystal (though a lovely thought). With that parenthesis aside: it's obviously good for high-performance code on more capable architectures too.
Pseudo Crystal:
The text was updated successfully, but these errors were encountered: