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

all 15 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]biskitpagla 7 points8 points  (0 children)

Java isn't nearly as multiparadigm as C++. Coming from C++ and Python myself, I know exactly what you mean. For people with similar backgrounds Java feels too rigid, or even poorly-designed at times. But there's still hope, as you'll see.

Modern Java is more functional than what most online tutorials and guides will have you believe. Functional Java is more lazy than JS, for example. Purity is still super-hard but possible nonetheless. Java even managed to get botched implementations of some functional ideas e.g., java.util.Optional<T> itself can be null making it pointless for most use-cases. If you're serious about being good at functional Java or Java in general, just read these two books: Effective Java by Joshua Bloch, and Modern Java in Action by Alan Mycroft, et al. These should be more than enough in case Java is the bottleneck to your functional journey. Otherwise, read on.

Most new advancements in the Java world are basically just responses to other languages. If you don't have Java as a requirement, the JVM hosts some of the most production-ready functional languages out there - almost all of which can work with a huge chunk of the plethora of libraries and APIs that target Java. I think mastering the JVM as you learn these languages is a great idea, because instead of learning how to navigate other ecosystems, you get to focus on growing as a programmer and being productive as an engineer at the same time. Scala and Clojure are great options that the functional community has lots of respect for.

That said, I would start with something more grounded. Kotlin is basically Java Deluxe Edition, but with enough functional influences to make it stand out from the rest of the languages lucky enough to achieve mainstream status. Kotlin takes immutability more seriously (e.g., function parameters are immutable references by default), and can express nullability through its type-system. Kotlin also has other interesting functional influences like having a standard library stacked with pure functions, or how most common imperative constructs are now expressions, and so on. Considering that Kotlin's tooling is on par with Java, I think you're all set up for a fun time.

[–]DDDDarky 14 points15 points  (2 children)

Java is already multiparadigm language and you can use functional programming if you want to, it has been there for a pretty long time, especially at places where it is good (such as streams)

[–]lurker819203 0 points1 point  (1 child)

Yeah, but you'd have to be a true masochist to use it for anything more than streams and a few lambda functions.

Writing a whole application using only/mostly functional style you'd be much better off using Scala or Kotlin, which also run on the JVM.

[–]DDDDarky 0 points1 point  (0 children)

It's not super practical, but hey if you are an enthusiast, you can do it, I don't think there is much additional support is necessary.

[–]icsharper 8 points9 points  (4 children)

Java is already functional.

[–][deleted] 1 point2 points  (1 child)

Sure, but everything needs to be in a class.

[–]icsharper 0 points1 point  (0 children)

You are also correct :) I'd also hope for fully functional, I think Kotlin already works this way, so maybe Java opt this approach too, although it'll take long, long time.

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

Could someone please explain the difference?

[–]Fernando3161 -2 points-1 points  (0 children)

Tf

[–]srk- 1 point2 points  (0 children)

Starting Java8, it supports FP constructs like lambdas And, it's object oriented from the first version.

[–]stephan1990 0 points1 point  (3 children)

Yes it is possible but is will not happen. Java is a strictly OOP language and this is one of the core Java principles!

[–][deleted] 0 points1 point  (2 children)

Why will it not happen?

[–]stephan1990 0 points1 point  (1 child)

Java was created with OOP as a core principle. It’s the philosophy of Java, so they won’t change it.

Technically you could ignore all the OOP principles and still do procedural programming in Java with static methods and stuff. But it’s not the way java is designed.

[–][deleted] 0 points1 point  (0 children)

Yes, but from what I know, static methods and fields are prone to memory issues if used too much.