Easy to learn language like Python, but which requires a variable declaration?

Python is very easy to learn and understand; I like its use of keywords, the lack of complex syntax (opposite perl, from what I heard) and easy to use data structures. However, I cannot bear the lack of a variable declaration because it makes it impossible to explicitly tell Python which scope you want to have. Are there any languages ​​that have all the qualities that I like in Python, as well as variable declarations and, possibly, an affordable set of available libraries?

Thankslot.

+3
source share
7 answers

Try pychecker , pylint , pyflakes or other code checking tools. They help break errors that the interpreter does not complain.

+7
source

You can try using Python with variable declarations:

>>> x = 0 # a global variable
>>> def fact(n): #n is a parameter
...     x = 0 # local variable declaration
...     z = 1 # declaration and initialization
...     for i in range(1, n + 1): # a loop variable is defined inline
...         z = z * i
...     return z
...     
>>> x = 5 # the global x
>>> fact(x)
120

Can you explain what the problem is with this? Also, as Nick Bastin said in a comment, this will help if you explain if your issue is related to an ad or an area.

If your problem is with syntax or static typing, would the following syntax be acceptable to you?

def f(double x):
    return x**2-x

def integrate_f(double a, double b, int N):
    cdef int i
    cdef double s, dx
    s = 0
    dx = (b-a)/N
    for i in range(N):
        s += f(a+i*dx)
    return s * dx

This syntax applies to Cython , a language for extending Python using compiled (C) extensions.

+2

#

.

+1

Google Go, . . . , - .

.

0

Perl 6, , Perl 5, , . , , , ...

dev.perl.org, .

0

Cython is very similar to Python, but has a variable declaration similar to C (in fact, Cython allows a lot of the things that are presented in C).

0
source

How about boo . CLR, very similar to Python. Static types with output type.

0
source

Source: https://habr.com/ru/post/1776107/


All Articles