Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What statically typed languages are similar to Python? [closed]

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:

  • Syntax support: such as that for dictionaries, array comprehensions
  • Functions: Keyword arguments, closures, tuple/multiple return values
  • Runtime modification/creation of classes
  • Avoidance of specifying classes everywhere (in Python this is due to duck typing, although type inference would work better in a statically typed language)
  • Metaprogramming support: This is achieved in Python through reflection, annotations and metaclasses

Are there any statically typed languages with a significant number of these features?

like image 536
Casebash Avatar asked Feb 15 '10 09:02

Casebash


People also ask

Can Python be statically typed?

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.

Is Python statically typed or dynamically typed?

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.

What languages are statically typed?

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.

Is Java a statically typed language?

Java is statically-typed, so it expects its variables to be declared before they can be assigned values.


2 Answers

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 
like image 150
Jørn Schou-Rode Avatar answered Sep 23 '22 13:09

Jørn Schou-Rode


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 
like image 25
Manuel Ceron Avatar answered Sep 25 '22 13:09

Manuel Ceron