work by RubyKaigi 2022 Team is licensed under a Creative Commons Attribution 4.0 Unported License. #BF4545 #B8A562 #755B8E #4E6994 #41414F #2C2C31 UFYUDPMPS
to RBS/Steep this year • Generating RBS is big topic • How can we use the type de fi nitions? • Show people the types instead of callseq • Type checking! 💪
have to fi x all of the type errors when you start • Give types to the related part as you need • Type checking a few small fi les would be good for exercise Detected 1759 problems from 85 files
have to fi x all of the type errors when you start • Give types to the related part as you need • Type checking a few small fi les would be good for exercise Detected 1759 problems from 85 files
way to handle nil safely: test every time before using it • Optional type helps you # @type var order: Order? if order = Order.find_by(id: params[:id]) order.update(...) else render status: :not_found end # def sample: () -> Element? unless array.empty? random = array.sample or raise end Do something else if nil It cannot happen
• You know there is no critical bug there • Steep will detect minor problems that forces you add workarounds • Many e ff orts, little bene fi ts • Let's write new code with Steep 💪 • There must be unknown bugs
suitable for the problem • Steep helps you keep case-when safe and up to date # @type var query: Query::Base query.build_relation() # @type var query: Query::Name | Query::Before | Quer case query when Query::Name ... when Query::Before ... when Query::PaidBy ... end Inheritance Union types
types 㱻 case-when • Known set of data types → union types + case-when Unknown set of data types → inheritance + method call • Expression problem • Union types are generalization of optional types • Integer? == Integer | nil • Union types help you enumerate all cases
write new code • Writing types and implementation • Anti-patterns without types can be a best practice • Easier trial and error with types than with implementation