Originally posted by Asher
View Post
Announcement
Collapse
No announcement yet.
Programming question
Collapse
X
-
Originally posted by Kuciwalker View PostBecause it does, in fact, always apply. Do you want to be closed over an int? Drop it in a final collection - done!
This whole thread is surreal. My estimation of your programming abilities has fallen."The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
-
You guys are ****ing dorks.12-17-10 Mohamed Bouazizi NEVER FORGET
Stadtluft Macht Frei
Killing it is the new killing it
Ultima Ratio Regum
Comment
-
Look...closures do not do anything that you cannot do without them. What they do provide is a clean, tidy, efficient, sensible way to do some kinds of operations.
The fact that you can approximate such behaviours in some languages with verbose, messy implementations is obviously not the same thing. Another advantage is decreased overhead and memory consumption -- something the Java approximations do not provide since they use heavy-weight classes.
I'll even revert back to C# 2.0 here and not use lambdas. Here's anonymous delegates in C# vs Java's hack:
C#:
Code:int totalWeight = 0; passengerWeight.EachPerson(delegate(Person person) { totalWeight+= person.Weight; } Console.WriteLine("Passengers weight {0}", totalWeight);
Code:final int[] totalWeight = { 0 }; passengerWeight.eachPerson(new PassengerWeightAnonymousFunc() { public void handle(Person person) { totalWeight[0] += person.getWeight(); } }); System.out.println("Passengers weight " + totalWeight[0]);
"The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
-
Here's how I can compute factorial in C# 3.0 with lambdas and closures.
I know Java doesn't have lambdas either, but how would you code this in Java, Kuci?
Code:delegate int FactorialFun(int i); static FactorialFun Factorial = (n) => n <= 1 ? 1 : n * Factorial(n - 1);
"The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
-
Look...closures do not do anything that you cannot do without them. What they do provide is a clean, tidy, efficient, sensible way to do some kinds of operations.
I'm not taking advantage of Turing completeness here. You literally cannot implement even pseudo-closures in C without writing a compiler or interpreter. Java has all of the elements you need to write a closure, and it's just a matter of awkward syntax if you want the full generality. Adding usable, fully generalizable syntax for closures is a very worthy goal for Java, but many (most?) of the closure/lambda use-cases actually already exist as interfaces and are frequently used as closures and lambdas.
Comment
-
Another cool feature of lambdas? They're what enabled LINQ to work.
In C#, you can do a SQL-like query on any collection. Automagically.
It's very badass.
Eg:
Code:public void Apolyton() { List
sextoysKuciHasUsed= GetSexToys(); List peopleKuciSleptWith = GetPeopleWithLowStandards(); var toyFirstChars = from s in sextoysKuciHasUsed= select s.ToyName[0]; var peopleFirstChars = from p in peopleKuciSleptWith select p.PornName[0]; var uniqueFirstChars = toyFirstChars.Union(peopleFirstChars); Console.WriteLine("Unique first letters from the names of Kuci's sex toys and the names of people he's slept with:"); foreach (var letter in uniqueFirstChars) { Console.WriteLine(letter); } }
Bedtime now.Enough coding...
"The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
-
Originally posted by Asher View PostHere's how I can compute factorial in C# 3.0 with lambdas and closures.
I know Java doesn't have lambdas either, but how would you code this in Java, Kuci?
Code:delegate int FactorialFun(int i); static FactorialFun Factorial = (n) => n <= 1 ? 1 : n * Factorial(n - 1);
Code:interface FactorialFun { public int apply(int i); } FactorialFun foo = new FactorialFun() { public int apply(int i) { return (i <= 1) ? 1 : i*apply(i-1); } }
Comment
-
Originally posted by Kuciwalker View PostLook...closures do not do anything that you cannot do without them. What they do provide is a clean, tidy, efficient, sensible way to do some kinds of operations.
I'm not taking advantage of Turing completeness here. You literally cannot implement even pseudo-closures in C without writing a compiler or interpreter. Java has all of the elements you need to write a closure, and it's just a matter of awkward syntax if you want the full generality. Adding usable, fully generalizable syntax for closures is a very worthy goal for Java, but many (most?) of the closure/lambda use-cases actually already exist as interfaces and are frequently used as closures and lambdas.
And in the process, you're using something like 10x the memory to do it."The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
-
Originally posted by Kuciwalker View PostErm, the only "free variable" in that "closure" is the function name, which isn't actually any more powerful than recursion. Observe...
Code:interface FactorialFun { public int apply(int i); } FactorialFun foo = new FactorialFun() { public int apply(int i) { return (i <= 1) ? 1 : i*apply(i-1); } }
Implement the same functionality using "closures" in Java.
I chose a simple example because it's simple. The point is implementing closures, not solving a specific problem with the solution you find best."The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
-
Asher, welcome to me at the beginning of this discussion, when I claimed that fully general closures are syntactically terrible but not impossible or even especially difficult. Also welcome to the earlier discussion where I said C# is a better language overall than Java. What exactly are you trying to prove?
Comment
-
Well, C# is a better language and I like to demonstrate why.
Your claim that Java supports closures still remains incorrect, by virtue of having to jump through so many hoops to approximate it that it negates the whole purpose of closures.
You've then spent a ridiculous number of posts claiming the authors of Java are wrong when they say Java does not support closures. You seem to be under the impression that supporting true closures in Java is just a matter of "syntax", when in reality it requires a big change in the whole JVM. Java does not support closures, it supports features that let you emulate closure behaviour with ugly syntax and even worse performance.
To claim it supports closures is:
(a) incorrect
(b) ignorant
(c) disingenuous
That is all."The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
Ben Kenobi: "That means I'm doing something right. "
Comment
Comment