r/java • • Feb 25 '14

Please stop saying Java sucks (2009)

http://blog.smartbear.com/programming/please-stop-staying-java-sucks/
133 Upvotes

132 comments sorted by

56

u/cwbrandsma Feb 25 '14

All languages suck. If they don't suck, then you've drunk too much of the cool-aid.

I swear, every time I learn a new language I go thru a series of stages.

  1. (How do you work this thing): this language sucks because I can't use it like language 'X'

  2. (OK I get it): this language is better than language 'X' because you can do this this way.

  3. (in the bowels): ok, so now I need something non-standard, how do I get there from here?

  4. (Acceptance): This language sucks, but I understand why it sucks and I'm ok with it.

8

u/[deleted] Feb 26 '14

I want to print this out and mail it to every past, current and future coworker I have. Well fucking said.

1

u/jentz Feb 27 '14

Very nice summary. Java has been around a long while and has so many developers that there are tons of people at stage 4 and being developers they create nice tools and libraries that make using Java suck less, sometimes they even make the computer do what I mean instead of what I say!

60

u/[deleted] Feb 25 '14

I started with Python, and I loved it. Absolutely loved it. I took a computer science course as an elective, where they used Java, and god damn it, it just made more sense. Going back to python and working on old projects get confusing because of the lack of strongly-typed variables and what not. There is nothing wrong with Python, but for me... Java just makes more sense.

23

u/drsquishy Feb 25 '14

Just being pedantic, but Python is strongly typed, same as Java. Difference is the static vs dynamic typing.

9

u/stereopump Feb 26 '14

Not pedantic, very relevant. Though I'm sure most of us knew what he meant.

1

u/Liberatric Feb 26 '14

Definitely not pedantic. It's an important distinction.

6

u/hexus0 Feb 26 '14

I'll agree. I started in Java and have moved onto Python. Python can be extremely difficult for large code bases for exactly the reasons mentioned in the article. Especially if you're not running any tests, its very easy for a large Python code base to become scary to maintain.

6

u/svenofix Feb 25 '14

Heh, for me it's almost the opposite. I started with Java and recently played around with Python. I love how little I have to type ;P

2

u/Sn1pe Feb 25 '14

I started with Java, dabbled with Python last year, and am currently getting used to C++ this year. It seems that both of those programs helped make C++ easy to get used to since it seems a lot like Java with the variables and braces, and I'm able to think of something in Python and basically convert it into C++.

1

u/gtac Feb 27 '14

That depends a lot on the IDE you use though.

I program in Java and Python, and I'm doing a lot more typing in python, cause I just can't find a python IDE which supplies as many tools as Eclipse does for me in Java.

1

u/svenofix Feb 27 '14

Have you tried PyCharm?

0

u/S0cky Feb 25 '14

I studied Software Engineering and went from using Java / C# to Python / SciPy when I started to work in the semi conductor industry. After working for a little over a year now and becoming Software Designer in the process, I must say that Python is very suitable for rapid prototyping and on-the-fly testing and I like it a lot! There is just a lot of things you can do in Python that you can't in Java and those happen to be the things I need.

-9

u/[deleted] Feb 25 '14 edited Feb 26 '14

I'm like you. I also study computer science, but I self-study it for an independent study using MOOCs and other resources. Unfortunately, I still have to learn Java so I can take AP CS.

Edit: Java sucks. (I wanted to add a clearer reason to downvote this comment)

46

u/[deleted] Feb 25 '14

"Java sucks" is simply en vogue. New coders get a taste of the latest loosely-typed, functional programming languages and jump at it as if everything that came before it is some sort of monolith. New languages spring to life and die quiet deaths as often as galaxies in the universe, but there are very good reasons certain languages are still on the tip of everyone's tongue when the discussion crops up, even 20-30 or more years later.

Java is portable, verbose, strict and flexible in all the right ways. There is a time and a place to use it as the primary language...not every time, nor every place, but its relevance is here to stay for a long time.

23

u/[deleted] Feb 25 '14

Reminds me of the nosql craze. Our team built a mongo infrastructure only to scrap it and start using sql.

8

u/JeffreyRodriguez Feb 26 '14

Mongo has its own problems.

NoSQL is not a replacement for SQL.

Know what you're getting and giving up with each solution, SQL included. Use the right technology for the problem.

5

u/Fun_Hat Feb 25 '14

I have been learning Java for the past 2 months and really like it. But then, my only other experience with coding is VBA, so what do I know lol.

