Further text is my point of view. Perhaps it will allow someone to take a fresh look at the design of programming languages ββor to see some advantages and disadvantages of specific features. I will not go into private details like "there should be a while construct in the language," but I will simply describe the general approaches. PS I once had the idea to create my own programming language, but it turned out to be a rather complicated process that I havenβt mastered yet.
This article inspired me to write an article . The author came up with his own programming language, and this language, with its syntax and peculiarities, turned out to be suspiciously similar to Free Pascal, in which the VM implementation for the language was written. And this is no coincidence. Programming languages ββin which we previously wrote, drive thinking into the framework of the language. We ourselves may not notice this, but an outsider with a different experience may advise something unexpected or learn something new.
The framework of thinking moves apart a bit after mastering several languages. Then in language A, you may want to have a feature from B and vice versa, and there will be an awareness of the strengths and weaknesses of each language.
For example, when I tried to invent and create my own language, my thoughts were completely different from those described in the article above. I thought about completely different things within completely different terms. Below I will describe the features of the language that I would like to see in the "ideal" programming language.
My experience: I once started with Pascal, later I became acquainted with Java, Kotlin, C ++, Python, Scheme, and I consider Scala to be the main language. As in the above case, my "perfect" language has a lot in common with Scala. At least, I am aware of this similarity)
"You can write in Fortran in any language"
It would seem that in any programming language you can express almost any idea and the syntax of the language is not important. But a typical program is written in as simple and short a way as possible, and some possibilities of the language may prevail over others. Examples with the code (I did not check them for correctness, it is just a demonstration of the idea)
Python:
filtered_lst = [elem for elem in lst if elem.y > 2]
filtered_lst = list(filter(lambda elem: elem.y > 2, lst))
, . , .
Scala:
val filteredLst = lst.filter(_.y > 2)
, . . , it => it.y > 2
, .
, lst.map(_.x).filter(_>0).distinct()
, , . , .
[elem for elem in
, . , - .
... = set(filter(lambda it: it > 2, map(lambda it: it.x, lst))))
!
lst.filter(...).map(...) , , . , numpy max β . , , - .
, java:
int x = func();
final int x = func();
, , , . Rust , .
let x = 1;
let mut x = 1;
, , . . ++, , template, typename, inline, virtual, override, const, constexpr
"" .
, , , , .
. , , , . , . , - , , .
, , . , hashmap -.
, . - , . (, - , , )
β must have . , , . β , .
/delphi ( ) (- ). , . . ? , . , Java, ++ . : " void!" , void , , . , Java HashSet<T>
HashMap<T, Boolean>. boolean β , . , HashMap , , . /++ sizeof(void).
, Unit, 0 ( , , Unit, ). , , . HashSet<T>
HashMap<T, Unit>
.
- , , , . , . ?! , :
, "" β , , .
std::tuple
++, , , , , (T1, T2)
. (, Unit ). T => U
, T U β - . , - Unit, , . , , . , .
Union, / , - . scala/kotlin/rust β .
val a = 10 * 24 * 60 * 60
val b = {
val secondsInDay = 24 * 60 * 60
val daysCount = 10
daysCount * secondsInDay
}
, , , ,
go.
-, -. , . , 0 , true (1) false (0) . . , , - success | fail
ok|failReason1 | failReason2
.
, -, . , ok | error(code)
Pointer[MyAwesomeClass] |null
.
-. . Union Tagged Union , , int | int
. Union int | int == int
, . - union . int | int
tagged union , int β .
, - (Union), .
List(x) = Unit | (x, List(x))
.
- ( ), , :
f(x) = 1 + x * f(x)
, f(x) = 1 + x + x*x + x*x*x + ...
, - () -
List(x) = Unit | (x, Unit) | (x, (x, Unit)) | ... = Unit | x | (x, x) | (x, x, x) | ...
C x = , x, , ...
, (x, Unit) == x
, x * 1 = x
, (x, (x, (x, Unit)))
(x, x, x)
.
, , , , , ( ), . , . , β , ++ -, .
, - , , - (). (A, B | C) == (A, B) | (A, C)
, , . .
2 3 , : , ++ . - , , .
β , -, . - . β final java.
, 1-2 /. , , . , "" β , , , , .
( , jvm , const)
, β . , D. - static value = func(42);
.
- gradle, , , build "wtf? ?"
android {
compileSdkVersion 28
}
Groovy. android { compileSdkVersion 28}
, - - , . groovy β , .
, , -
class UnderlyingAndroid(){
compileSdkVersion: Int = 42
}
fun android(func: UndelyingAndroid.() -> Unit) ....
, -, / UnderlyingAndroid, .
, :
android { it =>
it.compileSdkVersion = 28
}
! ? + DSL. , gradle , . , .
extension . , . , . - . β . , T, , sum, , T .
, , . , map.getOrElse(key, new Smth())
, . , assert(cond, makeLogMessage())
.
, β , assert if (cond) { log(makeLogMessage())}
, .
, must have , .
. "" , "" , , . , .
, . , , . , , . , int long.
. , . ( , ++). , ( ) .
. ++ , T
- . , , rvalue-, const. , , , . - Scala Kotlin, "" , .
# β , - . ( , # Unity) , , . 3 ! , , , - . , β .
kotlin/scala β , . , . , .
β inline C++/Kotlin. ! inline , inline , (++) return (kotlin). forced_inline__, noinline, crossinline, - . , , inline , .
, . . , ++ , , . lisp scheme, , .
. - - , β , - . : , "" .
, . , , , .
? Move- , . , . , , - /, . , () .
- , - , .
, , , . , , , , 5, 3, , .
-, . -, (, ), . , ( ++ ).
, , , . - , .
, , :
/ , , .
, . , .
, β .
Source: https://habr.com/ru/post/435300/
All Articles