42
Gophyr
8y

When you see a Java devotee using Python and they're doing something like this:

array = [1, 2, 3, 4]
for n in range(0,len(array)):
print(array[n])

At least I get to tell them "hey it doesn't have to be so hard just do it like this:"

array = [1, 2, 3, 4]
for n in array:
print(n)

Comments
  • 6
    “If it's stupid but it works, it isn't stupid“
  • 1
    @Skayo Very true :D
  • 5
    Doesn't Java have a foreach?
  • 0
    @SirDaryl Don't know, haven't really used it. I just ran into someone doing this and his excuse was "I program in Java."
  • 4
    It does,
    for( int i in array)
    {
    System.out.println(I);
    }

    Not so different

    Also welcome to devrant!
  • 0
    C/C++ devotee maybe
    Java and most other high level language has a forEach
  • 2
    @masterdoctor ah crap too much c# lol
  • 2
    @masterdoctor lol same I've been using unity when I go home and a tiny bit of java at work
  • 0
    @kaqqao Simply putting the word "Java" in it does not a good comment make.
  • 1
    There's a reason why Java devs do that. A list in Python is also iterable. In Java arrays are primitive and do not implement the Iterable interface.

    If that was a List<> of any kind a for each clause would work.

    In Java 8 the more "functional" way to iterate over a list is something like:

    List<String> cars = new ArrayList<>();
    // Add some strings
    Cars.forEach(car -> foobar(car));
  • 1
    @jiraTicket Even C++11 and later has a foreach.
    for(int i : array)
    {
    }
  • 1
    @isRantOverflow oh, sweet. Haven't used C++ for a long time, good to know it's evolving.
Add Comment