A subset of Python that transpiles to compiled languages.
- Use fixed-width integers:
i32,u64, etc. - Use decorators and composition instead of inheritance
- Use
Result[T, E]instead of exceptions - Use
matchas an expression. Note that there is nocasekeyword.match x: 1: ... 2: ... - match can be nested inside other matches to write succinct code
- Elide types when easily inferred
- Always specify return types on functions
- Use design by contract with
smt.preandsmt.post
def classify_triangle(a: int, b: int, c: int) -> TriangleType:
if smt.pre:
assert a > 0
assert b > 0
assert c > 0
assert a < (b + c)
assert b < (a + c)
assert c < (a + b)
if a == b == c:
result = TriangleType.EQUILATERAL
elif a == b or b == c or a == c:
result = TriangleType.ISOSCELES
else:
result = TriangleType.SCALENE
if smt_post:
assert smt.post(result)
return result