Re:If Java Is Dying, It Sure Looks Awfully Healthy
by cmircea on Thursday October 10, 2013 @07:49AM
(#6526892)
C# has had type inference for a long while. It's a pain using Java, which doesn't.
C# also sort of implements type classes. For your example, there's IComparable in C#; implement it and a List<SomeObject> can be directly sorted.
For pure functions, there's the [Pure] attribute, but it isn't enforced by the compiler, it's just a contract, a promise.
Re:If Java Is Dying, It Sure Looks Awfully Healthy
by quchen on Thursday October 10, 2013 @08:14AM
(#6526993)
Yes, there are languages that also have these features, the puzzling part is why not all of them do (except those that may have good design reasons not to).
Re:If Java Is Dying, It Sure Looks Awfully Healthy
by ufo on Thursday October 10, 2013 @08:51AM
(#6527240)
Its hard to implement type inference and type classes unless you carefully design the language to accommodate it from day 1. For example, return-type polymorphism (functions like `read` or `return`) is particularly tricky, specially in the more dynamic languages.
Re:If Java Is Dying, It Sure Looks Awfully Healthy
by frankzinger on Thursday October 10, 2013 @10:39AM
(#6527982)
"- Type classes: unifying things that "can do X", allowing the programmer to write functions that do similar things but work on many different types. A "sort" function can then be written for all things that "are containers of elements that can be compared". (Again, Rust adopts this.)"
This is what templates do in C++.
- Type inference: strong typing at the convenience of weak typing. (Some languages are moving towards this. C++ stapled on `auto` keywords, Rust is designed using it)
- Type classes: unifying things that "can do X", allowing the programmer to write functions that do similar things but work on many different types. A "sort" function can then be written for all things that "are containers of elements that can be compared". (Again, Rust adopts this.)
- Allowing separation of pure and impure functions. Imagine having a "pure" keyword that guarantees that a function doesn't have side effects. The benefit of this cannot be overstated in a multithreaded environment.