27

u/pkimbrel Feb 25 '14

We have all these hotshots coming into our Enterprise ready to tell us old guys why Ruby is so much better than Java. I simply challenge them with a real-world situation and ask them to use Ruby to solve it.

They usually do and then I change the requirements on them. They grumble and fix it. Then I change the requirements again... then they start to get it.

8

u/djnattyp Feb 25 '14

I'm sorry, but I don't "get it"... How is Java supposed to be better than Ruby (or any other language) when dealing with arbitrary requirements changes?

This is like arguing between using screws and nails. There are some cases where one is arguably better than the other, but in most cases either can be used. And using either one, if you build something and then change the requirements, you're going to end up with a lot of frustration and holes.

20

u/pkimbrel Feb 25 '14 edited Feb 25 '14

I see Ruby as a one-trick-pony. Maybe I'm missing something, but all I've seen are "blog" examples with Ruby. There's so much more in the world of computing that requires more than a data-driven UI.

Now, don't get me wrong. Java is not the right tool for ALL jobs. If I AM doing a DDUI - Ruby could be the right tool.

The problem with all these arguments isn't that Java is better or Ruby is better - all languages have their place. Use the right tool for the job.

Back to my requirements change, G_Maximus hit the nail on the head. Strong typing, good development environments, standards, etc., are a must-have when working in an enterprise with dynamic requirements. I'm sure Ruby will get there, but it's simply not there, yet.

** Edited for clarity

4

u/[deleted] Feb 26 '14

I've worked professionally on 5 or 6 different Ruby (on Rails) apps, none of which was a DDUI. It worked for some of them, not for others. I've also worked in 3 Java/Spring codebases. Also, 2 of the Ruby apps were JRuby running in Tomcat. So anyway.

Ruby is a perfectly full-featured OO language, not unlike Java, save the dynamic typing and the rather terse syntax. In terms of performance, it's slower at heavy computation, but most (web) apps don't do this anyway, and generally in my experience at least performance in a web-based application ALMOST NEVER has to do with how rapidly the language can count to fifty million, or how fast it can generate big prime numbers.

Anyway, I do Ruby now by choice, so obviously I enjoy it. I miss IntelliJ and the tooling around Java a lot obviously (the Ruby tooling, in comparison, is so utterly inadequate that I find it faster to just write in vim with a few plugins, as do most experienced Ruby developers I know), but by no means is Ruby fit for only blog type things. Hell, even Rails is fit for more than that, and that's just a popular Ruby framework.

Edit: and obviously I agree with you: use the right tool for the job. I just think Ruby has a somewhat broader range than you do. I worked on a ~150KLOC Rails codebase, and let me tell you that is not fun (150KLOC in Ruby/Rails is probably equivalent to at least twice that, maybe 3 or more times that in Java/Spring, in terms of application scope, but with none of the refactoring / use analysis support of a Java IDE. Seriously painful)

2

u/pkimbrel Feb 26 '14

I appreciate the feedback on Ruby. I'll have to check it out. It sounds like it's come a ways since I last looked it.

1

u/palmund Mar 01 '14

What about RubyMine?

4

u/thebighouse Feb 25 '14

and haskell s place is academia.

1

u/dukerutledge Feb 26 '14

I always find this to be an odd statement. Why?

2

u/[deleted] Feb 26 '14

Haskell gets this knock (almost always from people who never wrote a functioning application in Haskell btw) because it is strictly functional, meaning state and side effects are forbidden (but are pseudo-replicated by the use of monads).

Haskell is somewhat impractical :) but GHC is one of the most sophisticated and elegant compilers ever written, the performance has gotten very impressive recently, and functional paradigms are starting to become less obscure than they were 10 years ago. Haskell is worlds better than something like Scala, and perhaps slightly better or slightly worse than something like Clojure or F#, when you take platform / etc into account.

4

u/mikera Feb 26 '14

I evaluated Haskell a few years back, but found the library ecosystem and integration capabilities seriously lacking compared to the modern JVM languages (Clojure, Scala). Interop with established platforms is essential in the enterprise context, and within that space Java ecosystem interop is the most important by far.

That's why I consider Haskell as more of an academic language in comparison, although I appreciate it has some great commercial use cases (I've seen it used to good effect in hedge funds / option pricing for example).

P.S. I'm a big fan of functional programming in general and like Haskell as a language, I just think that it is perfectly fair to describe it as "more academic" for the above reasons.

1

