Security of Java takes a dangerous turn for the worse, experts say (ars technica)
Security of Java takes a dangerous turn for the worse, experts say (ars technica)
Posted Sep 12, 2013 11:53 UTC (Thu) by HelloWorld (guest, #56129)In reply to: Security of Java takes a dangerous turn for the worse, experts say (ars technica) by the.wrong.christian
Parent article: Security of Java takes a dangerous turn for the worse, experts say (ars technica)
Posted Sep 16, 2013 16:51 UTC (Mon)
by ThinkRob (guest, #64513)
[Link] (3 responses)
Posted Sep 16, 2013 22:51 UTC (Mon)
by HelloWorld (guest, #56129)
[Link] (2 responses)
Posted Sep 17, 2013 8:40 UTC (Tue)
by jezuch (subscriber, #52988)
[Link]
Giving an example that is easier does not mean that the original example is not easy.
Now, the *real* problem with the original example is that it's a simple adapter. If the iterator is supposed to do some filtering, then it becomes significantly less easy. That's when I long for yield in Java :) But the upcoming lambda support in Java 8 is supposed to make this much, much easier and effectively eliminate the need for implementing iterators thus making yield insignificant.
Posted Sep 19, 2013 15:27 UTC (Thu)
by ThinkRob (guest, #64513)
[Link]
Yes, C# requires fewer lines. I wasn't playing code golf though; I was responding to the claim that it was hard to write an iterator. It's not. It may not be as few lines as you'd like, but it's not hard -- or at least it shouldn't be for anyone who knows the language well enough to be writing more than Hello World in it.
It's worth noting that C# isn't burdened by the same backwards-compatibility requirements that Java is. There's a *lot* of parts of Java that could be better if they were allowed to introduce breaking changes (the Collections API comes to mind), but that's the curse of being first I suppose.
Security of Java takes a dangerous turn for the worse, experts say (ars technica)
It's not using iterators that's hard, it's writing one.
It's not hard. It's three methods, and one of those (#remove()) is optional.
Here's an implementation of an array iterator. Works for any array:
public class ArrayIterator<T>
implements Iterator<T>
{
private int index = 0;
private final T[] array;
public ArrayIterator(T[] array)
{
this.array = array;
}
@Override
public boolean
hasNext()
{
return this.index < this.array.length;
}
@Override
public T
next()
{
if (this.index < this.array.length)
{
return this.array[this.index++];
}
throw new NoSuchElementException();
}
@Override
public void
remove()
{
throw new UnsupportedOperationException();
}
}
Not too difficult. Wordy, perhaps, but certainly not hard to write.
I'm sorry, you Java fanboys are just pathetic. Here's the C# source code to do the same thing:
Security of Java takes a dangerous turn for the worse, experts say (ars technica)
public static IEnumerator<T> foo<T>(T[] bar) {
foreach(var x in bar)
yield return bar;
}
And of course it's easy to write this if all you're doing is iterating over an array. But things become much harder if you actually write an iterator that does something interesting. The C# (or Python) compiler actually helps you to get the control flow right, while Java is just in the way.
Security of Java takes a dangerous turn for the worse, experts say (ars technica)
Security of Java takes a dangerous turn for the worse, experts say (ars technica)
