Home >Backend Development >PHP Tutorial >10 most interesting features of modern programming languages
With the rapid development of information technology, more and more programming languages continue to appear in our lives, and at the same time, it also provides us with more job opportunities. Let’s look at the age of programming languages: Lisp (1958), Smalltalk (1972), Objective-C (1984), Haskell (1990), OCaml (1996), etc. These are all languages from the last century.
The editor of this article selected several latest languages: Reason, Swift, Kotlin, and Dart as research objects, and summarized 10 features:
1 Pipeline operator
Reason syntax
let newScore = me.score |> double |> (it) => add(7, it) |> (it) => boundScore(0, 100, it);
Corresponding JavaScript writing method:
boundScore(0, 100, add(7, double(me.score)));
And es already has a corresponding proposal: tc39/proposal-pipeline-operator
2 Pattern matching
Kotlin syntax
when (x) { in 1..10 -> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") }
3 Reactive (Rx) programming build in the language
Dart syntax
input.onKeyDown .where((e) => e.ctrlKey && e.code == 'Enter') .forEach((e) => dispatch(addTodoAction(e.target.value)));
4 Default parameters of lambda function
Kotlin syntax (using it as the default parameter)
strings .filter{ it.length == 5 } .map{ it.toUpperCase() }
Comparison with JavaScript
strings .filter{ it => it.length === 5 } .map{ it => it.toUpperCase() }
5 Destructuring
Reason syntax:
let someInts = (10, 20);let (ten, twenty) = someInts;type person = {name: string, age: int}; let somePerson = {name: "Guy", age: 30};let {name, age} = somePerson;
Kotlin syntax
data class Person(val name: String, val age: Int)val(name, age) = Person("Guy", 20)
es6 already has array destructuring, es8 adds object destructuring
6 operator cascade Cascade operator
Dart syntax
querySelector('#button') // Get an object. ..text = 'Confirm' // Use its members. ..classes.add('important') ..onClick.listen((e) => dispatch(confirmedAction()));
corresponds The JavaScript writing method
var button = querySelector('#button'); button.text = 'Confirm'; button.classed.add('important'); button.onClick.listen((e) => dispatch(confirmedAction()));
If you use jQuery, the writing method is basically the same as dart, but the two are essentially different
7 if expression If expressions
Kotlin syntax
val result = if (param == 1) { "one"} else if (param == 2) { "two"} else { "three"}
Some people like if expressions, some people hate them, and some people think it doesn’t matter; I like it very much. I have an answer on Zhihu before: https://www.zhihu.com/questio...
8 Try expressions
Kotlin syntax
val result = try { count() } catch (e: ArithmeticEx
ception) { throw IllegalStateException(e)
}
9 Automatic collation Automatic currying
Reason Syntax:
let add = (x, y) => x + y; /* same as (x) => (y) => x + y; */let five = add(2,3); /* 5 */let alsoFive = add(2)(3); /* 5 */let addFive = add(5); /* y => 5 + y; */let eleven = addFive(6); /* 11 */let twelve = addFive(7); /* 12 */
10 Method extensions
Swift Syntax:
extension Int { func repetitions(task: () -> Void) { for _ in 0..<self { task() } } }3.repetitions({ print("Hello!") })// Hello!// Hello!// Hello!
JavaScript can be extended on the prototype.
I think there is another very useful feature, optional-chaining. The reason why it is not mentioned is because most languages already have this feature. It seems that the development of JavaScript is still a bit slow.
The above are the 10 most interesting features of modern programming languages. I hope you all know something about them.
Related recommendations:
Top Ten Programming Languages of Today Which Do You Like
##TIOBE Programming Language Ranking in September 2017
What is PHP? Why should you choose to learn PHP as a programming language?
The above is the detailed content of 10 most interesting features of modern programming languages. For more information, please follow other related articles on the PHP Chinese website!