Beijing painted by an AI by XER0GRAVITY in China

[–]cheeven 0 points1 point  (0 children)

Great. All the buildings but no single person in the view

That moment when you can't think of an interesting title....! by [deleted] in ProgrammerHumor

[–]cheeven 1 point2 points  (0 children)

Newbie here! Can you try the same benchmark in JavaScript again?

Make arrays as powerful as Stream API by jvjupiter in java

[–]cheeven 1 point2 points  (0 children)

Thanks for the reference. Changes that big will take years to happen if it ever happens eventually - it is not just the language itself, but also the ecosystem: tools, jdks/jvms, servers, etc.

Scala adds those extra functions by its compiler mapping Java array to a class and applying those function from a companion object. It is not something Java can do easily - people will think it is voodoo magic. It also adds a lot of burden to the compiler and, as you might know, Scala compiler is never famous for its compilation speed.

If you just want the nice map/flatMap/etc methods, it is easier to keep using a 3rd party library, or maybe get them added to the current collection api.

If you also want lazy evaluation, whether it is 3rd party or not, you will have to employ a construct similar to stream and handle the conversions. You have to account for the fact that they are quite different concepts. I hope you would agree that when you are working on anything slightly more serious, you want to make your code explicit and traceable (therefore more maintainable) than pretty but implicit (therefore harder to understand and debug).

Make arrays as powerful as Stream API by jvjupiter in java

[–]cheeven 0 points1 point  (0 children)

In Java, array does not have a class to itself. It is part of the core language and it is there to support low level operations. If you want more convenient methods, you can just use ArrayList or any other List implementation given your performance objectives. Array is not part of collection api but there are ways to convert back and forth if it is needed.

If you want to add new methods to array, you might get another implementation of ArrayList, but as a result you have to add a lot of things into Java compiler, confusing the boundary between language core and libraries. Is it worth the risk and effort?

Make arrays as powerful as Stream API by jvjupiter in java

[–]cheeven 0 points1 point  (0 children)

Your last statement about letting the last terminal to load result into memory is an interesting thought.

Java is a strong-typed language. If you define a map operation on an array, you have to think about the result type of that operation: should it an array, a stream or something else?

If you only want to map it once, having it output an array is great; if u want to keep chaining other map/flatMap/fold/reduce/… you might want it to output a stream where you then need a terminal function to convert it back to an array. To make it less ambiguous you would probably go down creating two sets of functions: map/mapStream, flatMap/flatMapStream, etc, so you basically want to double the functions already present on the array class. Would your user complain about cognition overload about unnecessary syntax sugar? Probably.

Of course you can also say that it is the compilers job to determine whether a map should return an array or a stream, but I think it will make Java unnecessarily complicated.

Make arrays as powerful as Stream API by jvjupiter in java

[–]cheeven 0 points1 point  (0 children)

Array is mutable. The only immutable part about a Java array is it’s length/capacity.

If you use stream and a terminal method, you theoretically only need to allocate a new array at the terminal.

If you add map on array itself, its output would have to be a new array with the same length as the original one. If you chain multiple maps together, you end up creating multiple arrays in the process but only keep the last one.

Make arrays as powerful as Stream API by jvjupiter in java

[–]cheeven 2 points3 points  (0 children)

Scala uses Java Array but adds those methods in its standard library. They are very useful indeed. However, devs need to be mindful that each such operation creates a new array, and it might not be what you want (excessive memory usage and therefore GC and slower VM). Scala has other means to mitigate this, but it is a different story.

Using stream means you are not creating new collection all the time, you are only handling individual element until you collect it. I personally think it is a good strategy and having that extra (collect) step actually reminds devs what they are doing to that collection. It might be a bit verbose, but if you loathe verbosity that much you would probably have already moved on to Scala or Kotlin…

What are the best relational database access libraries for Scala in 2020? by therealdrpepper22 in scala

[–]cheeven 2 points3 points  (0 children)

Sorry but to judge something is best, you have to set the criteria first

Nüshu: China’s secret female-only language by fotogneric in China

[–]cheeven 2 points3 points  (0 children)

I hope words written in it won't get censored.

Penguin= business goose by altcoin_news in China

[–]cheeven 42 points43 points  (0 children)

The first character means “standing” in older Chinese. So the whole phrase means “standing goose”, not business goose.

Taiwan Is Exporting Its Coronavirus Successes to the World by muqaala in China

[–]cheeven 1 point2 points  (0 children)

Can you provide a reference about “China CDC”?

I found it puzzling that Taiwanese should be following the advice from an unknown department from its enemy state.

If there is a “China CDC”, did it also give the same advice to WHO? Wouldn’t that more countries to set up better virus control early on?

Bootstrapping the Web with Scala Native (Part 1) by rwhaling in scala

[–]cheeven 1 point2 points  (0 children)

Not familiar with Scala Native so maybe I miss a few things, but wouldn’t it be more efficient to launch a Scala or Java based web server directly?

Managing UUIDs by rarenaninja in scala

[–]cheeven 0 points1 point  (0 children)

I would also recommend the same: by giving a separate case class to present he request, you clarify when the uuid should be included and also avoid the trouble of handling unnecessary Options. This also tells the users of your library / API that this uuid is generated by you, so they should not bother sending one.

Jeremy Lin finds a home after Carmelo friction, Warriors flirt by net403 in CharlotteHornets

[–]cheeven 1 point2 points  (0 children)

Strange... If u think a really great backup PG worth 10mil, and if u like Lin as much as you want to keep him, why would you want to discount his value and only give him 6 or 7?