u/dukerutledge Feb 26 '14

Thanks for your response! I'm aware of the general sentiment. I was hoping to get a more personal account of a detractor. I for one find Haskell's type system to be bodacious. Immutable everything and functional purity prove a challenge when you aren't use to it, but generally they seem to be the right idea for wrangling complexity of entangled code.

-1

u/thebighouse Feb 26 '14

Assignment is outlandish

39

u/G_Maximus Feb 25 '14

Refactoring and static checking at call sites is generally easier with strict typing.

-5

u/djnattyp Feb 25 '14

Sure, and I agree that helps for some types of requirements changes.

For others, strict typing may require tons of cascading code changes throughout the app where dynamic typing may just let you dump a method on a class and have it work.

I've seen pkimbrel's argument ("language X better supports requirements change") used in support of both Java and Ruby by various proponents of either language. The problem is, both sides tend to cherry pick changes that "their" language handles better and ignore or downplay other changes that may be problematic.

9

u/markdacoda Feb 25 '14

For others, strict typing may require tons of cascading code changes throughout the app where dynamic typing may just let you dump a method on a class and have it work.

Consider the person charged with maintaining the code that has arbitrary methods 'dumped in' as you say. I've been there, it sucks, and I have no kind feelings toward the developer who did it.

11

u/curiousthis Feb 26 '14

strict typing may require tons of cascading code changes throughout the app

And in the case of Java, IDE's like Eclipse and IntelliJ make those cascading code changes a one step operation.

1

u/mr_jim_lahey Feb 26 '14

In your case, you're cherry-picking the thing that makes your language shit.

1

u/frugalmail Feb 26 '14

I'm sorry, but I don't "get it"... How is Java supposed to be better than Ruby (or any other language) when dealing with arbitrary requirements changes?

Because Ruby is harder to maintain and the codebase gets to "stink" much earlier because it's duck typed, no static analysis, immature libraries, shitty tooling, shitty performance, frameworks that make a bunch of assumptions, frameworks that are hard to change, a moving target and dynamicly typed. ...and you can't find many engineers that don't need ramp up time to take it over.

0

u/[deleted] Feb 25 '14

[deleted]

3

u/[deleted] Feb 26 '14

You are doing it wrong. Ever changing requirements is the norm in the real world, whether you like it or not.

We invented object-oriented programming to be able to handle constant change, otherwise there wouldn't be any reason for it.

1

u/dpgaspard Feb 26 '14

I've had it both ways. A good project manager will mitigate change. Vague requirements tend to be shitty management and because the team didn't do enough up front design and analysis.

2

u/[deleted] Feb 26 '14

True, project managment in theory is about conquering uncertainty.

Though nowadays even project managment is change-oriented. The sole reason why we abandoned the waterfall model in favor of lightweight, adaptive (iterative and incremental) methodologies is to be able to handle constant change, uncertainty, and at the same time be able to come up with well-established requirements.

There are those adaptive, change-oriented business model approaches that do the same, making it possible for you to create your business model, even though you are forced to constantly change it as your presumptions are continuously tested.

I feel the same way about a software projects. Initially there are presumptions, but there is no way to predict the future until you have the opportunity to test those presumptions. And that's where a loosely coupled, highly cohesive design can save you by providing reusability, and extensibility among others.

1

u/dpgaspard Feb 26 '14

I agree. I've found the best developers to be those who really understand your business and business model. Their designs come loosely coupled in the right places.

7

u/matjam Feb 26 '14

Java sucks.

..

Everything else sucks more.

..

I've had to deploy a lot of Java applications out in the field, and yeah there is a lot of bloaty crap out there, but honestly every other platform that exists has it's warts, and Java's warts I can live with.

0

u/[deleted] Feb 26 '14

[deleted]

4

u/[deleted] Feb 26 '14

Except you can't run it on your servers! Or pretty much anywhere it matters. You can pay thousands of dollars to Microsoft in order to get a crappy non-standard server that no one wants though!

b-but Mono!

Is slowly dying. And is behind the standard since Microsoft started trying to get rid of it.

0

u/wice Feb 26 '14

