|
||||||
|
||||||
Type Inference
Boo is a statically typed language. Static typing is about the ability to type check a program for type correctness. Static typing is about being able to deliver better runtime performance. Static typing is not about putting the burden of declaring types on the programmer as most mainstream languages do. The mechanism that frees the programmer from having to babysit the compiler is called type inference. Type inference means you don't have to worry about declaring types everywhere just to make the compiler happy. Type inference means you can be productive without giving up the safety net of the type system nor sacrificing performance. Boo's type inference kicks in for newly declared variables and fields, properties, arrays, for statement variables, overriden methods, method return types and generators. VariablesAssignments can be used to introduce new variables in the current scope. The type for the new variable will be inferred from the expression on the right. Only the first assignment to a variable is taken into account by the type inference mechanism. FieldsDeclare the new field _name and initialize it with an empty string. The type of the field will be string. PropertiesWhen a property does not declare a type it is inferred from its getter. In this case the type of the Answer property will be inferred as int. ArraysThe type of an array is inferred as the least generic type that could safely hold all of its enclosing elements. For statement variablesThis works even when with unpacking: Overriden methodsWhen overriding a method, it is not necessary to declare its return type since it can be safely inferred from its super method. Method return typesThe return type of a method will the most generic type among the types of the expressions used in return statements. When a method does not declare a return type and includes no return statements it will be typed System.Void. Generators
|
||||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
||||||