Ladies, look at your code. Now back to mine.
google.com
google.com
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4472509
Lots of the shortsighted decisions in the historical bug database can be attributed to xxxxx@xxxxx, who dismissed this as "yet another request for a syntactic sugar to save some user from typing... not worth it." I sure hope Oracle has let xxxxx go by now!
shankar.unni
I agree with the Evaluation, completely. This is truly pointless syntactic sugar, unless you're coming directly from the C# or Visual Basic world without ever having worked in any other language, and escape sequences are just too hard for you to comprehend.. (In which case, many other Java features would be, too..)
This is sad, some one offers a great language feature that will reduce bugs and save money and people respond with insults.
However, the notion of a Java programmer deriding others for their language choice is even more ridiculous because of the comparative ease of the syntax. If the argument held any merit (which it doesn't), Java definitely wouldn't be on top of the "real programmer" mountain.
Oh and I thought this was hilarious. :)
Java, on the other hand, has a completely different application space and feature set. First class functions and anonymous functions seem like natural additions to the language.
The wise are not dogmatic.
And to top it off, Guy seems to have that rare combination of being simultaneously super smart and reasonably humble. I have never read anything he's written or listened to any talk he's given where I was not greatly impressed by him and what he had to say.
I don't think I've ever seen him comment on Hacker News. I wish we could get him to comment regularly here, as his knowledge and insight would be of great value.
So Java went all-out with (1) a static type system and basic language features that C++ coders could respect, (2) a level of hype and corporate sponsorship/support that PHBs could respect, (3) a portable, eventually fast VM, opening up some nice deployment options. There was no need to introduce really exciting language features, only to keep promoting the OOP concepts that C++ thought-leaders were so enthusiastic about at the time.
> almost every programming language has more abstraction power than Java
Just curious: how does that make C++ stack up against other "fashionable" languages?
Even so, it fares pretty good. What it lacks in expressive power it makes up in speed, libraries and industry support. C# is in my opinion a realistic C++ alternative or complement.
It's silly to have to type stuff that's easily understood by both the programmer and the compiler.
employees.filter(predicate1).filter(predicate2).filter(predicate3)
instead of Iterables.filter(Iterables.filter(Iterables.filter(employees,predicate1), predicate2), predicate3) filter predicate1 . filter predicate2 . filter predicate3 $ employees
Where . is function composition. filter (\x -> p1 x && p2 x && p3 x) employees
which can then be made points-free. {-# RULES
"filter/filter" forall f g xs. filter f (filter g xs) = filter (f.g) xs
#-}
It's a programmable programming language. forall f g xs. map f (map g xs) = map (f.g) xs
?As for filter, I presume something like
forall f g xs. filter f (filter g xs) = filter (\x. g x && f x) xs
would work. forall f g xs . filter f (filter g xs) = filter (\x -> g x && f x) xs
was exactly what I meant, thanks for the catch!employees.filter(predicate1, predicate2, predicate3);
@employees.grep($predicate1 & $predicate2 & $predicate3);
The predicates can be a function, a regex, a type, or anything that can be smart-matched against.
Alternately, if you want to get the employees that match any of the predicates, you'd do the following:
@employees.grep($predicate1 | $predicate2 | $predicate3);
Or, if you want the employees that match only one of the predicates (think of xor):
@employees.grep($predicate1 ^ $predicate2 ^ $predicate3);
These can also be written, respectively, as:
@employees.grep(all($predicate1, $predicate2, $predicate3)); @employees.grep(any($predicate1, $predicate2, $predicate3)); @employees.grep(one($predicate1, $predicate2, $predicate3));
And, if you want things that match none of the predicates:
@employees.grep(none($predicate1, $predicate2, $predicate3));
You can combine these junction constructors. For example:
@employees.grep(all($predicate1, $predicate2) ^ $predicate3);
employees.filter( _.isPartTime )
And it runs in the same virtual machine.
[e for e in employees if e.isPartTime()]
You can even push it further:
[e for e in employees if e.isPartTime() or e.lazy() or e.havePassiveIncomeAlready()]
and further:
[e for e in employees if e.isPartTime() or e.lazy() or e.havePassiveIncomeAlready() or e in [exec for exec in BoardofDirector.all() if exec.haveTooManyPortfolio()]]
Above is your friendly neighborhood List Comprehension available since Jython 2.0
employees.find_all &:isPartTime
Crikey, should buy a book...
employees.findAll { it.isPartTime() }
(filter :part-time? employees) return Iterables.filter(employees, {Employee e -> e.isPartTime()});
Would be in C# (Since you'd also omit the { } and use "=>" not "->") something like this: return Iterables.filter(employees, e => e.isPartTime());
And it is a better C# idiom to make "filter" an extension method on IEumerable<T>. return employees.filter(e => e.isPartTime());
In fact, the existing extension method "Where()" is what you want. return employees.Where(e => e.isPartTime());
C# has had this for about 2 years now. And it is good. So, I'm looking at your code, and back to mine. Mine is shorter but still very readable (to me anyway). And it stays readable when you chain methods, e.g. return employees.Where(e => e.isPartTime()).ToArray();
I'll stay with mine right now. List<Ticket<ThingYouLove>> tickets = new ArrayList<Ticket<ThingYouLove>>();
You could write: List<Ticket<ThingYouLove>> tickets = new ArrayList<>();"
Nice, but I prefer C# there as well where you use the var keyword, like this: var tickets = new ArrayList<Ticket<ThingYouLove>>(); Nice, but I prefer C# there as well where you use the var keyword, like this:
var tickets = new ArrayList<Ticket<ThingYouLove>>();
Actually, JDK7 is better in this case because it helps developer to "program to an interface". List<Foo<Bar>> list = new ArrayList<>();
Programming to an interface is relevant between method calls, not inside the scope of a single method, which is typically where you use the var keyword in C#. This is programming to an interface, in C#, using the var keyword: public List<Foo<Bar>> MyMethod(...) {
List<Foo<Bar>> result = new ArrayList<Foo<Bar>>();
...
return result;
}
var list = MyMethod(...); //list will be of type List<Foo<Bar>>
In Java, the above would then look like this: public List<Foo<Bar>> MyMethod(...) {
List<Foo<Bar>> result = new ArrayList<>();
...
return result;
}
List<Foo<Bar>> list = MyMethod(...);
You don't save more characters in either case, neither is promoting programming to an interface more than the other, but I still think the var keyword is the better construct, since it removes type declaration consistently. It basically means that the compiler should infer the type of the variable immediately, without me having to spell it out. The Java construct on the other hand means something like: "In the constructor to a generic class, infer the generic parameters from the type of the variable the result is assigned to", which is a weaker construct, a less expressive one, a less flexible one.Both are still syntactic sugar implemented as compiler tricks, but the C# one simply does more.
List<Foo> list = new ArrayList<Foo>();
...is programming towards an interface, whereas var list = new ArrayList<Foo>();
...isn't, because the type of list will be ArrayList. I think his point was that with the new Java stuff you could instead do List<Foo> list = new ArrayList<>();
...which would then be explicitly programming towards an interface, while still not having to type so bleeding much.And quite possibly very drunk.
edit: oh I get it, he's referring to http://www.blogher.com/im-horse-old-spices-man-your-man-coul.... This is what I get for not watching tv anymore, I guess.
You can see the full list (that does get rather repetitive -- although keep in mind they were coming out about every 20 minutes for 2 days straight) here: http://www.youtube.com/user/OldSpice#p/u