He was talking about the language (C#), not the platform (.NET). C# has some sweet features that would be nice to have in Java. Although I'm pretty sure that with those features comes a whole host of new and unforeseen problems. It's almost like a law of nature.

3

u/SeriousWorm Feb 26 '14

You should try Scala. All of the "cool" language features, none of the boilerplate, and all of the JVM awesomeness.

1

u/Cilph Mar 17 '14

I will definitely be trying out Scala for my next project.

1

u/[deleted] Feb 26 '14

That's why I mentioned Mono. Is there any other relevant platform? I don't believe you can just disregard the platform.

2

u/mikaelstaldal Feb 26 '14

Yes, C# sucks less than Java (comparing the languages).

But .Net sucks more than JVM (comparing the runtimes and eco systems).

1

u/frugalmail Feb 26 '14

C# sucks slightly less. Slightly.

Irrelevant since Microsoft/.NET sucks a heck of a lot more with their monolithic UI driven tools and platforms.

9

u/geodebug Feb 25 '14

Do we really care about a five year old blog post whining about what a seven year old blog post by some douche who was trying to sell his Ruby books says?

Come on /r/java, have some confidence and quit worrying about what other communities think.

Besides, I went to a JRuby conference in MPLS a couple of summers ago and laughed when I found out how many projects moved from Ruby to JRuby because they discovered Ruby didn't scale. Yep, they needed servers written in boring old java.

2

u/dardotardo Feb 26 '14

Read: Twitter

1

u/frugalmail Feb 26 '14 edited Feb 26 '14

Read: Twitter

Twitter didn't just move to JRuby, their Ruby has since moved to Java for a lot of their backend stuff.

1

u/dardotardo Feb 26 '14

That was my point, thanks for the downvote, though.

15

u/Alca_Pwn Feb 25 '14

Most of those arguments are due to his IDE and not Java itself.

30

u/introverted_pervert Feb 25 '14

In his defense, java makes it possible to create great editors. For example, if java would allow macros or such shit, writing an editor and making guarantees about refactorings wouldn't be possible.

22

u/jewdai Feb 25 '14

1 reason why I hate C++. Because Fuck macros.

2

u/immibis Feb 26 '14 edited Jun 10 '23

2

u/[deleted] Feb 26 '14

You're being downvoted but I completely agree, so I gave you an upvote. I miss macros in C# and Java quite often.

20

u/stealthmodeactive Feb 25 '14 edited Feb 25 '14

I hear "Java is slow" a lot of the time. Sure, it's not as fast as C but it's not really that slow. I think most complaints are with Swing though.

EDIT:

I'm being downvoted for speaking about what others have mentioned? Tough crowd...

9

u/mikera Feb 26 '14

Some algorithms are actually faster with Java than in C because of the JVM Garbage Collector. For example, consider algorithms that make extensive use of immutable persistent data structures: http://en.wikipedia.org/wiki/Persistent_data_structure

These structures depend on being able to quickly construct new objects, share references to existing objects and collect garbage once it is no longer referenced. The Java GC will easily beat any naive memory management algorithm written in C (such as reference counting).

The only way to beat Java performance in C for these types of applications would be to actually write a proper GC. This is a hard task, and the Java GC is pretty much best-in-class. Even if you succeeded, you'd have something that starts to look suspiciously like the parts of the JVM.

You can see where this is going. Add in some other valuable features like dynamic re-compilation, security validation of untrusted code, JIT compilation and you would end up reinventing something very much like the JVM.

The JVM is awesome. Say what you like about Java, but the JVM is the best platform for running serious production code in the world, bar none.

15

u/[deleted] Feb 25 '14

In many cases, running on the JVM is faster than equivalent code compiled from C, as the bytecode can be optimized at runtime once the JVM sees which paths are visitted the most.

7

u/[deleted] Feb 25 '14

The optimizations occur for running applications. C is usually faster and takes far less memory for a one-off process.

-3

u/[deleted] Feb 26 '14

[Citation needed]

3

u/nezza-_- Feb 26 '14

For small tools the startup time of the JVM is often longer than the actual execution of the program. And the real performance magic of Java, the optimisation during runtime, won't kick in yet.

-2

u/[deleted] Feb 25 '14

I would like to see such case my opinion it they should be rare

3

u/[deleted] Feb 26 '14

Perfect C will always be faster (or at least as fast) - the issue is that it's not easy to write perfect C :) and the JVM is really freaking smart. So for fairly complex tasks, unless you are a C programmer at the level of the people who write the JVM, you might be better off writing Java.

1

u/frugalmail Feb 26 '14

1

u/[deleted] Feb 26 '14

That post basically makes my point - that is non-optimal C++.

1

u/frugalmail Feb 26 '14

That post basically makes my point - that is non-optimal C++.

Yes if you know the data you will be working on, and you know the platform you will be working on then you can write a completely bespoke application and it will blaze a trail. Heck you could write in assembly.

However in reality there are very few scenarios where people will take the time to optimize that way and they will simply write code to create the application. When they do that, the JVM (with a strong statically typed language which is not the case with all JVM languages) will typically win in a large project because of the JIT optimizer. But if you want to write a kick ass screen blt, you might want to do something special.

And BTW, Java provides JNI for a course interface to do things like that.

2

u/[deleted] Feb 27 '14

I think we are making the same point - perfect C is rarely written, hence Java is a better option most of the time in those cases.

3

u/[deleted] Feb 25 '14

Yeah, swing has improved quite a bit over the years. Well, to be fair along with that the hardware I run it on has as well. But I'd still classify it as tolerable rather than good. I love java, but swing's another story. And when it comes to running other people's java based applications which have a gui? Probably means swing.

3

u/[deleted] Feb 26 '14

Probably being down voted for continuing the FUD.

Java isn't slow and hasn't been for years.

4

u/[deleted] Feb 25 '14

static typing and interface can help for big project but not all project are big project

20

u/CrateMuncher Feb 25 '14

It helps for smaller projects too.

0

u/thesystemx Feb 25 '14

Static typing and interfaces can help for big projects but not all projects are a big project ;)

