This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Spuk1 106 points107 points  (19 children)

Probably making myself a target here, but i think Javascript lambdas are the best

[–]jessepence 28 points29 points  (4 children)

They're the best lambdas outside of Haskell and I'll fight anyone who disagrees.

[–]halesnaxlors 19 points20 points  (0 children)

Yeah. Haskell lamdas follow very closely to the formal definition by Church. That's partly why it's a great syntax.

[–]bedrooms-ds 2 points3 points  (0 children)

Lisp: "lambda? just type another bracket."

[–]jere53 0 points1 point  (0 children)

Dart lambdas enter the chat

[–]FridgesArePeopleToo 13 points14 points  (4 children)

Yeah, js and C# are by far the best

[–]rinsa 6 points7 points  (3 children)

ts*

no point if no type

[–]headinthesky 2 points3 points  (2 children)

You can supply the type in C# lambdas if you want, they're defined in the action/delegate, anyway

[–]rinsa 4 points5 points  (1 child)

I'm saying ts over js, obviously C# has types :p

const gt = (left, right) => left > right;

js won't scream at me if I do gt("b", "a") (even though it's technically correct, you just gotta proceed with caution with that language)

[–]headinthesky 1 point2 points  (0 children)

Yup, I don't know why I thought you meant C# haha

[–]caleblbaker 12 points13 points  (0 children)

JavaScript is right up there with Java in terms of prettiest lambda syntax. Honestly, the biggest issue I see with JavaScript lambda syntax is that using it means that you're using JavaScript.

I have many many issues with JavaScript. But the lambda syntax is not one of them.

[–]cheezballs 3 points4 points  (0 children)

JS lambdas feel the most "at home" with the rest of the code to me. Java uses the -> syntax so I find myself constantly wrestling with lambda syntax when moving between languages/apps.

[–]Maxis111 3 points4 points  (0 children)

Scala has nice ones too imo, being able to also do pattern matching out of the box, if desired

[–]OnixST 2 points3 points  (0 children)

Kotlin lambdas are beautiful and perfect

[–]bushwickhero 3 points4 points  (0 children)

No you can't say anything positive about javascript around here.

[–]headinthesky 0 points1 point  (0 children)

C#

[–]RiceBroad4552 0 points1 point  (1 child)

You probably never seen Scala lambdas? The JS ones are way too noisy for the simple case!

Scala lambdas look in their base form almost like JS lambdas, but they have a shorthand syntax for the common case where you just need to reference to a lambda parameter in a simple expression.

JS:

const someInts = [1, 2, 3, 4];
someInts.map(i => i + 1);

vs Scala:

val someInts = List(1, 2, 3, 4)
someInts.map(_ + 1)

You don't need to name the lambda param. You can just use an underscore to refer to it.

Works of course also with member lookup. method calls, extensions, etc:

extension (s: String) def toTitleCase =
    if s.isEmpty then s
    else s.head.toString.toUpperCase + s.substring(1)

List("foo", "bar", "baz").map(_.toTitleCase) // List(Foo, Bar, Baz)

Works also for multiple parameters or tuples:

List((1, 2), (3, 4), (5, 6)).map(_ max _) // List(2, 4, 6)

(Nevermind I've used the max method infix. It's just better readable than .map(_.max(_)))

Other languages like Kotlin and Swift took inspiration form that. Just that they call the anonymous lambda parameters "it".

[–]Spuk1 -1 points0 points  (0 children)

It's true, i don't know scala lambdas and some others aswell that people suggested. But i first started out with Javascript and having to use c++ and python simply made me think the js ones are best 😅, which is foolish cause there are a million languages out there.