Dev-reading /fe is a reading, reading, speed-reading REPO. Don’t rely on dev-reading/fe for knowledge. This REPo is just a quick tool to get to know the content of the article. It does not provide full text interpretation or translation. You can quickly understand the content of the article through this platform, find the article you are interested in, and then go to read the full text.

This article discusses the address: github.com/dev-reading…

The reading time is about 2 minutes


Most “modern” languages today still use the old C-style syntax.

Take a look at the chronologies of programming languages: Lisp (1958), Smalltalk (1972), Objective-C (1984), Haskell (1990), OCaml (1996), and so on. These are the languages of the last century.

In this paper, the author chose several recent languages: Reason, Swift, Kotlin and Dart as research objects and summarized 10 features:

1 Pipeline operator

A tiny grammar

let newScore = me.score

  |> double

  |> (it) => add(7, it)

  |> (it) => boundScore(0, 100, it);Copy the code

The JavaScript equivalent:

boundScore(0.100, add(7, double(me.score)));Copy the code

Es already has a corresponding proposal: TC39 / proposal-Pipeline-operator

2 Pattern matching

Kotlin grammar

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")}Copy the code

3 Reactive (Rx) programming build in the language

The Dart grammar

input.onKeyDown                                              
  .where((e) => e.ctrlKey && e.code == 'Enter')              
  .forEach((e) => dispatch(addTodoAction(e.target.value)));Copy the code

4 Default argument to the lambda function

Kotlin syntax (using it as the default argument)

strings
  .filter{ it.length == 5 }
  .map{ it.toUpperCase() }Copy the code

Compared with JavaScript

strings
  .filter{ it => it.length === 5 }
  .map{ it => it.toUpperCase() }Copy the code

5 deconstruction Destructuring

A tiny grammar:

let someInts = (10, 20);

let (ten, twenty) = someInts;



type person = {name: string, age: int};

let somePerson = {name: "Guy", age: 30};

let {name, age} = somePerson;Copy the code

Kotlin grammar

data class Person(val name: String, val age: Int)
val(name, age) = Person("Guy".20)Copy the code

Es6 already had array deconstruction, and ES8 added object deconstruction

6 Cascade operator

The Dart grammar

querySelector('#button') // Get an object.
  ..text = 'Confirm' // Use its members.
  ..classes.add('important')
  ..onClick.listen((e) => dispatch(confirmedAction()));Copy the code

The corresponding JavaScript notation

var button = querySelector('#button');
button.text = 'Confirm';
button.classed.add('important');
button.onClick.listen((e) = > dispatch(confirmedAction()));Copy the code

If you use jQuery, it’s basically the same as Dart, but there are fundamental differences

7. What is the expression

Kotlin grammar

val result = if (param == 1) {
    "one"
} else if (param == 2) {
    "two"
} else {
    "three"
}Copy the code

Some people like it, some people hate it, some people don’t care; I am very like, I have an answer on zhihu before: www.zhihu.com/question/55…

8 Try expressions

Kotlin grammar

val result = try {
    count()
} catch (e: ArithmeticException) {
    throw IllegalStateException(e)
}Copy the code

Can you use Automatic currying

A tiny grammar:

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); / * * /

let twelve = addFive(7); / * * / 12Copy the code

10 Method extensions

Swift grammar:

extension Int {
    func repetitions(task: (a) -> Void) {
        for _ in 0..<self {
            task()
        }
    }
}

3.repetitions({
    print("Hello!")})// Hello!
// Hello!
// Hello!Copy the code

JavaScript can be extended on prototypes.

I think there is also a very useful feature to add, option-chaining. I didn’t mention it because most languages already have this feature, but JavaScript is still too slow…


Reading text: Ten interesting features from various modern languages

Address: 10 of the most interesting features of modern programming languages

If you’d like to participate in the discussion, click here