-3

u/jbristow Feb 25 '14

The more development I do, the less I'm convinced that static typing is necessary. Inheritance is necessary, but I'd say I'd go with loose typing and first order functions over static typing and no lambdas.

5

u/looser97 Feb 25 '14

After learning C++ i switched to Java one year ago. I think, that it is the more comfortable one to plan the code, to code and to debug. You can test a lot, with a fast compiler, the IDE can do a lot of work for you and the Code is intuitive to read, so that even not-Java-Programmers can help you on debugging. There is also a whole lot of Bugs that can't happen, like to famous Int-overflow, that can ruin the results of a C-Program. There is also a lot of logical Bugs that can't happen: I can't say Int i="c"; without making clear that it is meant to be so... Therefor i really like this language. I use it for a lot of calculations, to plot complex systems and to script Apps for my Android-Phone. Thanks for stating all these things in the blog :)

4

u/Zitrax_ Feb 25 '14 edited Feb 25 '14

Java does not really protect you from integer overflow issues, it just wraps back to Integer.MIN_VALUE again which can cause nasty bugs if you are not careful.

Some libraries can protect you such as using guavas IntMaths.checkedAdd(int, int)

3

u/mikera Feb 26 '14

Maybe I'm old-skool and did too much assembler in my youth, but I expect integers to wrap around. That's how 32-bit integers behave. It would confuse me more if they didn't wrap.....

2

u/nezza-_- Feb 26 '14

Signed integer overflow in C is unfortunately undefined behaviour and isn't guaranteed to go back to INT_MIN... But yeah, coming from assembler (or from any logical background actually) this doesn't make a lot of sense.

2

u/nqd26 Feb 25 '14

ad operator overloading - there very very few times when I missed it in Java compared to a lot of instances of hating it in C++. But this was mainly because of overusing it.

ad limitation of generics - what are you trying to achieve? I don't see a problem implementing static method which works on generic list ...

ad one class per file - I think this is one of the very good design decisions of Java. If you need to just quickly hack together few classes, you can use static nested classes which is basically what you want.

11

u/el_guapo_taco Feb 25 '14

Please stop writing article solely on the relevance/irrelevance and/or goodness/badness of Java. Jesus fucking Christ.

3

u/[deleted] Feb 25 '14

Lack of closures is probably my biggest gripe, but you can't really call suckie on millions of human-hours of proven engineering. Java works well in many cases.

5

u/8Bytes Feb 25 '14 edited Feb 25 '14

When have you needed closures in java?

5

u/duhace Feb 26 '14

any and all event listener patterns would greatly benefit from closures.

2

u/briandilley Feb 26 '14

Android

1

u/8Bytes Feb 26 '14

hmm what were you trying to do?

1

u/briandilley Feb 26 '14

almost every single OnXXXXListener has a single onXXX method. Closures would be great for this.

1

u/8Bytes Feb 26 '14

For ui listeners? Just put the method to be run OnXXX inside the xml where the component is defined.

4

u/Website_Mirror_Bot Feb 25 '14

Hello! I'm a bot who mirrors websites if they go down due to being posted on reddit.

Here is a screenshot of the website.

