339 points · by snupples · 12y ago · 425 comments
But it's not making a good point. It's not even close. I wish people would stop voting it up.
- "In Java, you can forget about doing it in the cleanest or the best way, because that is impossible." -- cleanest in any language? Or cleanest for Java? Of course the "cleanest" way for Java is possible, and it does matter -- there is a huge difference between "clean" Java and unclean, and anyone who says otherwise is a Java pretender. And arguing about "cleanest for any language" is just a proxy for a language flamewar.
- "And nobody can glare at you and demand to know why you used 576 classes when you should have used 50, because in Java doing it with only 50 classes is probably impossible." -- The "Har-har-so-many-classes-and-don't-even-get-me-started-on-variable-names" argument. In Java, as in any language, you can over-design, or you can under-design, or you can design just what you need. The number of classes may end up higher than in other languages, but this argument is silly and tired, and yes, length is one of the tradeoffs of Java. An IDE (gasp!) should make that largely irrelevant.
- "The code was ridiculously verbose, of course, but that was not my fault. It was all out of my hands." -- This word "verbose" keeps being thrown around as an insult, but nobody brings up the tradeoffs. Verbosity has a purpose, just like brevity and terseness do. And of course it's never out of the programmers' hands. Once given a language, it's all relative.
There's more, but I'm arguing with a person who believes that a question about stdin and stdout is a proper gateway for measuring skill toward any programming problem ever.
There's actually something quite liberating about languages that deny you any clever solutions. Just write code that works and don't worry about whether you could have used <fashionable programming concept X> instead. I found Go to be quite refreshing for the same reason - the standard library is pretty small and the language lacks anything particularly magical, even some stuff that Java has like generics. The end result, however, is code that is very easy to read and write for anyone who learned imperative programming in the last 30 years.
That's a common anti-intellectual fallacy about why people code in higher level languages. High level languages are attractive because they let you write code faster and make your code easier to maintain, and not because they're "fashionable".
>There's actually something quite liberating about languages that deny you any clever solutions
To me, "deny[ing] clever solutions" translates to "this code is going to be a pain in the ass to write because I'm going to waste time fighting the language to get what I want." Programmers learn to avoid unnecessarily complicated code as they gain more experience. Mature programmers should have the freedom to exercise their judgement about what kind of code is appropriate.
Writing code faster is not my problem. The problem is building systems (that work) faster and this need sometimes requires using higher-level abstractions that maybe allow for more modularity, that maybe are more composable, or maybe are safer to use (and I'm specifically thinking here of concurrency, parallelism, asynchronous I/O, etc...). Higher-level abstractions is my goal when learning a new language (this or gaining access to another platform).
"clever solutions" is indeed an unwarranted euphemism that people use. But we are ending up having such discussions, precisely because we aren't defining well what we are talking about. Writing less code is a subjective problem. Not being able to build and/or work with a certain abstraction is an objective problem.
Maybe, maybe not. But at least 2 of the 3 points that you made are not true of JavaScript. Also, the whole "write code faster" has always been perplexing to me. The speed at which you write code is never significantly different between any two mainstream languages to really matter in the end, especially since the lifetime of a piece of software is dominated by maintenance.
And I don't know what you mean by "High level language". Java is a high level language.
>To me, "deny[ing] clever solutions" translates to "this code is going to be a pain in the ass to write because I'm going to waste time fighting the language to get what I want."
There's clever and then there's too clever.
My problem is that the solution in a slightly more expressive language is equally obvious, so I have to fight my own rage at java for its stuttering and clumsy excuse for closures. Fighting the language, on the other hand, is when I try to write a conditional or loop in sh.
This isn't a bad tradeoff though. Elegance means generally gains in maintainability, possibly with lesser costs in the actual development. And thinking about elegance in code is the first step to writing better, more maintainable code.
> For example... should I use map or reduce here, or maybe an iterator, or... oh fuck it, I'll use a for loop. It turns out that the old-school for loop works just as well despite earning you precisely zero style points.
I usually stick with for loops because they are clear. Remember:
elegance is about simplicity and clarity. If you sacrifice either of these, you are reducing the elegance of your code.
And a lot of thought went into Unix, as evidenced by its longetivity and long lasting tradition of its phylosophy. To date it's the oldest family of operating systems and at the same time, the most popular. Anybody that thinks the "worse" in the "worse is better" argument is about not carrying, is in for a surprise: http://en.wikipedia.org/wiki/Unix_philosophy
Even in the original comparisson to CLOS/Lisp Machines outlined by Richard Gabriel, he mentions this important difference (versus the MIT/Stanford style): It is slightly better to be simple than correct.
But again, simplicity is not about not carrying about design or the implementation and in fact the "worse is better" approach strongly emphasises on readable/understandable implementations. And simplicity is actually freaking hard to achieve, because simplicity doesn't refer to "easy", being the opposite of entanglement/interwiving: http://www.infoq.com/presentations/Simple-Made-Easy
"Worse is better" is, ultimately, an argument against perfectionism. Many of the features of Unix could have been implemented in a "better" way, and these ways were known to people working at the time. But it turns out that those "better" options are much more difficult to implement, harder to get right and are ultimately counter-productive to the goal of delivering software that works. We can set up clear, logical arguments as to why doing things the Unix way is worse than doing things another way (e.g. how Lisp Machines would do it), but it turns out that the Unix approach is just more effective. Basically, although we can invent aesthetic or philosophical standards of correctness for programs, actually trying to follow these in the real world is dangerous (beyond a certain point, anyway).
I think that's pretty similar to the OP's argument that, whilst Haskell is clearly a superior language to Java in many respects, writing code properly in Haskell is much harder than doing so in Java because, probably for entirely cultural reasons, a programmer working with Haskell feels a greater need to write the "correct" program rather than the one that just works. Java gives the programmer an excuse to abandon perfectionism, producing code that is "worse" but an outcome that is "better".
I think I know what you're getting at, which is that a comparison between Unix and the monstrous IDE-generated Java bloatware described in the OP is insulting to Unix. On this you are correct. But for "worse is better" to be meaningful, there still has to be some recognition that, yes, Unix really is worse than the ideal. Unix isn't the best thing that could ever possibly exist, it's just the best thing that the people at the time could build, and nobody has ever come up with a better alternative.
Use the least powerful tool that solves the problem. A map is less powerful than a fold (reduce), so use that if you can. A fold is probably less powerful than a for-loop, so use that if you can. An iterator is probably less powerful than a for-loop, so use that if you need the more streamlined accessing of elements rather than a fine-grained, indexed loop.
For loops have the advantage, particularly in languages like Perl, of being quite clear.
One important thing to note with any language is that the culture matters - a lot. For instance, Tcl and Tk let people easily create GUI's, but there was no UI culture. Most of the main books didn't dedicate even a page to how to make a good looking, functional GUI. You can produce some godawful messy code in Ruby if you put your mind to it, but there's a culture of not trying to be too clever, and also of writing stuff that's easy(ish) to read later.
Since I'm not really a Java guy at all, I don't know enough to comment in an authoritative way, but I sneak a glance from time to time, and my guess is that there may be a bit of a culture of over-designing things.
I think overall these cultures don't indicate too much of an underlying problem and aren't too harmful, except when assimilating developers from other language. But to your point, these barriers to entry likely exist for nearly every language (and if not, other barriers do), so on balance, it's largely a wash.
I think that the Java ecosystem being so massive and Java being so popular, it also attracted a lot of mediocrity, since the usual bell curve applies. That said, I know Java developers that definitely don't like verbosity and that don't follow the usual "best practices" as some kind of dogma. In the end, it all depends on the work environment you end up in.
I've been programming in Java (gulp) all my professional life of about a decade. I can totally attest to this.
Just couple of days ago in one of the code reviews I gave a lengthy explanation for using StringUtils.equals("foo", someVariable) over "foo".equals(someVariable). I could have instead just said what you've stated; prefer verbosity over cleverness :)
I love Ruby dearly, but I can't agree with this. There's a lot of being "too clever" in Ruby land. Not in terms of writing fiendishly convoluted but brilliant code (though we do have a nice subset of "code as art", like _Why's Camping micro-framework), but in terms of caring too much about elegance over things like speed and memory usage, until it comes back to bite us.
My pet peeve at the moment is Bundler and Rubygems, which while they are fantastic productivity tools when you start out, has the serious issue that the way they grow the load path means that the time to require a file grows exponentially with the number of gems. 100k+ failed stat calls on startup just to try to be "too clever" about not making people specify more clearly exactly what they are loading is no fun.
Many of these "too clever" things then starts to dictate app design. E.g. if you want to make a command line app out of a large tool that depends on a long list of gems and Bundler, you better think long and hard about making sure you defer all loading as much as you possibly can, or alternatively start up the app in the background and make a small command line app that talks to it over a socket...
For my part, I have a longer list of other Ruby practices I've come to detest than most, probably, as I'm working on a "as static and ahead of time as possible" Ruby compiler, and there's a lot of Ruby idioms that massively complicates things because Ruby developers are used to the malleability of the language, and so will often alter fairly central parts of the language even when there may be conceptually simpler ways of achieving the same that just doesn't look quite as clean.
Again Rubygems is a great example: It replaces "require". That's one of the means it uses to munge load paths. On the surface it was a great thing: it let Rubygems let people pretend Rubygems wasn't there, and yank out gems in favour of manually installing the files if they wanted to. But it came at the cost of contributing to the load path/stat mess I mentioned above.
Some of these things are in fact great no matter what, and exactly why we love our languages. But some of them come with ugly warts that we grow blind to because we understand the underlying reasons for why things have been done the way they have.
I think all languages grow these kind of warts. To me, Java has more of them than most... Java from beginning seems to have grown a culture of ceremony and abstraction that due to the language easily (but not necessarily) ends up with very verbose code.
http://hop.perl.plover.com/ - seriously clever.
Yes, I know that he says that he is negative and his praise comes across badly (he gives an example of him damning his blogging software). I suggest, if he is being sincere, that the problem is his attitude. If he isn't being sincere, then I'd say that he's not as clever as he thinks he is, or he just never had any passion for Java and so he actually hates it as he never mastered it.
In terms of boilerplate code, I'd love to see his exact examples. With annotations, I've found that plenty of Java code is actually not verbose at all. If he churned out thousands of classes when actually he could have reduced the number of classes to 50, then that's an example of poor management and poor workmanship, certainly not a problem with the language.
Here's the real issue: the article conflates a corporate environment that likes to measure productivity in klocs (or from the number of classes you create) with the tool that is being used. He even admits that he could have actually produced better code, just that nobody cared to correct him when he produced crap quality code.
However, when it comes down to it, the real phrase that comes to mind is:
YHBT. YHL. HAND.
The guy is trolling you all.
(Different languages have different failure modes. With Perl, the project might fail because you designed and implemented a pile of shit, but there is a clever workaround for any problem, so you might be able to keep it going long enough to hand it off to someone else, and then when it fails it will be their fault, not yours. With Haskell someone probably should have been fired in the first month for choosing to do it in Haskell.)
The languages he praises so highly are now put down. Correction: in each case, he's dissing the programmers who wrote the crappy code and caused the project to fail, and he's damning the terrible management that didn't have good enough leadership and oversight to prevent the project failure.
No disrespect to the guy though I'm sure he is and general respect for publishing a book like that.
I guess just limited exposure to Java
Even the best master carpenter wouldn't be able to build something as simple as an end table if he were given a pickle to use as a hammer, and an onion to use as a saw.
Also, have you heard the saying: A bad workman blames his tools
Well, it sure did a good job of identifying a lack of skill of folks on HN, so maybe it isn't quite so crazy after all.
Apparently you missed his second sentence:
> The first question on the quiz is a triviality, just to let the candidate get familiar with the submission and testing system.
Sure, you can overdesign in any language, but some inner language characteristics of Java lead to it more than other languages do. Copying input to output is a statement, if you think about it in in a logical, human way: "I want you, program, to perform the action of copying this to that". But Java, unlike some other languages forces you to say: "Make a class, make a main function because YOU need it, Java, and only after please do what I really want and copy that input to the outout".
In python, for instance, I'm in control of whether making a StreamCopier class, a copy_stream() function or just get to the core of what i want and write "print(input())".
Generally speaking, in most dynamic languages if I want to access the to_string() method of something passed to a function, I can pass a list, an int, a Duck object and till it has a to_string() function I'm good to go, or I can even monkey patch to_string() and call it a day.
In (too) many cases Java the language forces you to make instances over instances and implementation of interfaces and the like just to access the data you need in the way a framework or a method wants, not you, and often this is frustating because you see your data "just there" and the language fights against you preventing you to acccess it in an easy way. I need to call to_string() of SomeClass but I have an instance of SlightlyDifferentClassStream? Good luck with that, maybe the only possible way is to create a DifferentClassConverterProxy just to have a DifferentClassTranslator, extend TraslatorStream, feed it with my SlightlyDifferentClassStream and have something compatible with SomeClass.
This is not only true to Java, some of these "problems" arise from it being a statically typed pure OO language (a very good thing on my book when it is not implemented in a dumb way) that is put to shame by a cleaner implementation of the same principles like the one seen in C# that, on top of all, also offers a powerful dynamic programming, lambdas and so on.
Also, Java suffers from an enterprisey background. I consider a language environment to be a very relevant part of a language itself, and Java has promoted the proliferation of ridiculous bahamut frameworks with a freaking large number of classes and instances "just in the case someone needs to extend it".
These are facts, not "Har-har-so-many-classes".
Take a sane implementation of a web framework like Django. It is an opensource project born from the needs of a small group of developers. You don't have "so many classes" if you only write those that you really need to solve of your problems, and the project progresses from there to embrace the everyday, real world needs of a larger group of contributors. Most Java frameworks I've worked with really give me the tangible perception of a large group of monkey developers programming them following line by line a technical specification bible of thousands of pages written by a council of architects with business people yelling at them "mooooore, mooooore, we need more of all of this so that we can sell to ANYONE!"
Wow. What a pompous thing to say.
How does this have 91 points and is on the front page of HN?
Per the "most horrible answers were in Java", personally, I think he's missing selection bias, in that many newbie programmers who wouldn't know what they were doing in any language, think they "know" Java because they took a class on it.
I have no problem reading critiques of Java, not concise/etc., and like Scala/etc. as much as the next guy, but "relieved of the responsibility for producing a quality product"? Wow.
I suppose I'll add the disclaimer that if his 3 years of putting in time writing Java were doing J2EE, then I'll understand where he's coming from. But that's not the language.
> Wow. What a pompous thing to say.
I don't think it's pompous, I think it's actually self-deprecating. I think he's confessing to his perfectionism - to the fact that, if given a tool like Haskell he'll pursue some perfect, idealised program, because if you're not going to produce more beautiful code in Haskell then why are you using it? Java serves as the antidote here because nobody ever judges Java programs on their terseness, expressiveness or subjective 'elegance'.
When he says 'quality product' he's talking about the aesthetic qualities of the code, not the end result. When he says he's relieved of having to think about this, he means he can focus on shipping rather than perfection.
Because HN is full of Java hate, where all cool guys would never touch the JVM.
Meanwhile the world moves along and JVM based products get deployed every day.
i hate java. i hate java as much as i can. and i love hating java. java must be hated. java must be estranged. java must die. but definitely not the jvm. that's a beast i love. i use clojure and fantom on the jvm.
I agree [with you] that Java invites you (nay, urges you) to use good engineering practices.
I learned more about you than about Dominus with that comment.
Here is a link to his well received book, by the way: http://hop.perl.plover.com/book/
(But the book you should probably look at to understand the world better, is "Perl best practices".)
Edit: fuzzix -- you are certainly right about most useful modern books, I was making a point to what I comment on. The idi.. cough.. Which insinuated that readable code is an unknown concept to typical Perl programmers.
If you're going to argue that Perl is readable code then I'm going to have to disagree with you extremely after having been in a position to maintain some Perl code before.
1) Java has the paradox of choice problem. Unlike say Python, there are so many ways of structuring code based on the extreme flexibility of available frameworks and so many different libraries that it gets complicated fast due to sheer number of choices, unless you're really experienced and you already know what you want ahead of time.
2) Java's verbosity necessitates heavy abstraction through many patterns. Which patterns will you choose for your given problems? It's still somewhat easy to write spaghetti unless you have both the experience and discipline to prevent it.
Python isn't perfect, but its one way to do something philosophy leads to "relieved of the responsibility from doing 'the right thing'" unlike Java. People who use Ruby kind of experience this as well if they use Rails.
TFA is talking about simply not caring. Which I find an awful opinion. There's a really big difference between a well designed, well built Java product/library and a badly designed, poorly built one. The Java ecosystem being so massive, you can notice examples of both everywhere and the difference is night and day.
Java does in no way relive you from the responsability of producing quality. At times it makes it harder, as you need a lot of knowledge and extremely good taste to do the right thing, instead of sucumbing to "best practices" that are perpetuated as myths or instead of adopting poor libraries, just because they are popular.
Example: java.util.Date / java.util.Calendar versus Joda Time.
There's no surprise that this is the culture here. Need I mention the term "blub programmer"? Could anything be more elitist and offensive?
Off the top of my head, right now, in this text box, without google, I can't write the code to copy standard input to standard output.
System.out.println(System.in)? That's wrong. You need some kind of InputReader, or BufferedInputReader, or Buffered...something. I think System.in is an InputStream, so presumably I need to do new InputReader(System.in)? Or BufferedInputReader? Should I buffer the output?
Ok, let's do some API googling (ie, not StackOverflow).
So I was... pretty wrong. I think what you want is:
public class CopyInput { public static void main(String[] args) { while (true) System.out.write(System.in.read); } }
I haven't tried to run this though.
In my defence, I have never, in all my years of working, had to ever read standard input, let alone write it out again.
Don't tailor from-memory standard library questions to bits of code that almost nobody ever has to use.
For example:
Whenever I'm dealing with a data processing pipeline I tend to design things as if they would be used from a unix command line. I tell the team to make their classes etc as if they would be wrapped with a simple chunk of code to parse a text stream then serialize to it later. During the course of testing, I almost always will then write those tools to allow simple command line pipes to push test data around. It helps prevent reliance on certain toolsets and certainly helps stop us from conflating bugs in our code with bugs or operator error about a pipeline framework. Later we can go back and more closely integrate with the chosen operating environment, if performance demands it. On the other hand going from a situation where code is written to the environment and migrating to another environment can be very daunting, difficult and error prone.
So seriously? You almost never need to read & write to streams?
Again, most of us write real apps, not command line utilities.
Java didn't grow up in the world of unix where scripts that read from stdin and write to stdout get chained to produce pipelines. It grew up in the world of long-running stand-alone applications that communicate over sockets (like web applications). Java, because of the virtual machine, has a particularly slow start-up time and would be a poor choice for implementing mini pipeline components like this anyway.
import java.io.*;
public static void main(String[] args) {
byte[] buf = new byte[4096];
while (true) {
int numRead = System.in.read(buf);
if (numRead < 0) {
// hit EOF, terminate
System.out.flush();
System.exit(0);
}
System.out.write(buf,0,numRead);
}
}I guess I've been stuck in webapps and NoSQL libraries for a while now.
Yeah, but there is nothing different from this and having to copy data from an input stream to an output stream. If you can't remember how to do that, it kind of raises the question of what you were doing in Java.
Not knowing if you need to buffer is actually fine in my book. That's an optimization thing. Not knowing how to make the code correct though...
[1] http://en.wikipedia.org/wiki/Pipeline_%28Unix%29#Pipelines_i...
Ignoring that, what I like about java is that my programs are clear, and that once I compile my programs, they just work. I can refactor my code, and the compiler makes sure that I don forget anything. I don't love it they way I loved Perl or C. But when I write Java, I feel confident that my program is not going to break; and even if it breaks a stack exception is going to point me directly to the offending line.
Of course you don't have to use 25 Design Patterns at the same time. But lets not blame Gosling for that, that is the fault of the "Enterprise Architects", I still think you can write good tight java code.
I have no problems with Java. But I have routine fits of frustration during P1 issues when I have to dig piles and piles of code to analyze simple things. Often its like there are 9-10 hierarchy of classes each doing something very simple and passing the burden of implementation to things below and down there you see more and more verbosity, boiler plate, getters/setter and pages of exception handling.
In some way Java too is a write only language.
Totally agree.
Dijkstra wrote "a case against the goto statement" (which was renamed "Goto considered harmful" by the editor of the journal) when he saw these things happening to flow control because of GOTO.
These days Java (and C++, to a lesser but similar extent) has just as much "class spaghetti" as the "goto spaghetti" of the old days - and many programmers have no idea that it can actually be better.
The library is too verbose and over-architected. My idea of a good match would be the Java language with Python's libraries.
There's a balance. Neither is optimal. (I think C# comes very close to what I'd call "perfect", but it doesn't run anywhere I'd want to use it.)
Sure, it's a fine way to do math, and you get all the same answers, and it's not really much slower. But I didn't like doing it then and I wouldn't like doing it now.
Programming in Java feels like doing math with blocks. I have all this code that needs to be there, and I understand why it's there, but I still find its inclusion frustrating. Java is a fine tool, and can be used to build great stuff, but it's not to my taste.
The most probable reason for the failure is because Java is not used in industry that much as a shell programming environment. The most common use case for Java is as a server-side, long-running server, with C++-like performance and without C++-like headaches. I work with algorithmic trading engines in my job. Though I trade personally these days and the orders are small, the engines I implemented for banks typically handle $250m worth orders per stock exchange. I have NEVER, not in a single instance in the last 5 years, have had to read from stdin in Java. Why : in my particular niche in my industry, input comes via a socket that is abstracted away by an engine that implements the FIX (Financial Information eXchange) protocol. For all practical purposes, in the finance industry, the FIX library / server IS stdin and stdout. This doesn't make a colleague of mine who forgot how to access stdin in Java a nincompoop. It's a failure to remember what is rarely used, not a failure to perform basic job duties. See the difference?
I believe the author is / was a Perl expert? That's why he thinks being able to read stdin is "so basic". I challenge the author to confront his prejudices : hire a few candidates who fail the stdin / stdout test. If they are allowed to do the damn work instead of jumping through your Perl-shaped hoops, they might have actually done quite well on the job.
Similarly, many Perl programmers would fail a test devised by someone who is used to Java.
If the test is open book, then "I can't manage to look up how to deal with stdin and stdout in Java" is decidedly more damning than "I can't remember".
Further, if there is a requirement that you use the same language for all of the answers, choosing Java when you know Java best makes sense. If not, choosing for that problem Java (when you don't firmly remember how to do normal IO!) is itself a bad decision, when you likely would have got full marks for
#!/bin/sh
catWant to show off to the web CRUD hipsters, you can go Groovy, Grails and Play framework.
Want to show off to the Enterprise architect astronauts, you can go Hibernate, Spring, ElasticSearch and JBoss.
Want to show off to the Big Data ivory tower academics, you can go Weka, Lucene, Hadoop and Scala.
Want to show off to the esoteric language hipsters, you can go Clojure, JRuby, Jython, JScheme and Rhino.
Sun Microsystems and applets on IE6 live on in my big heart warmed up by hot cup of cappuccino beans.
It reminds me of a great post by Coda Hale a couple of years back where he was explaining why he switched back to Java from Scala (which was hot shit on HN at the time):
http://codahale.com/the-rest-of-the-story/
"The world has yet to take me aside and ask me for my opinion of it, and in the past few years I’ve found that it’s far more profitable to build things rather than tilt at windmills."
It's an environment that needs an IDE because of the large number of libraries and the large number of features delegated to libraries rather than the core language (which is an architectural decision that I approve of, BTW)
As for the java-hate - in my 10 years of java-programming it has always been there. They used to complain about it not being portable enough, not performant enough, GC-pauses, start-up times, and lately that it's to verbose and non-functional. But java has persisted, and only improved over the years. I'm happy I've been able to (mainly) program in the same language for so many years. It makes me realize just how long it takes to truly master a programming language (or perhaps programming in general). I guess that's why they say "..it takes 2 weeks to learn a programming language, and 10 years to master it". It's an art, and the language is your tool.
I was complaining that Java was verbose in 1999.
The codahale post is old news referencing issues which have already been fixed.
... it's not on HN. It's among the users to languages that aren't Java or C#.
Some people obsess over the tool itself. My tool has these 10 features, and it was hand crafted and it can solve 8 Queen problem in 2 lines and it has monads or a cute puppy for a mascot and so on. People who use tools obsess about them, and it kind of becomes the end not just a means to an end. They would read about the new features in the language, they would run over tutorials in their free time and so on. There is a good amount of pleasure derived from fawning over the tool itself.
Others don't care about the language or the framework, they just want to job to be done and get paid. It turns out that some part of code they are working on is written in FORTRAN, COBOL, or (oh the horror!) MUMPS, that won't bother them much. They'll just figure it out and fix the issue. The pleasure comes from getting paid and solving the business problem at hand.
Both are extremes and there is a continuum between the two on which most people fall. Neither extreme I think is healthy and at the same time there are good parts about each one --
Someone who cares about the tools they are using will probably also use the tool better and more effectively. Someone who is picky about the type of hammers and their design and knows the history is also probably pretty good at hammering nails in. They might spend $1000 for a titanium hammer but hey they will be good at it.
Also someone who cares to get the job done and derives pleasure from solving a business problem, might just be the one keeping the product/company/startup afloat. Making money and delivering products is the top goal of most companies. This often means what seem to be boring, old, broken, unfashionable frameworks or tools. But so what, look we are still getting a paycheck!
There is a validity in both.
Yes, in the broadest sense of the word, Spanish is a tool. So is a programming language, but the analogy is stretched and stale. The image it puts in people's minds is not super helpful. And if we must use such a broad word as tool - let's acknowledge that it's really a collection of tools (every API, bit of syntax, and language feature is a tool).
I still say it is a tool, just a tool with many buttons and settings. English is a natural language that I learnt (it was my 3rd natural language) primary to read and understand computer related materials (books, keywords, instructions). It was absolutely a tool just like a hammer is a tool to drive a nail in. It turns out to be a very beneficial tool but a tool nevertheless. I would never bother spending time learning the etymology of words or finding all the tenses or declensions (but some do and derive great pleasure from that).
Most of the time, there’s a balance to be struck in the tool you choose—if we did it in Haskell or OCaml or Scala, it’d probably be more correct and easier to maintain in the long run; but we are a startup that is likely going to run out of funding in a month or two, and if we hack it together in Ruby or Python or Node then no one will fault us and we can rewrite it in a good language later if we have the budget of time and money.
So while Haskell might be my primary language at work and play—and I see the tremendous value it holds for experienced developers—when beginners ask me what language they should learn, I invariably say: “Java”. At this point, it’s the essence of mediocrity, the dead middle of the bell curve; you can go better or worse from there.
While I don't have actual proof of anything (and I doubt parent has either), removing classes of issues is a big win. Not to say that any of the three languages you list is a silver bullet, they all come with a long list of drawbacks. You just have to pick which drawbacks you dislike the least.
> For Haskell in particular, if you change assumptions in your type system you are going to have a lot of work cut out for you which seems to go against 'easier to maintain'.
What do you mean by this? If your types are fine-grained enough (which you can absolutely do in Java, at the cost of a lot more code), and you change your specification, you will need to change your types. But if you did not have fine-grained types (in any language), you're going to be fixing errors at runtime instead. If you're not going to leverage the type system, you may as well work with Python, you'll get the same effect with a lot less code.
(reason for liking Java)
Well, here are some other reason for liking Java: https://medium.com/i-m-h-o/da3b2c180e9c
But I really believe the future of software is affected more by having better programmers rather than having better languages.
Yes, it helps to have cool languages like Julia, Nimrod, Rust, even Scala (which I think is the best statically typed JVM language out there). But I tend to think that a good developer will be good in any language, Haskell, C, Java or LOLCODE.
I think that a good developer "forced" to use Java will find tools that bring out the good parts of the language: Dropwizard, Play framework / Akka, even latest versions of Spring and Java EE are much more convention over configuration and lightweight than before. They will use Guava and Apache commons to streamline common Java verbosity and bloat. They'll use Java 8 which allows much more robust and concise syntax to common problems.
But I don't think that the language is the problem. I think that a great developer will be able to tackle any problem with the language itself easily, because the real problem is not how to implement X, but more what is X. Designing the software correctly is the main problem at hand, not how to move input to output. This is what stackoverflow is for.
One last point about this all "I hate/like Java" type of post
1) If you write Java for your day job and hate it, either try to introduce something else (Clojure / Scala / Java 8 / Kotlin) If you can't introduce any of these then either accept your fate or just quit and find another job. If you can't find another job, then perhaps you deserve to stay and write Java so stop whining, it's not that bad (and one day you'll get to use Java 8).
2) If you don't write java for your day job but as a freelancer - start getting other non-java gigs. Not so many non Java jobs? well, continue to write Java bashing blog posts until people will stop using it I guess...
3) If you don't write Java for your day job or as a freelancer, then just stop complaining about it. There are million of other things (not just programming languages) out there worth complaining about. They can use your writing talent for a better cause.
On average, I believe the quality of programmers will decline, simply because as they demand rises more and more people will come to the field that don't do it out of interest/passion but because it a profitable profession. Not that this is already the case today - I think it's a trend that's already begun and will probably continue this way.
This attracted a lot of people who weren't really passionated about programming.
Now years later I was hiring during the bank crisis and I interviewed CS students who got their degree but couldn't find a job. I couldn't understand that if you have your degree and are out of job in 2 years you haven't written a single line of code on a hobby project. But these people exist.
These people will be always there in any field.
He sounds like someone who never learn Java in the first place. Neither he learned what it is good for, what it is bad for. I think that if you interview in some language, you should understand what kind of problems are easy to solve in that language and which are hard or never done.
If I have to write libraries less input output example in interview, my code will be ugly and long. I'm not saying that interview should not ask these questions, it tests whether the candidates ability to find his way around api he uses rarely. It is needed skill, so no problem there.
If I have to design complicated system, adjust it to changing requirements and maintain it for years, I feel most comfortable in Java. Type safety, tools and language itself allow me to focus on the system itself and how systems parts cooperate with each other.
He also sounds like somebody who is biased against whoever uses java, because he worked once in bad java shop. It sounds that it really does not matter what those people would do, they used java, so they are incapable in his eyes.
"In Java, you can forget about doing it in the cleanest or the best way, because that is impossible. Whatever you do, however hard you try, the code will come out mediocre, verbose, redundant, and bloated."
Guess I was right about learning Java.
Only new Java projects would actually use the Java 8 features anytime soon. Existing Java codebases will stick to their Java 6 installation for a long while. It could be years before lambdas are used to any significant degree. Look at how long it took for many Java 1.4 shops to actually upgrade to Java 5, let alone encourage developers to use its features. Even today a lot of places still allow and even encourage use of collections classes without the generics specified.
As long as you aren't writing Java code on Android, in which case you're still stuck at Java 6 (with a very small subset of Java 7 features that were added 3 years after Java 7 came out).
Not the fault of the Java language, really, but it is incredibly annoying how unclear Google has been on the future of their dialect of Java post the Oracle lawsuit.
One worth noting: If existing code is using Proxy.getProxyClass and the Constructor.newInstance method to create a proxy instance, it will fail with IllegalAccessException. RFE 4487672
(yeah, shouldn't happen in the best of all possible worlds, but may still happen anyway)
Better programmers will likely make better languages. Undoubtedly a good programmer can learn to program in any language, because its the same process, but languages do certainly have their limitations.
Sorry, no. That's just too far. Imagine being handed a codebase of LOLCODE.
I hope to God no one ever was or will be handed a codebase of LOLCODE for a "real" commercial system.
But if anyone ever does, it will sure be fun to hear about it in a blog post.
I consider myself a fairly competent programmer, and I have a little knowledge of Java, including building GUIs and so on. Here's the Hello World program off the top of my head:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World.");
}
}
So to answer the interview question, I just need to figure out how to open stdin. At a guess, maybe something like System.in.readln will do it? Let's look in the class libraries.Bingo! I've found System.in, and it says it's an InputStream. So now I just need to find ... ah ... there are three of them. Is System.in a java.io.InputStream, org.omg.CORBA_2_3.portable.InputStream, or org.omg.CORBA.portable.InputStream? The documentation doesn't say.
Well, I have a vague idea of what CORBA is, and I don't think I'm using CORBA here, so it must be java.io. Good first problem solved. Now, what methods can I use?
abstract int System.in.read()
int System.in.read(byte [] b)
int System.in.read(byte [] b, int off, int len)
These methods just read bytes! I want a String, or at least a char. And Java uses multibyte characters. Can I get away with casting bytes to chars? I don't know. Maybe it was one of the CORBA methods after all? Or maybe ... I'm stuck!I figured it out in the end, but only through pure luck: I need to wrap System.in in a java.io.InputStreamReader.
? In most runtimes stdin is opened before you start. Certainly is true in the case of Java.
> So to answer the interview question, all I need to do is open stdin.
No, you also need to "open" stdout. More importantly, you have to figure out how to read and write to streams without losing data (which you'd think would be easy but evidence indicates otherwise).
The fact that I/O management is cumbersome in Java doesn't relate to the ability of Java programmers to provide value.
Doing it through, say, docs.oracle.com to check what's the stdin interface - that is quite easy, but writing it on a whiteboard from scratch would fail many Java developers.
People keep thinking that there are special functions involved in this solution for interacting with the console (which by itself is telling). Let's pretend it was just copying from an InputStream to a PrintStream. Those are both interfaces that most Java developers should be quite familiar with.
3 years is about the amount of time it took me to get a false sense of security in my understanding of a language, imo. After 3 years i thought I knew Java. After 3 years I thought I knew Ruby. I was wrong.
BTW- if I were to receive a question on my application asking how to read stdin and write stdout, that would be a bad sign.
> So yes, I enjoyed programming in Java, and being relieved of the responsibility for producing a quality product.
Many quality products I use have been written in Java.
> It was pleasant to not have to worry about whether I was doing a good job, or whether I might be writing something hard to understand or to maintain.
Though, I understand the intended meaning of "Java is too verbose", You can write code in Java that is easier to maintain. Java is not an excuse for poorly written code.
> The code was ridiculously verbose, of course, but that was not my fault. It was all out of my hands.
You get paid to write maintainable code that does what is intended. It was never "out of your hands".
I no longer like Java as much, but I don't think Java ever was a reason to sit back and let bad code happen.
It occupies a weird middle ground where you give up the capability to code to bare metal or easily interface with C functions in exchange for nearly being able to quickly and succinctly create powerful abstractions.
There's not a whole lot wrong with it, but I don't think I've ever been using any other language and missed something from Java. But when using Java that experience is common and I find the amount of effort you have to put in to not write repetitive code is annoying and results in overly complex architectures.
I'd say this ground is well and truly occupied by Common Lisp. Java occupies some other ground which is neither quick nor succinct.
At MIT, in 2003, there was a class called 6.171 Software Engineering for Web Applications. The final project was, in fact, to design and make a web application. It was very open-ended and it could be in any language you wanted.
This particular course soon stopped being taught, because a large number of people failed the final project. They could not make an application that functioned in any way by the time the course was over. (Keep in mind: 2003. There weren't really any easy answers to web applications.)
Many people had chosen to do their project in Java, because that's what they had learned and used in the prerequisite course. And in particular, over half of the people who chose Java failed.
(By the way, the course on web applications is now the main project-based course on software engineering at MIT, and it is now taught in Ruby.)
Which one is that? As far as I can tell, the "new" 6.170 (6.S197) uses Python (or at least used it in the fall of 2011).
(I gather by its new subject number that it is no longer a part of the core requirements, being largely supplanted by 6.005, which ironically appears to use Java. Of course, when I took 6.170, we used CLU. Boy, am I old.)
I guess it would be true that 6.005 is the "main" software engineering course now, not 6.170.
(1) This is an interview question, he's not asking you to be a professional stdin->stdout copier
(2) this isn't a micro optimisation problem:
> The first question on the quiz is a triviality, just to let the candidate get familiar with the submission and testing system
(3) A surprising number of programmers can't program. Basic warmup questions are a good thing and can save a lot of your time http://blog.codinghorror.com/why-cant-programmers-program/(4) Even if this isn't his attempt, there's genuine depth to even this problem. If you do the obvious
a = get_byte()
while a != EOF:
send_byte(a)
a = get_byte()
There's a surprising amount of work going on behind the scenes that you can dive into discuss how I/O works, when would you do this using blocking vs. non-blocking I/O, when should you do your own buffering or let the language/library do it for you. But it's short enough to get started to get to those points very quickly.(5) I wouldn't hire/not hire someone based on style alone, but you can get a pretty good feel for it from short programs that actually work. If the tasks or snippets on which you interview are too short to be complete programs, you miss a lot of organisation and "shape of the code" kind of stuff from their style.
(6) Interviews are tough as an interviewee. Professional programmers aren't professional job interviewers and often it can be hard to read their mind to see what they are looking for in a particular question. "It's open ended, take it where you like" usually doesn't mean what it says on the tin. As far as going from "here's a question" to "here's an answer" with little ambiguity this is one of the better FizzBuzz type questions I've seen.
This reminded me of the interview for my first job. I was basically between a rock and a hard place so part of what follows was clearly, in retrospect, a bad sign, but the choice between job and no job but $20k in debt to cover, I took the job.
The shop was a C shop, embedded systems. When I went in to interview I was virtually a shoo-in (just learned I'd misspelled this for years as shoe-in) for the job due to a college classmate already working there and recommending me. The code segment was straightforward. It presented several "implementations" in C of functions to swap the values in two variables. That is:
int x = 10;
int y = 20;
swap(x,y); // after this point x == 20 and y == 10 should be true
void swap(int x, int y) { int t = x; x = y; y = x; }
Now, that obviously won't work in C. One of the implementations was correct, 3 were wrong (like the above snippet). I was asked which were wrong, why they were wrong, which was correct. I answered them all (note: this was a week 2 or 3 programming assignment when I took a course using C as an undergrad, it really seemed obvious to me), and the interviewer was surprised. I was told, "You're the first person to get all these questions correct."Like I said, warning signs. Alarm bells should have been going off. If the interviewer tells you that, that means that your colleagues couldn't answer those questions. That only occurred to me about 4 weeks later once I'd finished all my reading and project familiarization and was getting into really working with my new peers.
#!/bin/sh
cat
There are a lot of nervous and shy people. Easing them into the process with an 'icebreaker' question gives them a chance to open up for the real questions.
This one guy chose Python, which delighted me since it's so rare. He then proceeded to produce answers much more easily than the average candidate, and he was able to make changes as I suggested them without too much effort.
We hired him but had to let him go after a month, when it became clear that he wasn't as good as I'd thought he was. Turns out it was Python that just made him look smart.
I like Java for actually getting things done, but it's such a vast ocean of TMTOWTDI that interviewing in it seems harder than in smaller languages.
Well, actually it has been said by Dijkstra again. www.cs.utexas.edu/users/EWD/OtherDocs/To%20the%20Budget%20Council%20concerning%20Haskell.pdf
I have a side project I'm maintaining (all in) Java that I spent a weekend on about two months ago. Frankly, it was ridiculously easy to splat out code with Eclipse (and not get anything done, but that's mostly my fault).
Several fundamental issues showed up:
- lack of first-class functions
- lack of extensibility on extant classes
- grossly mutating state
- Loads and loads of code that obscured what the logic of the program was
Project Lombok is a heinous hack to try to get around these issues (somewhat). So is, afaict, AOP.
I think for the right project - and with ruthlessly non-generic design - Java is the right tool. Otherwise you wind up with reams of wasted paper and mental overhead grappling with the sheaf of low-entropy code you've got.
I think you missed the point of the article.
I couldn't agree more. Lombok was the worst thing to ever happen to our codebase.
Java 7 kinda divided the line length by a factor 2 with the diamond operator, the try-resource and so on.
I've programmed some Java 8 since yesterday and it actually feels like a pretty decent language to express ideas. Nothing like Java 6.
I know most of the Java haters have been struggling using it day to day in settings were it was awful (over engineering + Java 6, hello, here is the gun).
But I feel like those haters should really try to think fresh on this one. Try Java 8 and its new features and decide for yourself _afterwards_.
public static void main(String[] args) throws IOException {
int ch;
while ((ch = System.in.read()) != -1)
System.out.print((char) ch);
}I was so wrong.
Three things wrong. The first is pedantic: you need to import IOException. The second though is one of those "scream out loud at the universe* questions: why the heck are you calling print() instead of write()?
Finally, do you think maybe you might need to worry about buffering of System.out's stream?
print() won't flush to the console unless you pass '\n' and auto-flushing is on. It will flush its internal buffer, but that's okay! The default System.out uses a BufferedOutputStream anyway:
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
...
new PrintStream(new BufferedOutputStream(fdOut, 128), true)
So using print() instead of write() shouldn't cause any extra system calls, although there many be a small CPU cost.Obvious, right? Don't you love java.io? :)
Yes, which is the _problem_, not the _solution_.
To clarify: the problem isn't that the code makes too many syscalls.
> you need to import IOException
try {
...
} catch(Exception ex){ ... }
;-)Edit: Or if you want to be just as pedantic, and not write an obnoxious catch-all
try {
...
} catch (java.io.IOException ex) { ... }There are some, but they aren't the ones people usually think of when they say, "I'd always use X instead of Java".
In python, this seems to work: import sys sys.stdout.write(sys.stdin.read())
What is being abstracted away/handled by python that I'm not seeing?
Except no. Then you run in to problems with a binary file that might not have a line break.
This is valid JDK 1 code. You only need to read the Javadoc for InputStream and PrintWriter. I think the author needs to check his biases.
Now Javascript... (just kidding).
Okay, that kind of points to the problem. You don't see anything wrong with that code beyond the casting (and avoiding casting is the wrong reason to read in to a byte[].. which opens up some additional complexity too).
So my ideal impl in java would be:
public class F {
public static void main(String [] args) throws Exception {
byte[] buf = new byte[256];
int len = -1;
while ( (len = System.in.read(buf)) != -1) {
System.out.write(buf, 0, len);
}
System.out.flush();
}
}
In python #!/usr/bin/env python -u
import sys
while True:
buf = sys.stdin.read(256)
if buf:
sys.stdout.write(buf)
else:
break
Which both feel roughly the same. Although I kind of wish python would let me assign within the expression - just in this case. The similarity boils down to the fact that they're sitting on top of posix read and write calls. There's not much variation you can get from that.The differences get down to fd stream flushing. Python we enable unbuffered io with -u, java we must flush. In C++ we can count on all FDs being flushed in atexit.
You certainly can muck this problem up for binary files and different charsets if you're not careful. But the OP's solution still works in many cases. A fine first answer. Any time a candidate writes code for you during an interview, the first answer will most likely have issues (stress, trying to finish quickly to impress, etc). I care very little about that stuff if there answer is roughly functional. After they have their first stab out, then you go thru the 'why did you do it this way?' 'what corner cases might you be concerned about?' and so on. The answers to those questions will let you make a good estimate of their knowledge and competence.
Ya think!?
Scanner sc = new Scanner(System.in);
String line;
while((line=sc.readLine())!=null)
System.out.println(line);
}What's so verbose about it?
It's amazing though how often the solutions posted are just wrong.
Java itself less so. It is just far too verbose. I found that I would get completely frustrated coding in an editor without code generation. Using Netbeans to generate most of the boilerplate code was the only way I stayed sane coding in Java. I cannot imagine having to write lots of production Java code in a "normal" editor. If my IDE can figure out what I'm trying to do, so should my programming language.
Ultimately java is just a tool. The culture around it shapes the macro picture but still.
Well neither does C, C++ as well. Nor does Scala actually.
There are a lot of good things about Java, namely the JVM, interfaces, great libraries, reflection and code generation, etc, etc. For example libraries like jmock/etc.
Ultimately, where does the language end, and the standard library begin? Whats the real difference? Yeah, so C++ and Java don't have built in syntax for hash tables. That's it?
That's, unfortunately, common misconception and excuse for writing bad software in Java.
Java has its own problems (as if other languages does not have them), rigid objects creation that has to be overcome by dependency injection, nulls that has to be overcome by using Optionals, badly designed time/date handling standard libraries, etc.
However there is a huge number of good quality, well design libraries that make Java shine.
- Guava gives us functional-like programming style plus nice collection handling - Joda Time solves problems with date/time handling - Lombok (projectlombok.org) cleans up code from getters/setters clutter - Need a nice, collections only library, there is plenty of them (for instance GS Collections) - You need to create super performant server? Just use Vert.x, Distruptor library, you are getting nice APIs and a lot of functionality for nothing - You want to write nice, concurrent code without using low level primitives, no problem, go with Akka - You need to orchestrate actions flow in your (huge) application - do it easyly, elegantly and almost without coding using Apache Camel - Google Guice dependency injection library provides nice workaround for a rigid object creation strategy in Java
And so on, and so on. Java ecosystem is changing, there are new ideas that refresh language, despite its rigidness (no macros).
Use Clojure when you're paid by the project.
Use Haskell when you need to ensure job security.
For all I know, he's probably still working there. The poor, poor bastard.
I'd say, Use Java when you need to ensure job security. And it is.
"There are many bad java programmers, hence java is bad. Even I was bad at it. Saying that I like java is just sarcastic link bait."
I couldn't even do the 'read-from-input write-to-output' thing mentioned in the example.
It's true it's because of the language: I've believe Java is more 'Enterprise' and sophisticated.
But I KNOW that because of this I tend to write better code (at least more standardized and better structured) in Java than in other languages I've had the same practice with, such as C, C++ or PHP, even though I don't need any IDE or manual of any kind to write such a simple program on those. And, no matter the language, it takes me the same time to do it right.
My conclusion is: If you like to 'hack together' a tool Java is probably not the best choice of language; If you want to build some big project on a team and keep it robust and maintainable using efficient libraries, it is.
But if I can choose the language it's easy...
#!/bin/bash
cat
If people can't come up with a different solution they probably just suck...All that documentation will show you is that you use System.in to access standard input, and that it is an InputStream, and you use System.out to access stand output, and it is PrintStream. I'm sure an interviewer would be happy to provide you with those prompts. Could you solve the problem with that help?
And it probably doesn't help that the java.io package is also really horrible.
read() returns byte[] but print() accepts only char[], so you'd need to cast or use write() which accepts byte[], but you need to pass it an offset and the length too: write(byte[] buf, int off, int len). Eh, that's just stupid. I'm happy eclipse tells me that stuff...
If I had to do this at an interview in Java, from the top of my head I'd probably ask if it's okay if I use Apache Commons IOUtils and try to IOUtils.copy().
But again, the article talks about language of your choice. I was just a bit shocked when I was able to write this in C and perl without autocomplete even if I practically never use C or perl.
Makes me wonder if it's really the IDE's that make you not memorize the standard library. Or if Java's standard library is really that horrible.
I think it's a combination of both.
Or maybe because I usually don't deal with this stuff in Java while implementing boring business logic.
Also, C:
#include <stdio.h>
int main(){
char strbuf[1024];
while(fgets(strbuf,1024,stdin)){
puts(strbuf);
}
}
Perl: perl -e 'while($a=<>){print $a}' while (<>){ print };
Fwiw, in Perl 6, the canonical incantation is: .say for lines
where:* thing.method calls method 'method' on thing (where thing is an object, or something that can behave as an object, which, in Perl 6, is any value). In the code above the 'say' method prints its arg, followed by a \n, to stdout.
* If thing isn't specified, the current topic (aka "it" aka $_) is assumed, so .say is being called on "it".
* 'for' sequentially sets the current topic ("it") to each of the items in the following list of things.
* 'lines' lazily reads lines (next chunk of text up to the next \n) from somewhere. The default somewhere is stdin.
A simpler incantation is:
slurp.say
which slurps all of stdin as a list of lines and then says them all, but slurp isn't lazy, so it'll wait till it's read all of your stdin before writing any of it to stdout.Well, I'm a little surprised, but I wouldn't begrudge an interviewee a peek at the javadocs. You should be pretty familiar with the API's and how to use them correctly though.
> read() returns byte[]
Actually, it returns an int. You're thinking of read(byte[]) I think... but it also returns an int.
> print() accepts only char[], so you'd need to cast or use write() which accepts byte[], but you need to pass it an offset and the length too: write(byte[] buf, int off, int len). Eh, that's just stupid. I'm happy eclipse tells me that stuff...
Eclipse won't tell you that a) you shouldn't use print(char) because you aren't trying to format a character. The offset & length is a pretty common Java idiom, and actually important for getting this right.
> If I had to do this at an interview in Java, from the top of my head I'd probably ask if it's okay if I use Apache Commons IOUtils and try to IOUtils.copy().
That's perfectly legit.. if you remember to flush the output stream.
> But again, the article talks about language of your choice. I was just a bit shocked when I was able to write this in C and perl without autocomplete even if I practically never use C or perl.
The C code is fine enough, though doesn't correctly detect when an error occurs.
The perl code is going to potentially chew up a lot of RAM with that input.
I agree though that Perl & C make this pretty easy to do right, and Java (along with a surprising number of higher level languages) doesn't.
In that case it does exactly the wrong thing, by declaring checked exceptions in the method signature, which client code will be forced to deal with.
If you don't even understand how checked exceptions are supposed to work then no wonder you are hurting yourself on the language.
> In that case it does exactly the wrong thing, by declaring checked exceptions in the method signature, which client code will be forced to deal with. > > If you don't even understand how checked exceptions are supposed to work then no wonder you are hurting yourself on the language.
It's an error that you don't have a way to recover from. Reporting an error and leaving it to the client code (or in this case, the parent process) to deal with it, exactly as specified by the declaration of the method. That's actually exactly how exceptions are supposed to work.
"[You don't get paid to write software as a Java dev, you get paid and judged by the amount of lines of code you write.]"
If Java and other imperative devs haven't heard that before then they need to consume more sources of knowledge and widely held opinions.
The quip about being dissolved of any real responsibility as a Java dev is stereotypical of course. And it doesn't solely apply just to Java but to the general mindset shared by the various big imperative enterprise languages. It is _possible_ to use such languages in a _cleaner_ fashion (with lots of hoop jumping) but rarely does the opportunity present itself in such enterprise environments because of politics and backwards thinking. Additionally, _why_ should you have to incorporate countless additional libraries and techniques just to "bend" the language to what it should have been in the first place? That's what everyone ridicules JavaScript for doing.
The best, most experienced programmers will naturally gravitate toward functional practices; which is basically SOLID in OOP land. Unfortunately, at the moment, only the luckier (or pluckier?) ones will actually find themselves in a job that lets them use a real functional language that deprecates the need to jump through so many hoops just to achieve a maintainable and immutable (and all the other good stuff) design.
(sigh) I despair, honestly. Please folk, take the time to see how some of the largest scale software on the planet runs on the JVM. Horses for bleedin' courses folk.
Personally I write my software in Bash, Java/Kotlin and Javascript - depending on the context each of these have proven to be excellent technologies.
I learned C while in grad school, but I really learned it at IBM while working on the Unix kernel. That gave a useful perspective on the strengths and weaknesses of C. So I can say that Java has some real advantages over C for certain kinds of work while C is the right language for kernel work.
Here, on HN, I've learned that Java programmers like programming in Java and that Javascript programmers love programming in Javascript. But please don't pontificate on how wonderful functional programming is in Javascript if you haven't got a reasonable amount of experience with a real functional language (OCaml, Haskell, etc.). Or that Java is better than Python because [whatever] unless you've really programmed in Python too.
...this question comes up so often you'd think they'd just figure out that the
chaining of streams is somewhat difficult and either make helpers to create various
combinations or rethink the whole thing
http://stackoverflow.com/questions/309424/read-convert-an-in... java is a blue collar language
James Gosling, The Feel of Java http://www.dfjug.org/thefeelofjava.pdfJava is indeed very workmanlike. Straightforward, predictable, reliable.
My observation is that the Java standard libraries (packages) are like a highly skilled and conscientious C programmer trying to write OOP. The don't want to cut off too much power from you. And that means you have to specify everything - exactly what kind of list do you want? In scripting languages you don't, because most of the time it really doesn't matter. (BTW: If you read some of the source, it is often written in a C-like style rather than Java-like).
The low-level style of libraries is at least half the reason Java has lost out to Python/Ruby etc. But also for its wins.
My second thought was to come here to the comments to see how long it would be before the attempts started.
My third thought was, if you're allowed to use any language at all, I'd go for code golf. Not sure it's possible to do it in fewer characters than:
#!/bin/sh
catHowever it is true that reading a stream from stdin is a big pain. More importantly it's also true that students learn an over-objectified style of Java programming in school which generally produces very bad code. Students tend to create too many layers of objects and to over-use inheritance, resulting in an inflexible structure with many opaque interlinks between objects. In the real world specs change at any time, and one must program in such a way that unanticipated features can be added. Deciding what blocks of code should be broken into shared routines remains, in my view, something of an art form, and one that the current Java-based programming curriculum does little to develop.
Related to this: At Uni we had a terrible lecturer for our first year C programming courses. We had a team project that none of understood. A few days before the submission, when we didn't have anything that would compile, someone got hold of the marking system. The marking was automatic, and up to 5 of the 25 marks were awarded for the code:comment ratio. We deleted the lines that were causing it to fail to compile, then copy n pasted the whole code below again, but as one giant multi-line comment, securing us a 1:1 code:comment ratio. We got 7/25, 5 of which was for "Legibility and good coding practices".
I know it's not pure, but Java does force you to think in an object-oriented way. And there are problems where that's an advantage.
The majority of a class's definition is spent defining methods. In Java, methods are not objects.
A large amount of method code is spent looping, branching and exception handling. In Java, loops, branches and exception handlers are not objects.
Scattered liberally throughout all of this, there are type annotations. In Java, types are not objects.
Could you please explain how Java forces me to think in an object-oriented way?
Smalltalk is, since numbers, booleans, etc. are objects, classes are objects, methods (and functions in general, known as "blocks" in Smalltalk parlance) are objects.
Likewise, the only control flow mechanism is the method call. Branching (if/then/else) is a method of the boolean objects. Loops are done via the "times" method of numbers. It's turtles all the way down.
If you have to be taught about dictionaries (1), you're a crappy programmer anyway.
(1) I will accept the denomination "map" also, but they are not called "hashes" damnit.
Just yesterday I wrote some extensions for Solr, you can do it in Groovy (hell even Javascript).
There's very little point in writing things in pure Java these days. Especially if you're just using Java libraries and gluing pieces together, use some scripting language that compiles to bytecode.
Here's one cool thing about Java: The documentation is probably the best of any development ecosystem out there. APIs are wonderfully documented. For an extreme dose of hilarity, compare Javadocs to Nodejs documentation.
Java has become the language of "the noob." For a very large percentage of programmers, it's the first language that's presented to them. As such, there are endless examples of Java projects written by people who are still struggling with basic flow control, let alone project architecture. Some of these projects are written by smart people, and they're genuinely useful. As an example, think of the research biologist who's writing code for her thesis - code for which there's probably no measurable market.
Because it's the language of the noob, it's really easy to gain the kind of experience this author is describing. The kind where you just glide along, "turning the crank" not really learning anything for a long, long time. People come away honestly believing that because they've worked with the language for so long they're experts. That there's nothing left which will surprise them, or change the way they work in this language.
I've seen a lot of cases where these people bump up against some really cool things and never realize it. Because they don't understand it they quickly write it off as bad code/architecture/naming.
One of the most common examples I've seen of this is when people pull class names from the Spring application framework core, parading them around with no context and no knowledge of why they exist or why they might be incredibly useful, let alone why they sometimes make Java a joy to work with.
"AbstractSingletonProxyFactoryBean??! I don't care what it is, that's just stupid!" [1]
How ignorant.
> After all, you produced 576 classes that contain 10,000 lines of Java code, all of it seemingly essential, so you were doing your job.
I can agree that Java is a verbose language, and sometimes it's really difficult to express an abstraction succinctly as compared to some other languages. I can agree that it's also easy for people to run wild and over abstract. However, I think it's just as likely for people to mistake well abstracted code for needlessly verbose code.
> And nobody can glare at you and demand to know why you used 576 classes when you should have used 50...
Without a specific case, it's hard to figure out what's really going on here, but if this is a primary target metric, I'd say you're prioritizing the wrong things.
> ... because in Java doing it with only 50 classes is probably impossible.
Just throw separation of concerns out the window and you can write just about anything in one class.
1: http://docs.spring.io/spring/docs/2.5.x/api/org/springframew...
See, this is a mistake. Abstraction is not an end in itself; it's there to make life easier and to make things easier to undestand.
Bloat is one of the many things abstraction is supposed to reduce; if an abstraction is increasing cognitive overhead and reducing the signal-to-noise ratio, then we've got ourselves a problem.
For reasons that I cannot comprehend, Java seems to be the only language that seems to have excessive abstraction as a requirement. Not as a convenience, not as a nicety, but as a requirement to do things like Dependency Injection, Inversion of Control, Unit Testing, Mocks, logging, etc. The fact that you need to use entire frameworks to accomplish the functionality that in many languages is covered by a couple functions in a built-in module is a mystery to me.
I'm not the wisest expert, but I have over a decade in a field and I've worked in all sorts of different software, and Java (along with some very badly written .NET systems) seems to be the only technology that requires me to grok a dozen files to understand basic workings of MVC systems with the most elementary of logic. And the thing is, 90% of that code is absolutely useless to the extent of the use cases proposed by the system, and none of its potential extensibility is actually used. You have to ask yourself how come neither Python nor Haskell have these monstruous frameworks.
Sure, it's a lot better now, after having caught up 8 years behind the rest of technologies, but the foundations are notoriously complicated for things that are effortless with other tools.
This points to me towards the idea that Java abstractions have simply been poorly chosen.
This idea is often repeated in programmer's forums, yet I think it's simply not true. Abstraction is not there to make things easier to understand, it is there to empower you _after_ you understand the abstraction. It is there to pack the knowledge you _already have_ after working with some system, and being able to port it to similar systems.
Let's take math as an example. Understanding the "+" operator is much harder than understanding that if you have two apples and you get another one, then you have three apples. However, once you grasp the "+" operator, you can quickly solve a bunch of related problems where the "+" operator applies.
This does not mean that I disagree with the rest of your comment though. Java's (classical) means of expressing abstractions are fairly limited - basically, you need _interfaces_ for everything. In most cases, this leads to a lot of cognitive overhead that obscures the essence of the abstraction being used.
A simple example of this problem is the lack of function values and lambda types (pre jdk8). Due to these missing features, people expressed the same abstractions by defining interfaces that define some method, and then providing implementations as anonymous classes. That is, instead of defining a function type and then just implementing it, you now have an interface and weird class declarations in your code. To the untrained eye, this is much harder to understand. As a result, some of the programmer's cognitive effort is now spent on this, and hence it becomes harder to understand the more useful part of the code (which is likely some kind of abstraction).
Just to shed some more light into this, consider Haskell's _monads_. Monads are very hard abstractions to grasp. They are much harder to understand than just "doing whatever you want to do and call it a day". However, they become extremely useful once you understand the abstraction and become available to use it without the cognitive overhead.
I think some abstractions exist for either reason, and some for both reasons, but either way thanks for saying it this way - you definitely put it better than I did.
> Bloat is one of the many things abstraction is supposed to reduce; if an abstraction is increasing cognitive overhead and reducing the signal-to-noise ratio, then we've got ourselves a problem.
I whole-heartedly agree, but I'd caution readers not to conflate abstraction with bloat. If it's bloat, chances are you're abstracting the wrong details, and working on a system suffering from poor cohesion.
> For reasons that I cannot comprehend, Java seems to be the only language that seems to have excessive abstraction as a requirement. Not as a convenience, not as a nicety, but as a requirement to do things like Dependency Injection, Inversion of Control, Unit Testing, Mocks, logging, etc. The fact that you need to use entire frameworks to accomplish the functionality that in many languages is covered by a couple functions in a built-in module is a mystery to me.
I'm not sure I follow. Are you saying that you think it's wrong or inconvenient that these features aren't somehow natively supported by the language? That is, that you'd like to have a grammar/syntax around each one of these things which ultimately boils down to a bunch of hidden runtime anyway?
Maybe it might help to clarify that I'm defending Java the language, not Java the runtime library.
> Java ... seems to be the only technology that requires me to grok a dozen files to understand basic workings of MVC systems with the most elementary of logic
I do agree that web frameworks in Java are one area where there's just tons of bloat, but I still don't think that has anything to do with how the language is designed. My advice: get a better MVC. There's nothing about MVC that says you must use a framework. (Edit: if it's the container that you're fighting with, there are tons of other options out there aside from the mainstream few).
Also, check out the network code in the Linux kernel sometime. Beautiful code, but holy shit do you need to shave a whole heard of yaks the first time you go to read it. The cognitive overhead is high, but each one of those abstractions is there for a reason.
> This points to me towards the idea that Java abstractions have simply been poorly chosen.
Again, given that I'm talking about the language alone, not the runtime library, if you still uphold your response I'd ask you to consider who's fault it might be that the abstractions used in your program(s) are poorly chosen. It's quite rare that it's the fault of the language.
There are certainly unnecessary parts - there's a hell of a lot of bloat in spring - but just doing without frameworks entirely is not the answer.
Sure there are. There's even a version of Spring for Python. It's just that nobody uses them. You're free to guess why.
There are plenty available, just not one dominant one.
> I'm tempted to suggest that Python doesn't have these frameworks because it doesn't bother to support writing large programs.
That probably approximate the truth, in that the brittle "large program" architectural style that IoC/DI approaches seek to mitigate the harms of is probably less popular for large systems where Python is used (or at least the Python parts) which favor smaller programs interacting through standardized communication protocols for constructing large systems.
> Likewise with testing, there's the unittest module but it's not really integrated with a build system or anything else.
Since there is no "build" with python, the fact that its unittest module is not integrated with a build system isn't surprising. There are plenty of tools that support integrating unittest (or other python testing frameworks) in workflows, including utilities that do testing on every file save (similar to autotest in Ruby). Obviously, in the absence of a build step, they aren't integrated into a build system, but the workflows are often better because of the absence of a build step.
Well, last time I needed something similar on Python, I just loaded the settings from the database, included the wanted code at runtime, and inserted the desired symbols at the local context. Took a bit more than a day to write, and was very appliction specific, but saved a lot of trouble with those crazy constructors that appear on Java.
(I am from a Perl environment which have a bit emphasis on tools/libraries and language extensions, because it is easy to do with automatical tests on most every platform/Perl version.)
Modern PHP has cloned that. See for instance the Symfony 2 framework.
So what are you proposing? That everything has to be built in into the platform itself, hidden away from me? In fact, Java not doing so is a big advantage, because it allows me to change the implementation. Otherwise, everything has to be done by the platform developers. I would depend on their resources.
In the Java world, if something is worth to become part of the platform (either a new language feature such as try-with or a new core API or runtime library like Joda Time), it is discussed within the JCP. This created an ecosystem, where I can plan for the next 10 years and not just for the next it-does-everything-dynamic-language cycle-jerk.
BTW. If you want to reduce repetitve tasks, you should use code generation. That's the best abstraction and Java is a nice simple language to generate.
Isn't that one of the design goals of the language? IMHO, the simplicity of Java and the small number of concepts is commendable, but I feel it could have provided identical features in a less verbose way. Take accessors. If Java had Python-like properties, the average size of a Java codebase would shrink by 50 % (though having public final fields everywhere as a convention would work equally well for non-API code - I probably changed a field getter into a computed property once, and it certainly wasn't in public-facing code). Same with qualified imports.
That said, if you have an IDE, you can fold a lot of cruft away. And the business logic part of the code is often very readable (as long as it has been written by decent programmers, obviously).
One thing that puzzled me about the article is the rant about HashMap not being special. There is no special syntax for writing maps, but there is no special syntax in Haskell either, and I haven't seen anybody up in arms about it. If you don't know when you should reach for HashMap, your lack of knowledge in basic data structures will not be fixed by having special syntax. The Java collections library (enhanced by Guava) is one of the best things about the standard library.
Along with PHP (for different purposes, though).
A great application of Poe's Law[1]
I wonder if "cat" would count as a valid answer.
Scanner scan = new Scanner(System.in) while(scan.hasNext()) { System.out.println(scan.nextLine()+"\n") }
How do you think this code will handle binary data? How do you think it'll handle a simple two line text file?
Yeah, but there are solutions that actually solve the problem.
My hate is on the Java code being posted here. It's horribly bad.
The issue is the totally over-engineered APIs
StreamUtils.copy(System.in, System.out)
I'm pretty sure there is a function that just copies an input stream to an output stream in commons-lang.Still I agree with him - I won't write Java in a test like that. It is almost impossible to write Java fast without an IDE to autocomplete everything for you. There are way too many names to remember. I can't even tell you what package StreamUtils are in or if it's StreamUtils or FileUtils.