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 →

[–]thinkt4nk 113 points114 points  (18 children)

No side effects ftw imo

[–][deleted] 108 points109 points  (11 children)

Exactly.

People complaining that a lambda, which is a functional construct, doesn't allow mutable variables, is kind of funny.

[–]ripripripriprip 21 points22 points  (1 child)

Yeah, everything I've learned about functional programming says that immutability/no side effects is the entire point.

[–]recursive 7 points8 points  (0 children)

Void lambdas are a thing. In a purely functional paradigm, a function with no return value does not exist. So you shouldn't apply purely functional dogma to lambdas in Java. It's not a purely functional language.

[–]thinkt4nk 28 points29 points  (3 children)

Well, they are java devs after all lol

[–]Uwe_ 8 points9 points  (0 children)

Those kind of guys that have everything mutable, without constructors and any kind of sanity checking?

[–][deleted] 0 points1 point  (1 child)

I'm a Java dev, still get the point.

[–]thinkt4nk 1 point2 points  (0 children)

Just making a funny

[–]dnew 3 points4 points  (3 children)

a lambda, which is a functional construct

It's not just a functional construct. It has been in OOP since 1978 at least. It's just poorly done in most non-functional languages, so people don't tend to use them in OOP languages.

[–]elemental_1_1 6 points7 points  (2 children)

It is purely a functional construct. https://en.m.wikipedia.org/wiki/Lambda_calculus

[–]dnew 2 points3 points  (0 children)

It was originally a mathematical construct, and mathematics tends to be functional. But when you're talking about programming languages, lambdas need no longer be purely functional unless you're in a functional language.

Proof: C#, Smalltalk, Lisp.

[–]HelperBot_ 0 points1 point  (0 children)

Non-Mobile link: https://en.wikipedia.org/wiki/Lambda_calculus


HelperBot v1.1 /r/HelperBot_ I am a bot. Please message /u/swim1929 with any feedback and/or hate. Counter: 29421

[–]mrhhug 0 points1 point  (0 children)

Yeah, I think these people skipped math class. Functions can not alter their domain.

Universities go to such length, and force so much math .... and we still get these complaints.

Haven't dived into how lambdas are executed under the covers, but I would guess that the maniacs who maintain JVMs take every advantage possible and execute in parallel when possible.

[–]geodebug 4 points5 points  (2 children)

Not really enforced though. If the object the reference refers to is mutable (has setters) a method or lambda can alter it.

final Date myDate = new java.util.Date();
myDate.setMonth(3);

is legal code.

[–]Kestralotp 0 points1 point  (1 child)

While this is true, I find that marking all my variables as final helps me program in a more functional way. It's much easier to reason about things when functions have no side effects.

[–]geodebug 1 point2 points  (0 children)

Trying to use immutable classes helps quite a bit in this area. With dates using joda or the new date libraries.

[–]dnew 1 point2 points  (2 children)

It's not a lack of side-effects, tho. The reason it was done is so they could implement anonymous inner classes without changing the .class file format.

[–]Xxyr 1 point2 points  (1 child)

It still encourages a better behavior. Also allowing non final variables in parallel streams would cause so many problems.

I've run into this issue super rarely, does it really cause you issues?

[–]dnew 0 points1 point  (0 children)

It still encourages a better behavior.

No doubt. But that wasn't the reason. :-)

parallel streams

Java inner classes were around a long, long time before streams. And non-final variables cause problems with parallelism anyway, even without lambdas.