Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It seems like these all are exclusive to dynamically/weakly typed languages. Anyone have examples of wats for languages with strong static typing?


Java Puzzlers spring to mind. There's a book [0], and some fun talks available on youtube [1][2][3].

[0]: http://www.javapuzzlers.com/

[1]: https://www.youtube.com/watch?v=wbp-3BJWsU8

[2]: https://www.youtube.com/watch?v=yGFok5AJAyc

[3]: https://www.youtube.com/watch?v=Wnzyp1aitb8


Java:

* Reassigning interned integers via reflection

* private fields work on a class level, not an instance level, i.e. Instances of a class can read private fields of other instances of the same class.

* Arguably package-private fields as the docs like to avoid mentioning they exist.

* ==, particularly in regards to boxed types.

* List<String> x = new ArrayList<String>() {{ add("hello"); add("world"); }};

* The behaviour of .equals with the object you create above

* Type Erasure


to add another:

    System.out.println(0.0 == -0.0); // true
    System.out.println(java.util.Arrays.equals(new double[] {0.0}, new double[] {-0.0})); // false
(It's documented in the contract for Arrays.equals, but still kind of ridiculous.)


Byte is signed. `Byte b = 127; b += 1; assert b != 128;`. That's not cool man.


OCaml's parsing rules are pretty opaque sometimes. For example, if you have an "if" statement that's just performing effects (not returning a value), you may run into behavior like this:

    # let x = ref 0;;
    val x : int ref = {contents = 0}
    # let y = ref 0;;
    val y : int ref = {contents = 0}
    # if false then
        x := 1;
        y := 1;
      ;;
    - : unit = ()
    # (!x, !y);;
    - : int * int = (0, 1)
    # y := 0;;
    - : unit = ()
    # if false then
        let z = 1 in
        x := z;
        y := z;
      ;;
    - : unit = ()
    # (!x, !y);;
    - : int * int = (0, 0)


Some guy made https://www.reddit.com/r/lolhaskell and put 3 posts there.


Sure. Javas signed byte type comes to mind.

Oh, and `null`, in any language ;-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: