6 ms·
Why and how I write Java
- banachtarski 13y ago> High efficiency languages include C, C++, Rust, D, etc. I would love one language to rule them all, but it seems that for now there is still a gap between what language to choose application programming and for high efficiency programming. What is this supposed to mean?
- andrewflnr 13y agoIt was also pretty weird to see Erlang on that list. Erlang may be good at parallelism, but I've never heard that BEAM is especially fast at sequential operations. edit: s/linear/sequential/
- derefr 13y agoGiven that he's a web programmer, I presume "high efficiency" in this case means "getting the most out of the hardware" in a more general sense, to which "idiomatic code is automatically concurrent" contributes quite a lot in some cases.
- banachtarski 13y agoYou're confusing "parallelism" with "concurrency." Also, being fast at sequential operations (throughput) is often times not as useful as having low latency.
- frenchy 13y agoFor most programming, as long as your algorithms are not stupidly slow, clarity is more important than efficiency. In certain situations (video games, embedded devices with few resources) this is less true, and things like the ability to do manual memory management becomes a lot more important.
- banachtarski 13y agoThis is more or less how I interpreted the statement. But grammatically it's hard to parse and I felt it needed a lot of clarification. You're assuming the memory model was the cause of a loss of application clarity but I know many programmers that don't actually feel this is the case.
- hnriot 13y agonot most programming. For client side ui work maybe, but pretty much everything I do algorithmic efficiency is a big concern. It's this sort of attitude that gives java it's reputation for being slow and results in behemoth's of software like weblogic.
- lukasm 13y agoHigh efficiency is misleading. They should be called explicit resource management languages.
- wedig 13y agoI've tried explaining this using terms like system programming or high efficiency programming. I guess it is best to just say "explicit memory management", so I updated the post.
- Xdes 13y ago>Diamond operator Wow. So instead of adding something like var in C# or auto in C++ they went the opposite way. Makes no sense to me.
- twic 13y agoI suspect this was because it was a smaller change. Inferring from the type of the variable to the type of the expression only has the inferred type flowing inwards to smaller scope. Inferring from the expression to the variable gets inferred types spreading out over the whole program. That is possible, and is how many languages work, but it would have been a huge change for Java. For better or for worse, it's in the nature of Java to be conservative, and not make huge changes.
- eropple 13y agoThe diamond operator isn't variable type inference, it's parameter type inference for generics. It should have var/auto, for sure, but this is a different thing.
- deleted 13y ago[deleted]
- M4N14C 13y agoHe could rewrite that entire blog post as a one liner in Ruby.
- blueblob 13y agoNot sure if the author of this post is on or not but what did you mean when you say you use java for scripting?
- wedig 13y agoI took this out because it was unclear. I meant scripting in the sense that Python and Ruby are called "scripting languages". One possible policy is to use Java for your application, and something like Python to write scripts for stuff like devops or whatever else "scripting" is. Instead of this, I prefer use one language as much as possible, currently Java.
- greatsuccess 13y agoI rolled my own java scripting tool. Its pretty easy to do, but I think that most folks do this with Groovy now.
- vorg 13y agoQuick & dirty scripts for testing and such where speed doesn't matter is Groovy's strength. Its managers at VMware are trying to use the Groovy distro as a delivery channel to sneak other unrelated software into businesses, such as a static compiler and type checker which were written by one person only and have virtually no commercial use. There's many other higher quality languages out there for JVM static compilation, e.g. Java 8, Scala, Ceylon, Kotlin, each of which have far larger teams working on them.
- greatsuccess 13y agoA little surprised Spring is not mentioned. Composition in Java is a nightmare without Spring, and you can do some really interesting things in configuration that would take you days of writing initialization code in very little time. If not for Spring, I'm not sure I would want to construct things in Java at all.
- epper 13y agoHe does mention Dependency Injection briefly. Anyway Spring is just one option (e.g. Guice is another one).
- greatsuccess 13y agoTrue, I just dont like Google's take on Java so I dont use any of their libraries.
- suyash 13y agoBecause he doesn't use Spring, he uses GWT.
- sfjailbird 13y agoThere is no overlap between the two, you can use Spring with GWT as easily as with any other project. You probably mean Spring MVC.
- jayvanguard 13y ago> With Java I have one language that can target servers, Android, and browsers via Google Web Toolkit (GWT). Credibility shot. He's a fan of GWT. That explains a lot.
- wedig 13y agoI really like GWT. I will be writing some posts that will go into more detail.
- jayvanguard 13y agoI kid... partly. What I can't get over is a common justification for using GWT seems to be "but you can program in java and Swing then!", which only holds for fans of Swing. It seems is most often advocated by people uncomfortable with Javascript development and little UI development experience outside of Java. I don't think Swing is terrible but I do think it isn't particularly productive for user interfaces compared to Javascript or even Objective-C, C#, etc. So if all you have a Java/Swing hammer then GWT is great, otherwise not so much. In any event, I look forward to your post.
- wedig 13y agoNo worries then :) I'm comfortable with JavaScript and I've never used Swing. I just use GWT to reach the browser, not to embrace it as an all encompassing framework or anything. I use Bootstrap as the UI starting point.
- curun1r 13y agoI gave up on GWT ~3 years ago, so some of this might have changed since then, but here is my list of things that annoyed me: * Compilation speed. Even when I dug into the compiler to increase parallelization, it was still dog slow. Yes, running in hosted mode helps, but compiles were still frequent enough that we'd have coffee breaks simply to wait for the compiler to finish. * Testing. GWTTestCase never worked right for me. And tests that don't run in pure Java are, again, slow. We got around it by writing a Java agent to transform the bytecode at classload time to intercept all of GWT's native methods, but this was a huge PITA. * Doesn't play well with others. The way that GWT loads makes it difficult to use on concert with other front-end frameworks/technology. * The inability to embed structured data in the page. The serialization in GWT's RPC is fantastic. Embedding type-unsafe JSON for reference data in a page seemed wrong. But GWT didn't give any supported way to serialize and deserialize outside of an RPC call. We eventually figured it out, but the solution involved having to sometimes include unused code in a RemoteService to ensure that the deserialization code was compiled in, which always felt hackish). Still, for what it was, GWT was always impressive. It's performance always beat what we were able to achieve with hand-coded JavaScript. Chrome has somewhat lessened the need to write high-performance JavaScript, but it's still impressive that GWT's generated code was that fast. And I've yet to encounter another RTE that was as easy to use and "just worked" as well as GWT's RTE. Every time I'm asked to do something with CKEditor or any of the native JavaScript options, I always wish that it was possible to use GWT's editor outside of a GWT application.
- andrewflnr 13y agoHaving been exposed to OCaml, I'm starting to think that if you have null references, you don't really have static typing. I guess I'll have to look at guava, but it can only help so much in interacting with other code.
- dasil003 13y agoAs a rubyist by day this is the thing I find so exciting about Haskell. I write dynamically-typed code all day, and the most common bugs are not because of passing an Apple to an Orange interface—that just isn't very common—it's because of cascading nulls. Of course Java's static checks are worth something, but not much more than the most cursory of checks that my basic test coverage does in Ruby.
- frou_dh 13y agoMy takeaway from looking into OCaml was that pattern-matching with exhaustiveness checking was the jewel, as contrasted with primitive C-style if/else chaining or switches.
- andrewflnr 13y agoRight, exhaustiveness checking is how the compiler makes sure you handle missing values (option types) correctly. I guess you could say that's one of the bigger payoffs.
- oafitupa 13y agoRuby could really use optional typing, like what PHP and Clojure have.
- fleitz 13y agoAnd especially not if you have type erasure. Java makes you type class names, and the compiler makes you cast things, as for it being a statically typed language, I'm not really sure. As with most things java it's a lot of typing for not a lot of accomplishing anything useful, but somewhat better than C. OCaml/F#/Scala have far better type systems that check a lot more things, and require less typing.
- mwcampbell 13y agoDo you use a framework for routing and handling HTTP requests, or just servlets? What about accessing the database, if any? I assume you're not using Java EE. EDIT: For iOS, http://j2objc.org/ http://j2objc.org/ can help you share code between platforms, but you'll still do the UI and other platform-specific things in ObjC.
- wedig 13y agoI use GWT-RPC because it is easy. For other clients I wanted to try Thrift. I like what Evernote did: https://blog.evernote.com/tech/2011/05/26/evernote-and-thrift/ https://blog.evernote.com/tech/2011/05/26/evernote-and-thrif... Thanks for the j2objc tip! I will definitely be looking into that. I thought Thrift was as far as I could reach into iOS without Objective-C. I haven't used J2EE. My experience with Django years ago made me framework adverse. I will be posting a sample app in a month or two that shows what I mean.
- dkuntz2 13y agoIf you're looking for a small and simple HTTP framework in Java, I've been working on one that I think is really nice (you might think the exact opposite): https://github.com/dkuntz2/java-httpserver https://github.com/dkuntz2/java-httpserver
- Untit1ed 13y agoEclipse is silly no matter what language you use... yet he uses Eclipse?
- cgh 13y agoFor me, this was the most amazing thing about this post: "Programming with explicit memory management: This bucket includes C, C++, Rust, D, etc. I haven’t needed to explicitly manage memory, so I haven’t used these." I guess I'm just old.
- sramsay 13y agoMaybe I am too, but that phrase just bugged me. Surely there are other reasons to use these tools than just "explicit memory management?" I suppose I could say, "I haven't used any JVM languages, because I haven't felt the need to gouge my eyes out over memory errors I can't control."
- jtheory 13y ago> Surely there are other reasons to use these tools than just "explicit memory management?" Sure, though he does mention he's biased by the projects he works on (generally web apps/services -- not device drivers, image processing, realtime anything, etc.). > I suppose I could say, "I haven't used any JVM languages, because I haven't felt the need to gouge my eyes out over memory errors I can't control." The phrase that bugged you wasn't cast as an insult, though, and yours is... mysterious; Java's GC is quite stable, so any memory-related errors are under the coder's control. "Memory errors" being basically just "using too much memory", as I've never seen any other type of memory error in Java. Maybe you could say "I haven't used any JVM languages, because I've never felt the need for automated memory management"? That assumes Java has nothing else to offer.
- primitivesuave 13y agoI think one thing that this post touches on is the effectiveness of Java as a programming language for large projects. Although personally I've moved on to Python since it greatly simplifies web-related tasks, a lot of our legacy projects are in Java and I still hear plenty of people sipping the Java haterade. So I thought I'd share some of the most common things I hear. Only my grandpa writes in Java anymore. I hired a junior developer a couple months ago who absolutely refused to write code in Java, swayed by the vitriol that is often spewed by highly opinionated developers against Java. Instead of taking the time to learn the language, he read up on all the Java Versus Everything Else rants out there and emailed me links to them, trying to convince me that his arrival meant our code base should be rewritten in a "more modern language". Needless to say that he didn't last very long. The fact remains that Java is an incredibly mature language that runs much faster than most other solutions, and makes it significantly easier to handle the complexity of a large project. There is an enormous ecosystem of libraries for Java, and it would be foolish to move to a less mature language which needs more wheel reinvention. Garbage collection is bad. There are the obvious downsides to garbage collection, e.g. Android apps running on low-memory devices, but for an enterprise application running on a server you shouldn't be breaking balls about garbage collection. Obviously it would run 10 - 30% faster in C, but we live in a day and age where it is cheaper to provision extra servers than it is to pay people for the extra man-hours they spend gdb-ing for segfaults and valgrind-ing for memory leaks. It is much easier to pick up a good Java developer than a good C developer, because the good C developers have already been picked up by the big companies that actually need the performance advantage. And from my experience working in a company on an enormous C code base, I know firsthand how easy it is to pick up a really shitty C developer. It seems like most of my Java code is just checking for errors. Would you rather not check for errors? What I mean is, would you rather allow a single developer's "return null" statement that was absentmindedly used to handle a rare edge case to completely fuck your application when that edge case is actually reached? Pardon my French, but I'd rather take the time to throw/catch exceptions than get fucked by a gung-ho developer's null, since Java will force exceptions to be caught and handled at some level. With a well-architected solution, error handling can be centralized and developers can more easily contribute to the codebase if the throw-catch paradigm is part of the coding standard. Java's GUI capabilities really suck. This one can't really be refuted - Java's Swing UI components are indeed quite shitty. But you can work around them by creating your own Swing components, and enjoy the benefits of a cross-platform solution. I know this rant was long, but a lot of it was taken from emails that I've sent to my devs in our Java vs. no-Java threads. I'm no Java fanboy, but I am better than most at seeing past the haterade to where it works and where it doesn't work. Maybe I'm wrong, but my experience is a bit more practical than just reading an article that nitpicks at Java's perceived downfalls.
- gebe 13y agoAs a sidenote regarding iOS, you could checkout http://www.robovm.org/ http://www.robovm.org/. It's already used for running libgdx (a Java game framework for a number of platforms) games on iOS for example.
- smegel 13y ago> I use Java for application programming. I recommend Python or Ruby for learning programming. Define "application". There are plenty of cases where Python or Ruby makes sense. And Java actually makes sense as a learning language aswell, as it has more OO depth which is what most courses focus on largely, without the pain of trying to teach students C++.
- _pmf_ 13y ago> Define "application". I think he/she defines application as "application", as opposed to the web folks' definition that a web site having a text box, a button and 1 mb of JS libraries is an application.
- deleted 13y ago[deleted]