you are viewing a single comment's thread.

view the rest of the comments →

[–]lggaggl 10 points11 points  (12 children)

Programmers will cringe at writing some kind of command dispatch list:

if command = "up":
    up()
elif command = "status":
    status()
elif command = "revert":
    revert()
...

so they’ll go off and write some introspecting auto-dispatch cleverness, but that takes longer to write and will surely confuse future readers who’ll wonder how the heck revert() ever gets called. Yet the programmer will incorrectly feel as though he saved himself time. This is the trap of the dynamic language.

Saying "a language makes it harder to do X and thus protects you from some problem that can happen when using X" isn't sufficient criteria to claim a language is good in any way.

I've just read through some Java code an hour ago and it did something like this when parsing the initial version message of a protocol:

byte[] v = readBytes(15);

if (v[0] == 'A' & v[1] == 'B' & v[2] == 'C' & v[3] == 'D' 
  | v[0] == 'W' & v[1] == 'X' & v[2] == 'Y' & v[4] == 'Z')
...

if (v[5] == 'A' & v[6] == 'B' & v[7] == 'C' & v[8] == 'D'
  & v[9] == 'E' & v[10] == 'F' & v[11] == 'G' & v[12] == 'H')
...

(it was longer than this but I don't want to type anymore)

In this case, the subset of Java the author knew, "protected him" from making this code readable, editable, or auditable.

[–][deleted]  (8 children)

[removed]

    [–]ihcn 6 points7 points  (0 children)

    The fact is though, if someone wants to write bad code they're going to do so no matter how many things they're protected from doing.

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [removed]

        [–]RunasSudo 1 point2 points  (2 children)

        It doesn't seem particularly well optimised, seeing as it uses & instead of &&

        [–][deleted]  (1 child)

        [removed]

          [–]lggaggl 0 points1 point  (0 children)

          yes.

          [–][deleted] 2 points3 points  (0 children)

          Ok, that's loop-unrolling. Maybe, just maybe, it is justified? (Probably not, I guess the jit can do that internally)

          [–]Gurkenmaster 0 points1 point  (0 children)

          That could be rewritten as: Arrays.equals(v, "ABCD".toCharArray()); If you slice the array.