Re:Python wats
by nv-vn on Saturday October 10, 2015 @07:47PM
(#10367447)
It seems like these all are exclusive to dynamically/weakly typed languages. Anyone have examples of wats for languages with strong static typing?
[ Parent
| on HN ]
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
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.