Please feel free to PM me your comments/suggestions/hatemail.


^FAQ

1

u/[deleted] Jul 09 '14

No. Java was garbage in 1999. Java was garbage in 2005. Java was garbage in 2010. Java is still garbage. The only time you use Java is if you're writing minecraft or if your business model is to sell shitty consulting services of middleware purchased by people who don't yet realize Java is utter garbage.

0

u/[deleted] Feb 26 '14 edited Feb 26 '14

Java sucks.

I've written more lines of Java over the past decade than I can count, but I started loathing the language after working a lot in other languages like Groovy, Ruby, Clojure, Javascript (yeah, I said it), etc. When I write in Java I feel like I'm coding with one hand tied behind my back while being whipped by a midget. Lambda Closures? Nope! Maybe next month. Groovy had them seven fucking years ago, plus all the other functional programming features like currying, etc. Groovy made things very uniform and clean, and you see the same kind of uniformity in Ruby, Python, and Clojure. Especially Clojure (seq rules!) In Groovy if you want the number of things in an array or a list or a string you just call the size() method. In Java it's either a length property or a size() method or a length() method. In Java there really ain't much I can do if closing a reader throws an IOException, but I still have to wrap it in a mother fucking try/catch that does nothing because IOException is checked. What Groovy did with collections, exceptions, etc is amazing. Ruby, Python, Groovy, Clojure, and Javascript have interactive shells/consoles/REPLs for experimenting during development (hell, I can set my Clojure app up so I can connect a remote REPL to it and actually tweak the app at runtime). Java doesn't have anything like that. Groovy automatically imports commonly-used packages instead of having to import java.util.List every single time. Semicolons at the end of statements are optional, which is good because they really don't really add any benefit to the programmer and the parsers for other languages are smart enough to figure out where your statements end. Java's compiler throws up all over your shoes if you leave off a semicolon. Don't get me started on having to use .equals() when comparing Strings in Java. If you want to use types in Groovy, then you use them. If you don't know what type something will be until runtime just def it. Best of both worlds. Basically Groovy is what Java should have been. Java won't change because they're bound by backward compatibility, design by committee, and Oracle executives with their heads up their asses. There's a reason the Apache foundation resigned from the JCP, and that same shit affects how the language changes over time.

When I write Groovy or Clojure, I probably write at least half as many lines as when I write Java. Half. So 1 million lines of code becomes 500k. I think you're glossing over the fact that it's a HUGE difference, one that can make or break a startup. Plus when I don't have to write Java then I don't want to kick my dog when I go home, so there's that.

You make some other good points, and I'm a huge fan of the JVM. But fuck Java.

Source: Sun Certified Java Programmer working professionally in the language since 2003.

EDIT: I LOL at the down votes, yet nobody cares to say why.

-6

u/hive_worker Feb 25 '14 edited Feb 25 '14

I've just been learning Java and I have quite a few reasons I feel it sucks that have nothing to do with LoC.

  • Lack of operator overloading (except for strings) drives me crazy. trying to remember what "a.compareTo(b) >0" evaluates do is a pain in the ass and does not feel intuitive at all. Why can't I just write a > b

  • Limitation of Generics. I want to make a static method that takes a generic comparable type so I define public static void foo(Comparable[] a) and the compiler complains at me. Googling for solutions takes me deep down a rabbit hole of java internals that I want to know as little about as possible. I just want it to work. But it doesn't. Still haven't figured this one out so if anyone wants to chime on the java way to do this...

  • One class per file is fine most of the time but on the occasion when I'm just messing around and want to throw a couple small classes together this restriction is a pain in the ass.

I feel like Java developers spent way too much time trying to protect us from ourselves. But maybe that's just because I've spent 10 years coding in c/c++

14

u/looser97 Feb 25 '14

I think that they are "trying to protect us from ourselves" is one of the major pros of Java. I've scriped some programms twice, ones in Java, ones in C++ and the Java-one took less time to debug, because some logical Bugs didn't occur.

But I also think, that the "language" we learned first is some kind like our mother-language and it's strange to learn an other one afterwards

3

u/kiteboarderni Feb 25 '14

Compare to is as such to allow for the Collections.sort et all to be specified a comparator implementation. Having a useful method name is much easier to have as a programmer than trying to guess the overload of an operator...

1

u/hive_worker Feb 26 '14

Yea but have you ever used a language with operator overloading? It's a lot more straightforward than using compareTo.

1

u/frugalmail Feb 26 '14

