Every now and again, me and my colleague will have to go back to some old code and completely forget how it was structured or how it works. This will prompt us to say something like, "Jesus, we really need to document this shit better," and resolve to do just that.
You can for example run Python code on a Spark cluster and the JVM can reference your Python objects in memory, which is nice for distributed computing.
The Python objects have to be cached using serialization though (pickle) because Java itself doesn't know what to do with them.
Since the interpreter ignores blank space, you can format the code so all the braces and semicolons are out of view and are just there to help the interpreter, while you look at the code through indentation.
public class Permuter{private static void permute(int n, char[] a){if(n == 0){System.out.println(String.ValueOf(a));}else{for(int i = 0; i <= n; i++){permute(n-1, a); swap(a, n % 2 == 0 ? i : 0, n);}}}private static voice swap(char[] a, int i, int j){char saved = a[i]; a[i] = a[j]; a[j] = saved;}}
I want to say kotlin is just java done right, but in reality kotlin is just Java wearing one of those hyper-realistic disguises like in Mission Impossible
Don't get me wrong, Kotlin, groovy and scala are all really amazing, and to be perfectly honest, I'd rather work in C#.
But I go where the money is, and right now that's java and C#.
Where I live it's 70% java, 30% C# (not a realistic number, there are a lot of other jobs, c++ is on the rise, but I'm just talking about proportions). I think it's because the city is full of big shot universities and the main ones focus on java over C# for whatever reason.
I haven't used scala or groovy but Kotlin is literally just Java with a more sensible syntax, to the point that you can just mix and match java an kotlin code at basically any point, not that you should, but you can. If you know one you know the other.
I never did much on Java besides college until a few months ago that we started a new project that had to be done in java/kotlin. It took almost no time for any of the Java developers and the non-java developers(me) to start using kotlin. I still hate it because it is still Java but at least the syntax is pretty.
Since the methods don't modify the state of the class, it makes sense they're static. Also the class has no state at all so it's a utility class. What bothers me is the absence of a private constructor
If you don't put it in Java is added by default by the bytecode compiler. Is necessary to specify so people using your classes / future developers instantly (I hope) recognise the role of that class in the system. Otherwise it could be misinterpreted as a strategy pattern or something else, adding fields and method and, essentially, making a god class (antipattern)
Oh sorry didn't know that without static methods you can't mess things up I'm just going to change every local variable to a field. Serious answer: adding fields to what would have been a procedures only module back in C days adds possible execution states, because you have instead of every possible computation that procedure makes, that number multiplied the number of states your class can have, i.e. every possible value of that field. So even form a purely abstract (and pointless) enumeration point of view you're wrong. Also, tell me where a unit test can't test a static method, by declaring expectations and asserting on the results. I'm not pro void methods though, because then you're clearly moving class methods in utility classes. There is a way of doing things wrong for every Java modifier. On one thing maybe we can agree.. stop making that damn classes final
It's not about testing the static methods, but other classes. Instead of easily mockable object you have a static method in your program and hence nice refactor ahead.
Happens every time, say you want to have runtime configurable parameter or want to log something. Staying 100% objective is safer and costs you if anything just few keystrokes.
You're right that what you describe can happen if one's not careful with static methods. We don't want c-like code after all. I always end up with one or two small utility classes for this reason, most of the time what I really want is a factory or a strategy, but for some stuff static utility classes are preferable imho. Let's say abusing with something is always a bad thing, each pattern has its scope
Say what now? That's wrong on just about every level. Ofc there is a point to static. No language can be moron proof, if you have no idea what you're doing, anything can break anything.
Rule #2: Everything that's been on the first 2 pages (50 posts) of trending posts within the last two weeks, is part of the top of all time, or is part of the common posts [list yet to be built] is considered a repost and will be removed.
If you feel that it has been removed in error, please message us so that we may review it.
57
u/FUCK_your_new_design Oct 15 '18
Is there a code formatter that does this?
201
u/hanna-chan Oct 15 '18
This looks like it should be a criminal offense to do this.
34
u/GDavid04 Oct 15 '18
so, javathon?
41
u/SignatureStorm Oct 15 '18
What in the actual fuck are those braces and semicolons doing?
16
u/Raidend Oct 15 '18
Python programmers should skip directly to kotlin instead of Java it makes more sense
4
u/Fulk0 Oct 15 '18
I need to speak to the admin of the sub, I had a stroke from looking at this and will need indemnification
3
u/Blake_Abernathy Oct 15 '18
π¬
6
u/[deleted] Oct 15 '18
What is it with python developers and static methods? π€
1
u/[deleted] Oct 15 '18
this makes my eyes hurt
1
u/[deleted] Oct 15 '18
My eyes are bleeding
1
u/[deleted] Oct 15 '18
Did this for an assignment once. Full marks!
1
u/zdko Oct 15 '18
I suspect the Python interpreter is abstracting away exactly this sort of shenanigan to the code in order to build out the AST...
1
u/Skthesoap Oct 15 '18
What theme is that?
1
u/DaarkChocolate Oct 15 '18
I feel like this is the type of thing to shock me at first, then grow on me
1
u/shakix99 Oct 15 '18
MY EYES
1
u/RadicalLarryYT Oct 15 '18
βIβm going to have to stop you right there!β
1
u/mocomaminecraft Oct 15 '18
oh god someone kill him for his sins
1
u/Paulsify Oct 15 '18
Why.
1
u/Plungerdz Oct 15 '18
Help. I don't like this because I like Java and respect it so much. Yet this shit is the most Pythonic masterpiece I've ever laid eyes on.
1
u/[deleted] Oct 15 '18
Scanning left to right: "this looks okay. I don't see anything that seems out of - Oh Jesus!"
1
u/j3sterPi Oct 15 '18
My eyes hurt! I want to take them out with the fu**** spoon
1
u/Rogocraft Oct 15 '18
Well they are jumping ships now that the python developers are removing master and slave terms and such to keep the undesirables at bay
1
u/Rudolph_OW Oct 15 '18
Dear lord
1
u/idlesn0w Oct 15 '18
I'm strangely okay with this but I feel like I shouldn't be
1
u/[deleted] Oct 15 '18
What the fuck are those brackets doing there????
1
u/jona250210 Oct 15 '18
This Looks Really weird xD
β’
u/XXAligatorXx Oct 15 '18
Your submission has been removed.
Rule #2 violation.
Rule #2: Everything that's been on the first 2 pages (50 posts) of trending posts within the last two weeks, is part of the top of all time, or is part of the common posts [list yet to be built] is considered a repost and will be removed.
If you feel that it has been removed in error, please message us so that we may review it.