7 ms·
Ladies, look at your code. Now back to mine.
- InclinedPlane 16y agoConsidering that Javascript, Ruby, Python, C#, Perl, and even PHP have supported anonymous functions or lambda expressions, this advancement is a long time coming.
- Locke1689 16y agoOh 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. Oh and I thought this was hilarious. :)
- _delirium 16y agoWhile 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.
- Locke1689 16y agoWell, 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.
- 10ren 16y agoHe also co-authored the Java Language Specification (with James Gosling and Bill Joy.) The wise are not dogmatic.
- koenigdavidmj 16y agoHe's also responsible for^W^Wthe author of http://www.careferencemanual.com/ http://www.careferencemanual.com/ .
- michael_dorfman 16y agoDamn, Fortran with lambdas-- that would be cool.
- tjr 16y agoGuy'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.
- blub 16y agoIn 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.
- rbanffy 16y ago> Today C++ has (much) more abstraction power than Java. > almost every programming language has more abstraction power than Java Just curious: how does that make C++ stack up against other "fashionable" languages?
- blub 16y agoLots 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.
- etal 16y agoWe 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.
- philwelch 16y ago"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
- aaronbrethorst 16y ago> I'm on a horse. 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-could-smell http://www.blogher.com/im-horse-old-spices-man-your-man-coul.... This is what I get for not watching tv anymore, I guess.
- Qz 16y agoOr even HN? There was a fair amount of coverage of the Old Spice man on here when they were doing their nonstop live commercial shoots.
- deleted 16y ago[deleted]
- aaronbrethorst 16y agoI spend a fair amount of time reading HN, but this is one of the topics I skipped over.
- baguasquirrel 16y agoDid this strike anyone else as being mildly chauvinistic?
- lotharbot 16y agoIt's a parody of an Old Spice commercial (official version at http://www.youtube.com/watch?v=owGykVbfgUE http://www.youtube.com/watch?v=owGykVbfgUE ).
- baguasquirrel 16y agoWow, nevermind then. That was hilarious.
- erikpukinskis 16y agoThanks for speaking up about chauvanism though! :)
- whatusername 16y agoAnd 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 http://news.ycombinator.com/item?id=1516195 And the key discussion about the campaign was here: http://news.ycombinator.com/item?id=1512225 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://www.youtube.com/user/OldSpice#p/u
- skoob 16y ago"If you want to sound like a creep, just add the word 'ladies' to the end of things that you say" -- Demetri Martin http://www.youtube.com/watch?v=TBcxwrNTpGg#t=1m38s http://www.youtube.com/watch?v=TBcxwrNTpGg#t=1m38s
- muyyatin 16y agoIn Scala you can just do: employees.filter( _.isPartTime ) And it runs in the same virtual machine.
- erikpukinskis 16y agoIn Ruby: employees.find_all &:isPartTime
- patio11 16y agoAnd I liked employees.select {|employee| employee.part_time?} Crikey, should buy a book...
- Confusion 16y agoPersonally, 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.
- mark_l_watson 16y agoI agree, I also prefer the slightly longer version. OK, enough small talk ... :-)
- steveklabnik 16y agoAs 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. 1: http://ruby-doc.org/core-1.9/classes/Symbol.html#M000031 http://ruby-doc.org/core-1.9/classes/Symbol.html#M000031
- jarin 16y agoThank goodness Symbol#to_proc was introduced in Ruby 1.9, the Rails implementation of it was slow as hell: http://www.lukeredpath.co.uk/blog/optimising-symbol-to_proc.html http://www.lukeredpath.co.uk/blog/optimising-symbol-to_proc....
- statictype 16y agoCorrect 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?
- StrawberryFrog 16y agoC# 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. return employees.Where(e => e.isPartTime()).ToArray(); I'll stay with mine right now.
- statictype 16y agoMinor nitpick: The lambda operator in C# is "=>"
- StrawberryFrog 16y agoWhoops, I have fixed that cut-and-paste error. I hadn't noticed that the java code had another gratuitous difference.
- jules 16y agoYou have to use => instead of ->. This got me many times too ;)
- StrawberryFrog 16y agoGood point - this is the first time it's got me, but then I don't look at much java.
- mhansen 16y agoIt's sad that you can't easily chain these methods. e.g. employees.filter(predicate1).filter(predicate2).filter(predicate3) instead of Iterables.filter(Iterables.filter(Iterables.filter(employees,predicate1), predicate2), predicate3)
- Nitramp 16y agoI 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.
- jrockway 16y agoThat's what's nice about functional programming, where functions are functions, not thingies inside your object. You would write something like: filter predicate1 . filter predicate2 . filter predicate3 $ employees Where . is function composition.
- jlouis 16y agoYou 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: filter (\x -> p1 x && p2 x && p3 x) employees which can then be made points-free.
- lsb 16y agoDon't just hope, write it yourself! {-# RULES "filter/filter" forall f g xs. filter f (filter g xs) = filter (f.g) xs #-} It's a programmable programming language.
- ced 16y agoNice. What's the limit on what you can do with these RULES? Could you extend the language? Write a DSL? Implement a mini-prolog à la On Lisp?
- mkramlich 16y agogo Java! catching up a little more with Python. Meanwhile, back to my Python hacking session...
- jrockway 16y agoIf Java were Haskell, the syntax would be "filter isPartTime". It's silly to have to type stuff that's easily understood by both the programmer and the compiler.
- gojomo 16y agoPerhaps Java8 will get multiline string literals -- an over-9-year-old request: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4472509 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!
- csmeder 16y agoWow, 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.
- Locke1689 16y agoI find it ironic that a Java programmer is deriding other programmers (C# and VB) for not being "real" programmers.
- scotth 16y agoThat's narrow minded. There are some great Java programmers. It's just that they don't have the same priorities that you do.
- Locke1689 16y agoI 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.
- ebtalley 16y agoIm on a horse. Freaking awesome.
- tibbon 16y agoNow I want to see the Old Spice guy make a response video to this... or maybe just read this aloud.
- fourneau 16y agoI'm really glad that JDK 7 finally has diamonds. (In more ways than one: http://weblogs.java.net/blog/forax/archive/2009/08/27/diamond-gate http://weblogs.java.net/blog/forax/archive/2009/08/27/diamon...)
- Jach 16y agoHe 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.
- admorphit 16y agoAwesome - love it.
- kinnth 16y agoSo funny and i'm not even a geek!
- EliRivers 16y agoWhich of those two styles is being presented as superior?