This is irrelevant, but I just had my first Java experience yesterday. I decided to make an Android app, it's a simple remote control for hobby projects (Raspberry Pi/etc) that gives you a customizable UI with buttons that perform API calls. It'd be pretty simple to do in Python, which is the language I am proficient in, but Android development sounds fun so I wanted to get started in that. Creating the UI was easy e…
Java is old enough that the current best practices recommend using the language and libraries differently than originally intended. For new developers that want to do more than trivial things in Java, reading "Effective Java" will help you avoid many of the pitfalls in the language. As an example, the current best practice around exceptions is that checked exceptions were a mistake. Don't use them in new code. For co…
Javapocalypse
111–120 of 129 posts
Re: Javapocalypse
#112Earlier quoted context omitted.
Type inference = the compiler being able to figure out what types your variables, function arguments, and return values are without you having to explicitly tell it. Polymorphism = the ability to write one function that works for multiple types. So for example, if you want to implement a sorting algorithm, you can write one function that is capable of sorting ints, floats, doubles, chars, and Strings. Java doesn't ha…
What you are describing (calling it overloading,) having different functions of the same name implement different algorithms based on types, is called "ad-hoc" polymorphism, but Java isn't limited to that, and it isn't the best way to do things, because you invariably end up duplicating parts of the algorithm. Java is very capable of writing parametrically polymorphic functions — on object types. They are called Gene…
Ad-hoc polymorphism = overloading functions or methods within a class
Subtype polymorphism = overloading methods from the superclass.
Java is fine for working with objects, but it's just a terrible language for working with primitive datatypes. Part of the reason it's not really used for performance-critical code.
Re: Javapocalypse
#113Earlier quoted context omitted.
> Unfortunately its extreme object-orientation... Like Smalltalk, Eiffel, C#, VB.NET > It's too high-level to be useful for systems or game programming True if you are speaking about AAA games or writing kernels, for everything else lots of people seem to be quite successful using it. > So, it's mostly used for building enterprise web services. And Android apps. And in embedded environments powerful enough to run it,…
I don't know much about the other languages you mentioned, but C# is multi-paradigm, allowing certain functional and declarative programming practices that Java does not. It's much more expressive than Java.
Re: Javapocalypse
#114Earlier quoted context omitted.
I don't know much about the other languages you mentioned, but C# is multi-paradigm, allowing certain functional and declarative programming practices that Java does not. It's much more expressive than Java.
How do you write pure functions and procedures outside classes in C#?
But C# does have closures and lambdas, and lets you use functions as arguments and return values. Java doesn't have any of those yet, although they're supposed to be coming in 1.8.
Re: Javapocalypse
#115Earlier quoted context omitted.
DI will defer the injection to runtime instead of compile time, so you don't get the benefit of type checking during the compile. I've been bitten by this in the past with SpringMVC. It usually ripples up quickly and has never been an issue in a released app.
Yeah, it's not a big risk to production, but it just makes the development loop that much more frustrating. There's nothing more annoying than building, deploying, starting, before discovering that you mispelt a bean name...
My mental model for dependency injection is a little different. I think of dependency injection as a technique instead of a tool. The only tool I used to do DI is a text editor.
Here's an example of how I would use dependency injection (manually) in Java:
interface Dependency {
void doSomething();
}
class Foo {
Foo(Dependency x) { ... }
}
new Foo(new ConcreteDependencyA());
new Foo(new ConcreteDependencyB());
Both instances of Foo receive their dependencies at runtime, but the compiler is going to check that (1) the concrete dependencies are subtypes of the abstract dependency, (2) the concrete dependencies don't throw extra checked exceptions in their doSomething() method, and (3) the dependent class (Foo) only uses the interface of the abstract dependency. I gain the advantages of dependency injection without undermining the language's type safety.Re: Javapocalypse
#116Earlier quoted context omitted.
How do you write pure functions and procedures outside classes in C#?
Yeah, I don't use C# and I don't know if you can do that, I think you have to create a class and declare them as methods like Java. But C# does have closures and lambdas, and lets you use functions as arguments and return values. Java doesn't have any of those yet, although they're supposed to be coming in 1.8.
All primitive types are actually alias for classes and structs that live in the System namespace.
My point was basically from a point of view of someone with compiler development background, if one bashes Java for being OO based, there are lots of other languages to bash for the same sin, which for whatever reason people like to forget.
Re: Javapocalypse
#117Earlier quoted context omitted.
Java is old enough that the current best practices recommend using the language and libraries differently than originally intended. For new developers that want to do more than trivial things in Java, reading "Effective Java" will help you avoid many of the pitfalls in the language. As an example, the current best practice around exceptions is that checked exceptions were a mistake. Don't use them in new code. For co…
I'm really, really sorry that most of today's developers (it seems) consider checked exceptions to be a bad practice. Sometimes I feel like I'm the only person in the world still advocating their usage. I'm currently working on an application that uses libraries developed by people who had the same opinion about checked exceptions as you. Of course, their code still throws exceptions. Except now, I don't know whether…
You're not alone. I find checked exceptions to be an invaluable language feature.
Re: Javapocalypse
#118Earlier quoted context omitted.
Yeah, I don't use C# and I don't know if you can do that, I think you have to create a class and declare them as methods like Java. But C# does have closures and lambdas, and lets you use functions as arguments and return values. Java doesn't have any of those yet, although they're supposed to be coming in 1.8.
Still it makes it fundamentally an OO language, because C# closures and lambdas are mapped to System.Delegate class. All primitive types are actually alias for classes and structs that live in the System namespace. My point was basically from a point of view of someone with compiler development background, if one bashes Java for being OO based, there are lots of other languages to bash for the same sin, which for wha…
Re: Javapocalypse
#119This is irrelevant, but I just had my first Java experience yesterday. I decided to make an Android app, it's a simple remote control for hobby projects (Raspberry Pi/etc) that gives you a customizable UI with buttons that perform API calls. It'd be pretty simple to do in Python, which is the language I am proficient in, but Android development sounds fun so I wanted to get started in that. Creating the UI was easy e…
Java is verbose. Tooling is great, however. For exceptions, there are two types. Checked exceptions and runtime exceptions. * Checked exceptions need to be explicitly handled in your code, or it doesn't compile. * Runtime exceptions can just happen, you don't need to check them. I personally don't really like the runtime exceptions because they can hide in thousands of place and throw when you don't expect it. Howeve…
Re: Javapocalypse
#120Earlier quoted context omitted.
Still it makes it fundamentally an OO language, because C# closures and lambdas are mapped to System.Delegate class. All primitive types are actually alias for classes and structs that live in the System namespace. My point was basically from a point of view of someone with compiler development background, if one bashes Java for being OO based, there are lots of other languages to bash for the same sin, which for wha…
Well, Ruby is OO too, even moreso than Java because there are no primitives in Ruby. Even the "integers" in Ruby are not ints but objects with lots of methods. But Ruby has a lot of powerful, functional, expressive, declarative, and meta language features that Java lacks. Java is like an OOP straightjacket, that's why it gets so much hate.
Most modern languages are all OO based in some form, while being more flexible, like your example.
Java 8 will probably improve the situation. At least on the enterprise level, I don't see it moving away from Java and .NET anytime soon.