143

Today on "How to do easy things the wrong way"...

Comments
  • 6
    Where did you find that?
  • 3
    *cries*
  • 12
    This would be a great lesson for beginners since it shows loops, try-catch blocks, and arrays all in one nifty function
  • 14
    @gorsamp I really hope there is some hidden sarcasm in that comment.
  • 7
    The tag still exist cause it has a name
  • 4
    Maybe the problem statement was to calculate the length without using the length property. Just saying maybe there’s a reason.
  • 5
    I read the tags...
  • 1
    @Gnu-Not-Unix Schrödinger’s tags
  • 2
    If everyone who knew about the tags dies the GC will get them.
  • 0
    What we are seeing here folks is what we are taught in an AP Computer Science A class.
  • 0
    AmountInArrayX = count(array)

    Like really....
  • 1
    @abhishekb Still though, putting the try/catch inside the loop in stead of around it seems pretty inefficient, and if also looks pretty clumsy. Also, he could just have used an enhanced for loop with a counter like so:

    ‘for (Object o : array) i++;’

    doing it that way prevents the exception from even being thrown.
  • 1
    @abhishekb
    Oh and it’s probably cheating but just doing

    ‘return Arrays.asList(array).size()’

    Would also get the job done without calling .length 🤓🙃
  • 1
    @ArcaneEye I thought it was java, but I guess they're pretty similar.
  • 2
    @ArcaneEye It has a .length public attribute. And I agree, it's ridiculous, but @abhishekb pointed out that it might be because of a challenge to calculate the length without using .length, so I thought it would be fun to take a look and come up with some other, i.m.o. more elegant ways :) (which still should never be used in any serious projects of course 😅 )
  • 0
    A C programmer probably wrote this
  • 1
    @stevemk14ebr yes, because C is known for its exception usage and managed arrays, right?

    @ArcaneEye it's Java. The highlighting theme is the IDEA Dark theme and .NET doesn't have ArrayIndexOutOfBoundsException and you'd probably use object instead of Object
  • 0
    I think the guy might know something we don't....
  • 2
    Nah. Tags don't exsist.
  • 0
Add Comment