Earlier quoted context omitted.
They are hard to test only if they are not functions and access some global mutable state. In vast majority of cases static methods are functions and are easier to test than normal methods, because you do not need to initialize object.
I suspect that the issue that the GP is discussing is not that they are hard to unit test, but that they are hard to mock: If you don't want to call the static method, either some relatively unfortunate thing has to be done to your mocking classes, or you have to inject it, which is uncommon in this kind of situation in your typical Spring application. Now, what I'd say to that kind of argument is that a good static…
Paving the on-ramp to Java
111–120 of 156 posts
Re: Paving the on-ramp to Java
#112Earlier quoted context omitted.
They are hard to test only if they are not functions and access some global mutable state. In vast majority of cases static methods are functions and are easier to test than normal methods, because you do not need to initialize object.
I suspect that the issue that the GP is discussing is not that they are hard to unit test, but that they are hard to mock: If you don't want to call the static method, either some relatively unfortunate thing has to be done to your mocking classes, or you have to inject it, which is uncommon in this kind of situation in your typical Spring application. Now, what I'd say to that kind of argument is that a good static…
Re: Paving the on-ramp to Java
#113Earlier quoted context omitted.
They are hard to test only if they are not functions and access some global mutable state. In vast majority of cases static methods are functions and are easier to test than normal methods, because you do not need to initialize object.
I suspect that the issue that the GP is discussing is not that they are hard to unit test, but that they are hard to mock: If you don't want to call the static method, either some relatively unfortunate thing has to be done to your mocking classes, or you have to inject it, which is uncommon in this kind of situation in your typical Spring application. Now, what I'd say to that kind of argument is that a good static…
I think some people put unit testing to the extreme by not wanting to test logic outside of the unit tested (which is not possible to do fully). They write additional code for mocks so their tests could be less useful but more "pure".
Re: Paving the on-ramp to Java
#114Kotlin's syntax is cleaner in some most places, more explicit in some places (no implicit nulls, and wrt generics) and much terser when using naked functions etc. Did Java's papa get jealous?
I always find it funny when people bring up Kotlin in the context of Java's evolution. It's not one of Java's main competitors, and while Java has borrowed many features from other languages [1], to date it has not adopted a single feature from Kotlin [2]. In fact, almost at every turn -- from data classes, through async/await, to string interpolation (JEP 430) -- Java has opted for a different approach. Is Kotlin th…
On the JVM: I'd say yes.
Scala, Groovy, Jython, JRuby, and what not came and went.
I'd say Clojure is the third, and it take a nice place in the design space.
But Kotlin to me is so close to Java that it is basically Java 2.0: the Java that Java cannot be due to intended organizational slowness.
> Python is one of Java's main competitors, and when it comes to teaching a first language it is the main competitor.
Yes it probably is. The changes outlines in the article are not going to help here I'm afraid.
But I'm weird. I'd say the best lang without static typing for noobs is a LISP (so that every student is likely equally confused). When learning a language with types go for Rust or Idris. All not exactly competitors of Java :)
Re: Paving the on-ramp to Java
#115Confused about the criticisms now. Otherwise everybody complains about Java boilerplate. Remove some of it and make it optional, to avoid bogging down newbies in irrelevant details in the first instance, and further lead to less boilerplate to make simpler applications in the second instance (or further down the line). I'm not seeing a massive amount of effort being expended here, and I don't see how it's being waste…
I agree. Ironically, Java the language doesn't have any more boilerplate than, say, C++ or Go, which people are apparently okay with? It does however have some stuff that's plain dumb (can't have functions outside classes, public static void main(String[]), ...) some of it isn't even fixable (default visibility should be private, final should be like const in C++, or even better like const in D). This is a change tha…
Re: Paving the on-ramp to Java
#116Re: Paving the on-ramp to Java
#117Earlier quoted context omitted.
They are hard to test only if they are not functions and access some global mutable state. In vast majority of cases static methods are functions and are easier to test than normal methods, because you do not need to initialize object.
I suspect that the issue that the GP is discussing is not that they are hard to unit test, but that they are hard to mock: If you don't want to call the static method, either some relatively unfortunate thing has to be done to your mocking classes, or you have to inject it, which is uncommon in this kind of situation in your typical Spring application. Now, what I'd say to that kind of argument is that a good static…
In fact, dependence on mocking frameworks is a huge code smell because it covers over the common practice of not coding to an interface. If you want to expose poor design in a code base, remove the mocking decencies and see how hard it is to rewrite the tests.
Re: Paving the on-ramp to Java
#118Earlier quoted context omitted.
I beg to differ, as soon as they need a second file, import a dependency or use additional helper methods, they get to face all of it anyway. And then there is the issue with leaky abstractions when the code that gets compiled interfers with the ideal worlds that the compiler injects, and possible confusing error messages get generated. Like it happens with all guest languages that target the JVM pretending to be Jav…
> as soon as they need a second file, import a dependency or use additional helper methods, they get to face all of it anyway. The problem isn't the set of things students will need to learn, but the order in which they encounter them. Students write a one-file program before they write a two-file one, but because Java is optimised for large programs, today they encounter things like accessibility rules -- which exis…
Re: Paving the on-ramp to Java
#119Earlier quoted context omitted.
I beg to differ, as soon as they need a second file, import a dependency or use additional helper methods, they get to face all of it anyway. And then there is the issue with leaky abstractions when the code that gets compiled interfers with the ideal worlds that the compiler injects, and possible confusing error messages get generated. Like it happens with all guest languages that target the JVM pretending to be Jav…
> as soon as they need a second file, import a dependency or use additional helper methods, they get to face all of it anyway. The problem isn't the set of things students will need to learn, but the order in which they encounter them. Students write a one-file program before they write a two-file one, but because Java is optimised for large programs, today they encounter things like accessibility rules -- which exis…
Re: Paving the on-ramp to Java
#120Earlier quoted context omitted.
You can't really mock static methods though, so it makes testing harder.
Static methods should be treated like functions. Same input same output. Keep them small. If you find yourself needing to mock them they are doing too much.