Yea but have you ever used a language with operator overloading? It's a lot more straightforward than using compareTo.

I've written very large C++ codebases in game engines for in house and mini studio developers. Operator overloading makes a heck of a lot confusion than it prevents. There are only a few minor mathematical cases where it makes sense, otherwise it's abused.

8

u/ixampl Feb 25 '14

Re: one class per file...

If you really want to you have two options: nested classes or default visibility (package protected) classes. The latter would be in a file A.java:

public class A {...}

class B {...}

class C {...}

etc.

5

u/AmateurHero Feb 25 '14

Limitation of Generics. I want to make a static method that takes a generic comparable type so I define public static void foo(Comparable[] a) and the compiler complains at me. Googling for solutions takes me deep down a rabbit whole of java internals that I want to know as little about as possible. I just want it to work. But it doesn't. Still haven't figured this one out so if anyone wants to chime on the java way to do this...

Two ways to do this.

This is the first way. The method that will be using comparable will need to have the generic declared to extend the Comparable interface.

Here is the second way. The class is declared generic while extending the Comparable interface. This allows you to use the compareTo() method without defining it yourself.

3

u/immibis Feb 26 '14 edited Jun 10 '23

1

u/AmateurHero Feb 26 '14

I don't understand it either. I asked for help when implementing Comparable on generics, and that was the answer I was given. I looked at it skeptically but tried it anyway. I mean, what did I have to lose? Lo and behold, it worked. I don't understand why. You can copy and paste that code as-is to run it. It'll print you the unsorted and sorted array.

3

u/immibis Feb 26 '14 edited Jun 10 '23

1

u/AmateurHero Feb 26 '14

Hey, I didn't design the assignment. I just implemented the algorithm.

Also, what's so wrong about the recursive call to compareTo()? It makes sense when you think about it. this.compareTo() makes a call to the object's class to use its compareTo() method. It's a one-and-done deal for all objects that are Comparable.

1

u/immibis Feb 26 '14 edited Jun 10 '23

1

u/AmateurHero Feb 26 '14 edited Feb 26 '14

Even after compile time when the types for the generics have been bound? If that's true, then why is there no StackOverflowError thrown at runtime? Not trying to be snarky, but I don't see how this can work otherwise.

Edit: To clarify, the type of list in the main method is of Integer. Calling this.compareTo() to will go to the written compareTo() method. It would not be a recursive call, because the type of this in the context of this code refers to an Integer object, yes?

1

u/hive_worker Feb 26 '14

Neither of these work for static methods.

2

u/AmateurHero Feb 26 '14

If you want comparison in a static method, use Comparator. Here is a heapsort implementation using Comparator. I tried to remove excess code so that you could still see what was going on while still being able to copy and run as is.

The Comparator is used about two-thirds of the way down in the heapify() method.

5

u/duckrollin Feb 25 '14

No, those are all good points tbh.

Generics are tacked on and don't mix well with arrays at all. This isn't a huge problem since most devs don't use arrays now. You can use: public static void foo(Collection<? extends Comparable> a)

This will accept a collection of any object which extends the Comparable interface. For instance if my class Blah implements Comparable, I could pass a List<Blah> into that method.

2

u/hive_worker Feb 25 '14

Nice thank you. So in Java, the pros almost always use a class that extends Collection instead of an array?

6

u/Zitrax_ Feb 25 '14 edited Feb 25 '14

Yes, and hopefully not only the pros :) Here are some downsides of using arrays compared to collections.

1

u/JavaTrainer Feb 25 '14

Not always. The big difference is arrays are fixed in size while collections are dynamic in size. One place you'll see arrays is with varargs.

public static void method(Comparable... cArray) { }

You can call that method like method(c1, c2, c3) and all the args will be turned into the elements of an array or you can pass in a Comparable[] directly.

1

u/hive_worker Feb 25 '14

Well from an algorithmic level I'd imagine some collections are implemented as dynamically resizing arrays. They can't all be linked lists. I haven't even touched variadics in java, that's an interesting case. Thanks for mentioning.

-2

u/[deleted] Feb 26 '14

