Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
I've been trying to learn Kotlin but I find it to be a lot easier to learn when I can slowly apply it to things I'm working on in Java. Is it a bad idea to mix Java and Kotlin in production?
I know the overall goal is to use one or the other but is there anything wrong with the latter?
Objectively, we can say that compatibility with Java was one of Kotlin's main objectives, according to the official docs:
Kotlin is 100% interoperable with the Java programming language and major emphasis has been placed on making sure that your existing codebase can interact properly with Kotlin. You can easily call Kotlin code from Java and Java code from Kotlin. This makes adoption much easier and lower-risk. There’s also an automated Java-to-Kotlin converter built into the IDE that simplifies migration of existing code.
Many features are designed specifically to ease calling Java from Kotlin or vice versa: for example, the fact that property accessors are implemented in the same way as normal Java accessor methods, and the ability to implement SAM interfaces; and where Kotlin implements things differently, there are often annotations or other ways to use a Java-style implementation.
And in my own experience, there are no issues with mixing Java and Kotlin classes. Many of our projects have both (new classes written in Kotlin, a few old ones converted but many still in Java), and I'm not aware of any significant problems. I also converted a major project from Java to Kotlin, one class at a time — and after each one, everything still compiled and tested and ran perfectly.
Of course, new projects can be written in Kotlin from the start; but if you already know Java, mixing in some Kotlin is absolutely an option, and may be the easiest approach. You can convert parts to Kotlin piecemeal, when convenient, or leave them in Java long-term; pretty much everything just works, and you benefit from the parts that are in Kotlin. (You might even find that the way you write Java code benefits from knowing Kotlin!)
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm just new at Groovy and a few years experience on Java. I'm following a simple tutorial said 95% of Groovy syntax are same as Java. So I am wondering is that a good practice to write your Groovy code as Java? And why not?
thanks
You can write Groovy code in Java syntax to make it easy for Java developers to move to Groovy: as this language feature allows them to start by writing code as they know how to, or they can copy/paste existing Java code into a groovy script.
In other words: the groovy language was designed on purpose to allow for this, to help attracting users.
Looking at pros and cons:
The big advantage of writing java-like groovy code is simple: in case you get unhappy with groovy, it is easier for you to move back. And it allows your team members/coworker who haven't learned groovy to understand your work.
The downside: the whole point of groovy is to give you some features that Java is lacking, so to an experienced groovy programmer, "too much java" style might trigger the question: "why using groovy when you write pure Java all the time?"
Beyond that, keep in mind that groovy is really more of a niche language, that never gained a lot of attention (outside the gradle build eco system).
From that point of view, my personal two cents: don't write groovy code in the first place. Even gradle can be used with kotlin these days. Unless you get paid for doing so, rather spend your time and energy with other languages, e.g. kotlin.
"Is that a good practice to write your Groovy code as Java?"
You mean using a Groovy compiler to compile your Java code? Why would you do that?
Although Groovy supports Java syntax, it's mostly intended for simplifying and compacting your code, providing Groovy programming idioms and syntactic sugar. If you're just a beginner, it's ok to combine Groovy and Java code while you're learning Groovy syntax. But ultimately you should use Groovy syntax only.
So the answer to your question: no, it's not a good practise to write Groovy code as Java.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Can someone help me understand why people is using scala over Java for spark? I have been researching but haven't been able to find a solid answer, I know both works fine as they both run on JVM and I know scala us functional and OOP language.
Thanks
Spark was written in Scala. Spark also came out before Java 8 was available which made functional programming more cumbersome. Also, Scala is closer to Python while still running in a JVM. Data Scientists were the original target users for Spark. Data Scientists would traditionally have more of a background in Python, so Scala make more sense for them to use then go straight to Java
Here is direct quote from one of the guys who wrote initially wrote spark from a reddit AMA they did. The question was:
Q:
How important was it to create Spark in Scala? Would it have been feasible / realistic to write it in Java or was Scala fundamental to Spark?
A from Matei Zahara:
At the time we started, I really wanted a PL that supports a language-integrated interface (where people write functions inline, etc), because I thought that was the way people would want to program these applications after seeing research systems that had it (specifically Microsoft's DryadLINQ). However, I also wanted to be on the JVM in order to easily interact with the Hadoop filesystem and data formats for that. Scala was the only somewhat popular JVM language then that offered this kind of functional syntax and was also statically typed (letting us have some control over performance), so we chose that. Today there might be an argument to make the first version of the API in Java with Java 8, but we also benefitted from other aspects of Scala in Spark, like type inference, pattern matching, actor libraries, etc.
Edit
Heres the link incase folks were interested in more on what Matei had to say:
https://www.reddit.com/r/IAmA/comments/31bkue/im_matei_zaharia_creator_of_spark_and_cto_at/
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've done a lot with IO in Java and after looking for code to convert primitives to byte arrays and back I found source for java.io.Bits on one of the Java source code hosting websites. After a quick glance I realized it's exactly what I need, except it's package-private. So I made a copy which I made public, stored in my project's package and used (only in personal projects, I assure you). I find it very useful.
My question is, why is this package-private? I can see it being really useful for people who work with IO and I see no disadvantage from changing it's visibility to public (in rt.jar). Or is there perhaps an equivalent (and please don't mention other libraries)?
Here's a link to a randomly chosen website that has Java source for java.io.Bits: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/Bits.java
You'd have to ask one of the Java devs for sure, but by making it package private, the API can be treated as "internal" - i.e. it might change or disappear at any time. This means the API can be developed relatively quickly, and doesn't need to go through the same relatively thorough testing process that public APIs need to go through (since once they're released, they're stuck there for good.)
In short, making an API public has long term implications, and it requires much, much more work than just hitting a switch.
I would hazard a guess it started life as a "hacked together" group of functions useful for a few other classes in the IO package, and has just stayed there ever since.
It's package-private, sure, but there are public APIs that expose the same behavior, e.g. ByteBuffer.wrap(array).getInt(index) and the other methods on ByteBuffer. You're almost certainly better off using that properly designed, well-documented public API than trying to wrap or copy internal implementation details from Java.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am considering using Akka in one of my projects, but I have to use only Java. A majority of the material (books/articles) are on Scala version, so I am wondering if I use Java I would be a second-class citizen.
Are there any significant functional/performance differences between the two?
Thanks
In terms of performance of Akka itself it will be the same since you are going to be running the same Akka byte code. However in terms of integrating you will be using the Java API and be limited to the language features of Java. As such you will be a second-class citizen in terms of using the API. However in functional and performance terms it will be pretty much identical. Just keep in mind that your Java code will be interacting with the library differently from Scala code. With Scala you have access to closure and other constructs that you cant use with Java (yet). Nevertheless Akka is a great library also when used from Java....
I think the main web site page on Akka sums it all: 11 lines of Scala, 17 lines of Java (+50%).
No or negligible performance difference (bytecode, JVM,...). The performance issues will be around what you write on top of Akka.
Significant functional performance (not in terms of possibilities but code clarity... and clarity has a direct relationship to bugs and fixing them)
Between the two implementations, there are no differences in terms of performance and functionality. If your formation is Java then Akka can be a good solution to introduce the actor model in your Java projects. Clearly with Scala would have the advantages that the whole expressiveness of the language offers.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am a java developer and I want to know,
what is the main benefit from learning a language such as Scala or Groovy?
You can get the same benefit from learning another JVM language as learning any new language. It increases your understanding of programming in general and more importantly, it adds another tool to your toolbox.
So the next time you have to solve a problem, you may reach for a nail gun instead of a hammer.
To be more specific, Groovy is a good language for mocking up code quickly, and Scala, while I've never used it, is suppose to great for writing concurrent applications due to it's functional approach. As others have mentioned, the JVM languages can interact with Java code. Which can be useful for adding onto legacy systems or for mocking up pieces of a application quickly.
Some good reasons that come to mind:
They have features that Java doesn't have and that you may find useful in certain circumstances.
They use different programming paradigms, different way of thinking.
Learning other languages opens your mind.
Learning languages makes you conscious about their respective strengths and weaknesses.
They are getting more and more attention and better JVM support (with Java 7).
Actually, maybe ask yourself the reverse question:
Why not learn an addiitional JVM language?
The other answers here have very good points, but there's one thing I'm missing.
A good coder rarely identifies himself as a 'Java developer', a 'Python developer' or any ' developer'. Learning another language (be it a JVM language or not) will make you understand there's a lot more in the world to learn.
If you're satisfied with only one language, it usually means you're oblivious to the problems it has, and that there are many tasks that are better suited for other languages.
This is why the Pragmatic Programmers encourage every programmer to learn a language a year.
The languages you've mentioned practice a different programming paradigm that could help you be more productive. They are also more fun to work with.
Languages such as Scala and Clojure run on the JVM and exhibit great performance in multi-core systems without imposing synchronization requirements.
And of course you are still able to use the full wealth of libraries that are available for Java.
Because then you'll know a new language, which means a broader skill set and another way of looking at problems. But because Groovy and Scala run on the JVM and you know Java, you can integrate existing libraries and code if you want or need to.
from http://groovy.codehaus.org/:
"Groovy is like a super version of Java. It can leverage Java's enterprise capabilities but also has cool productivity features like closures, builders and dynamic typing. If you are a developer, tester or script guru, you have to love Groovy."
So in many cases it does make sense to use Groovy over Java; For instance in Java unit tests!
Scripting language advantages inside jvm. Seamless interaction with compiled java code.
I know with Groovy, you can load scripts (from files) at runtime from your Java application. This allows me to customize the behavior of application actions at a client site without requiring me to recompile code. It's rather lovely.
Sorry more questions then answers..
What would you spend your time on if you are not learning a new language?
Why are you limiting yourself to JVM languages?
Would it be of more benefit to learn test driven development?
What about learning standard design patents?
What are you trying to achieve with your investment of time?
Learning a language is always good, however if you don’t learn them very well and use them you don’t get a great benefit, as you need to be able to “think in a language” so as to broaden your mind.
Using more than one language in a company leads to lots of additional long term costs so you may gain more by learning how to programme better in your main language, only you can decide.