Python is the nicest language I currently know of, but static typing is a big advantage due to auto-completion (although there is limited support for dynamic languages, it is nothing compared to that supported in static). I'm curious if there are any languages which try to add the benefits of Python to a statically typed language. In particular I'm interesting in languages with features like:
Are there any statically typed languages with a significant number of these features?
Python will always remain a dynamically typed language. However, PEP 484 introduced type hints, which make it possible to also do static type checking of Python code. Unlike how types work in most other statically typed languages, type hints by themselves don't cause Python to enforce types.
Python is both a strongly typed and a dynamically typed language. Strong typing means that variables do have a type and that the type matters when performing operations on a variable. Dynamic typing means that the type of the variable is determined only during runtime.
A statically-typed language is a language (such as Java, C, or C++) where variable types are known at compile time. In most of these languages, types must be expressly indicated by the programmer; in other cases (such as OCaml), type inference allows the programmer to not indicate their variable types.
Java is statically-typed, so it expects its variables to be declared before they can be assigned values.
Boo is a statically typed language for the Common Language Infrastructure (aka. the Microsoft .NET platform). The syntax is highly inspired by Python, and hashes/lists/array are part of the syntax:
i = 5 if i > 5: print "i is greater than 5." else: print "i is less than or equal to 5." hash = {'a': 1, 'b': 2, 'monkey': 3, 42: 'the answer'} print hash['a'] print hash[42] for item in hash: print item.Key, '=>', item.Value
Cobra is a statically typed language for the CLR (as Boo). From its web page:
Cobra is a general purpose programming language with:
- a clean, high-level syntax - static and dynamic binding - first class support for unit tests and contracts - compiled performance with scripting conveniences - lambdas and closures - extensions and mixins - ...and more
Sample code: """ This is a doc string for the whole module. """ class Person """ This is a class declaration. """ var _name as String # declare an object variable. every instance of Person will have a name var _age as int cue init(name as String, age as int) _name = name _age = age def sayHello # This is a method # In strings, anything in brackets ([]) is evaluated as an expression, # converted to a string and substituted into the string: print 'Hello. My name is [_name] and I am [_age].' def add(i as int, j as int) as int """ Adds the two arguments and returns their sum. """ return i + j
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With