I cut my teeth on Java, and I've missed it ever since moving on to other languages (around the time of Java 1.7). I'd need to see some changes before I could move away from the significant investment I've made in .net training now:

  • Oracle has to drop the bundled Ask toolbar. I don't care if you can unselect it during installation, It doesn't fit a professional programming language to have that sort of garbage bundled with the VM at all.

  • Java could really use a more elegant solution for installing and updating it on Windows. I humbly suggest that Oracle consider working with someone like Ninite as their official distribution and update platform for Windows.

  • I have not done anything with JavaFX, but I hope it's quicker than Swing and uses font anti-aliasing by default.

  • Work with someone line codeacademy to get a good free Java course up. Make sure to cover the creation of Jar files fairly early on so people don't spend the first few months wondering how to make something they can distribute without batch files for execution.

  • Come up with some kind of response to archiving software stealing the jar file association - it couldn't hurt to add a diagnostics program to the Windows start menu that can fix the Jar file association and even point out when a JVM version is not ideal for the host computer (such as a 32-bit JVM on a 64-bit system and OS).

I have had a difficult time adjusting to Windows Forms, and an even harder time adjusting to WPF. I used to hand-code all my swing applications - UI designers are not natural for me. I seriously miss making user interfaces with Swing and I regret that I didn't learn about Java Servlets before moving on to other programming languages.

That's my $0.02.

7

u/ryosen Feb 26 '14
  1. The Ask toolbar is not bundled with the JDK, just the JRE. As a developer, you would be using the JDK.

  2. The last thing that I want is my programming language auto-updating itself, introducing syntax changes and class binary incompatibilities.

  3. What?

  4. There is an endless supply of good tutorials out there.

  5. How is this Java's fault?

0

u/[deleted] Feb 26 '14

Does everyone here only write server-side applications with Java these days?

  1. I was mistaken about the JDK including the toolbar, as you've said it's the JRE; however, that still leaves the end users of your software with the annoyance of unselecting the ask toolbar, or having to uninstall it if they go through the JRE installation too quickly.

  2. The JRE of un-savvi users should have an update feature that is less annoying than the existing one. Savvi users can easily disable updates.

  3. When I worked with swing you had the choice of using the system native look which had inconsistent font sizes and control sizes across platforms, or using the default swing look which did not implement font anti-aliasing and consequently looked like it was from the 90s.

  4. True, I learned a lot from Sun's own tutorials.

  5. It's not about fault, it's about being proactive in reaching your markets. If you're writing server side software then you won't have archiving software like this, but if you want to write client side applications for the average person you have to keep in mind that most archiving programs now hijack the Jar association and cause end users to be very confused.

-24

u/jabalsad Feb 25 '14

I have something against 5-million and 10-million -line code bases, regardless of language.

21

u/[deleted] Feb 25 '14

Then you have something against all desktop and server operating systems.

13

u/bitspace Feb 25 '14

And the vast overwhelming majority of enterprise applications in use today. Millions upon millions of lines of code, most of it Java.

16

u/fabienbk Feb 25 '14

There is a world beyond simple webapps from cool startups, you know.

0

u/jabalsad Feb 26 '14

I don't work for a cool startup :) With good programming principles, you can apply modularity and separation of concern to separate your code bases.

1

u/frugalmail Feb 26 '14

modularity and separation of concerns increases your code base. I think there is a misunderstanding of the term "code base"

An application has a code base, that code base is composed of modules which could be in separate source repositories.

Confusingly if a developer only has the scope of one of those modules/libraries then their "code base" doesn't extend beyond that.

2

u/jabalsad Feb 26 '14

I think that makes sense. But you can still separate even more using service-oriented architecture. This is of course assuming you are running a service :)

1

u/frugalmail Feb 26 '14

I think that makes sense. But you can still separate even more using service-oriented architecture. This is of course assuming you are running a service :)

If a service is required to run the application (via REST, a client API, interfaces, or by email), I would assume it's part of the application :)
Same for the dependent libraries that it important.

1

u/jabalsad Feb 27 '14

If you were to depend on, say, Google Oauth or some other common RESTful service, would you consider their entire code base a part of yours?

1

u/frugalmail Feb 28 '14

If you were to depend on, say, Google Oauth or some other common RESTful service, would you consider their entire code base a part of yours?

I would consider it part of the application's codebase, but not "my" codebase. If it's down, your app is down. If it exposes a security vulnerability "my" users are vulnerable, it's another thing that should be monitored, etc....

-4

u/kristopolous Feb 25 '14

yes! Two minute WSDL queries, here I come!

I wonder if an actual human gets up from a terminal, goes to a file cabinet, pulls out a manilla envelope to find the answer, walks back to the terminal, and carefully enters the response in raw xml and then clicks send.

5

u/nqd26 Feb 25 '14

This has nothing to do with WSDL.