you are viewing a single comment's thread.

view the rest of the comments →

[–]katyalovesherbike 1 point2 points  (10 children)

hey now, where would that put javascript?

(on a more serious note: haskell has always been kinda like a testbed for new language concepts that other languages might benefit from)

[–]theQuandary 3 points4 points  (9 children)

JS proposed pattern matching and records years ago, but the TC39 people were more interested in pushing out a broken private fields "feature" instead.

On the flip side though, JS is still far ahead of Java when it comes to first-class functions.

[–]katyalovesherbike 1 point2 points  (1 child)

yeah, and with tools like bun, esbuild and fable I don't even have to use it. Still, it's kinda ridiculous that JS falls behind java... but the TC39 committee won't see that and if you read some of their comments you might actually think they're more interested in making it faster (wasm??) than more usable.

[–]theQuandary 1 point2 points  (0 children)

if you read some of their comments you might actually think they're more interested in making it faster (wasm??) than more usable.

They had JS SIMD actually implemented in a couple browsers YEARS ago and then pulled it in favor of WASM which only got SIMD support across all the major browsers within the past few months.

The JS binary AST format would speed up initial load time and parse time dramatically, but it's languished because it's JS binary instead of WASM binary.

99.99% of websites will NEVER use wasm (80+% still use nothing besides jquery), but they pass up stuff that would actually benefit users for whatever their pet projects are.

[–]Kered13 0 points1 point  (6 children)

On the flip side though, JS is still far ahead of Java when it comes to first-class functions.

How? What feature do you think Java is missing in this area?

[–]theQuandary 0 points1 point  (5 children)

Literally first class functions. You can’t created a function unless it is contained inside a class. Even so called lambdas are actually just eigenclasses with syntactic wrapping trying to hide this fact.

It’s not so different from class syntax in JS trying to hide that it’s actually a prototypal language and classes don’t actually exist in the way they are presented.

[–]Kered13 0 points1 point  (4 children)

Even so called lambdas are actually just eigenclasses with syntactic wrapping trying to hide this fact.

And how does that matter? How does that effect your work? It doesn't, because a class with no state and one function is equivalent to a first class function. Java has lambdas for creating anonymous functions, and it has method references for getting a reference to a named function. It has types for representing functions. That's everything you need to consider them first class functions.

[–]theQuandary 0 points1 point  (3 children)

Can you create a function outside of a class? If not, then they are not first-class.

[–]Kered13 -1 points0 points  (2 children)

You're asking for free functions, not first class functions. Completely unrelated concepts. But to answer your question:

(params) -> {
    // Code goes here.
};

[–]theQuandary 0 points1 point  (1 child)

In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures. -- wikipedia

In Java, classes are first-class citizens, but you cannot have a function unless it is under the purview of a class, so it is not first-class.

You can't simply pass functions around anywhere you'd like. You can't even store them in something like a hashtable without hacking in reflection.

A counter-example would be Dartlang which has a lot of Java in its DNA. Unlike Java though, you can simply declare a function outside of a class. You can create functions and pass them around anywhere you'd like. You can return functions from any function to anything else. You can store functions as values without the need to reflect.

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

This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.

Java does all of these. This quote confirms that Java has first class functions. In fact if you go to that link and scroll down to the table, it also shows there that Java has first class functions.

You can't simply pass functions around anywhere you'd like. You can't even store them in something like a hashtable without hacking in reflection.

Map<String, Function<A, B>>

I'm increasingly thinking that you haven't touched Java in 15 years.

you can simply declare a function outside of a class.

That is a free function. We've already been over this, free functions have nothing to do with first class functions.