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!
Re:Ladies, look at your code. Now back to mine.
by csmeder on Saturday August 28, 2010 @12:40PM
(#1641925)
Wow, what an ad hominem answer:
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.
Re:Ladies, look at your code. Now back to mine.
by Locke1689 on Saturday August 28, 2010 @08:49PM
(#1642783)
I think you misunderstood me: I was saying that the notion of who is a "real" programmer is stupid. I really despise using PHP. Does that make everyone who works at Facebook not a "real" programmer?
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.
Re:Ladies, look at your code. Now back to mine.
by InclinedPlane on Saturday August 28, 2010 @02:57AM
(#1641375)
Considering that Javascript, Ruby, Python, C#, Perl, and even PHP have supported anonymous functions or lambda expressions, this advancement is a long time coming.
Re:Ladies, look at your code. Now back to mine.
by Locke1689 on Saturday August 28, 2010 @03:03AM
(#1641385)
Oh God it's so much worse than that. You remember who was a coauthor on the original specification? Guy Steele. Yes, "Lambda Papers" Guy Steele. I have no idea how this has taken so long.
Re:Ladies, look at your code. Now back to mine.
by _delirium on Saturday August 28, 2010 @03:33AM
(#1641416)
While Steele's been involved with Lisp and Scheme, he also has a really long history of involvement with imperative languages, which he seems to have kept separate until recently. He's been on the C and Fortran standards committees, for example, and that hasn't caused much noticeable crossover of features like lambdas into those languages, either.
Re:Ladies, look at your code. Now back to mine.
by Locke1689 on Saturday August 28, 2010 @04:19AM
(#1641461)
Well, that's true to a certain extent. Closures and such really just don't make sense in a C context, especially with manual memory management. Function pointers are probably the most implementation friendly solution in that problem space. I think Apple's blocks are the closest that we'll come, but I'd be hesitant to use them in certain subdomains.
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.
Re:Ladies, look at your code. Now back to mine.
by tjr on Saturday August 28, 2010 @10:13AM
(#1641755)
Guy's words: We were not out to win over the Lisp programmers; we were after the C++ programmers. We managed to drag a lot of them about halfway to Lisp.
Re:Ladies, look at your code. Now back to mine.
by nocman on Saturday August 28, 2010 @04:27PM
(#1642339)
I think it is also important to remember something else here. Guy Steele certainly had significant influence on Java, but he was far from the final decision maker. I'm sure there are tons of things he would have wished Java to have (or not have) but they weren't his call to make. If anything people should be grateful that he was involved at all, since Java would probably have been a lot worse off it he hadn't been.
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.
Re:Ladies, look at your code. Now back to mine.
by blub on Saturday August 28, 2010 @01:35PM
(#1642023)
In 1996 C++ was much more difficult and fragmented, but that quote is from 2003. Today C++ has (much) more abstraction power than Java. On the other hand, almost every programming language has more abstraction power than Java, which knows only about classes, XML and design patterns.
Re:Ladies, look at your code. Now back to mine.
by etal on Sunday August 29, 2010 @02:42PM
(#1644262)
We might be agreeing here already, but my understanding was that the mindset Java fought against -- and finally won -- was: Interpreted, garbage-collected languages, or basically anything with a substantial runtime component, will be too slow and unpredictable to use in serious production environments.
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.
Re:Ladies, look at your code. Now back to mine.
by blub on Monday August 30, 2010 @11:45AM
(#1646514)
Lots of languages are fashionable today, but most of them don't overlap with the use cases that are traditionally handled by C++.
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.
Re:Ladies, look at your code. Now back to mine.
by philwelch on Saturday August 28, 2010 @11:44PM
(#1643077)
"In 1994, Steele joined Sun Microsystems and was invited by Bill Joy to become a member of the Java team after the language had been designed, since he had a track record of writing good specifications for existing languages." --Wikipedia
Re:Ladies, look at your code. Now back to mine.
by jlouis on Saturday August 28, 2010 @06:06AM
(#1641547)
You still need to hope the fusion optimization kicks in there. It can be done faster with one filter over the list and then checking all three predicates at each element in some cases. I think the following will do the right thing:
Re:Ladies, look at your code. Now back to mine.
by Nitramp on Saturday August 28, 2010 @04:38AM
(#1641476)
I think you will be, if they manage to get extension methods into this properly. Also, Google's Iterables could return a FilterableIterator or something like that, so you could at least chain after the first step.
Re:Ladies, look at your code. Now back to mine.
by didip on Saturday August 28, 2010 @04:34PM
(#1642349)
Joining the club, in Python:
[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
Re:Ladies, look at your code. Now back to mine.
by Confusion on Saturday August 28, 2010 @06:15AM
(#1641553)
Personally, I prefer your version; the &: version starts reeking of Perl line noise. Although I believe Ruby would benefit from an _ for not explicitly named block arguments.
Re:Ladies, look at your code. Now back to mine.
by steveklabnik on Saturday August 28, 2010 @02:25PM
(#1642130)
As a random note for anyone who's wondering how this syntax came about, this is the Symbol#to_proc [1] method, which was actually a monkeypatch from Rails that ended up making its way back into Ruby proper.
Re:Ladies, look at your code. Now back to mine.
by wuputah on Saturday August 28, 2010 @12:35PM
(#1641915)
That was fixed some time ago. It is very marginally slower to use Symbol#to_proc now (a constant time difference to actually create the Proc), but not enough to warrant a change in practical use.
Re:Ladies, look at your code. Now back to mine.
by statictype on Saturday August 28, 2010 @04:00AM
(#1641441)
Correct me if I'm wrong but I believe the C# compiler goes a step further and allows you to write those lambda arguments without the type annotation. Is there a technical reason why the Java compiler can't do the same?
Re:Ladies, look at your code. Now back to mine.
by StrawberryFrog on Saturday August 28, 2010 @05:55AM
(#1641542)
C# will infer lambda argument types from context, yes. So the code given:
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.
Re:Ladies, look at your code. Now back to mine.
by henrikschroder on Sunday August 29, 2010 @05:53AM
(#1643541)
What do you mean, that you can do something like this?
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.
Re:Ladies, look at your code. Now back to mine.
by StrawberryFrog on Sunday August 29, 2010 @02:43PM
(#1644265)
Could you expand on what "program to an interface" means to you in this context, I'm not getting it. Assume that I know what it means in the usual context, of depending on the services of an interface type not a concrete type.
Re:Ladies, look at your code. Now back to mine.
by nitrogen on Wednesday September 01, 2010 @11:30AM
(#1653036)
It's interesting that the latest Java does not include the var keyword, as JavaFX (which is modeled after JavaScript) uses the var keyword and does type inference on regular Java types.
Re:Ladies, look at your code. Now back to mine.
by Jach on Saturday August 28, 2010 @05:06PM
(#1642413)
He should have thrown in the new feature for meaningless underscores in numeric literals. I've always wanted this feature in every language, since 1_000_000 is so much more readable than 1000000 or 106.
Re:Ladies, look at your code. Now back to mine.
by whatusername on Saturday August 28, 2010 @08:50AM
(#1641692)
And since you missed it - about a month ago Old Spice did a great internet level promotion with this ad - answering questions from facebook / reddit / youtube / twitter. And cleverly targeted videos at people like Kevin Rose. It was really impressive.
HN had the post about how they did it here: http://news.ycombinator.com/item?id=1516195
And the key discussion about the campaign was here: http://news.ycombinator.com/item?id=1512225
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
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.
As for filter, I presume something like
would work.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...
1: http://ruby-doc.org/core-1.9/classes/Symbol.html#M000031
employees.findAll { it.isPartTime() }
Both are still syntactic sugar implemented as compiler tricks, but the C# one simply does more.
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
http://www.youtube.com/watch?v=TBcxwrNTpGg#t=1m38s