Literal notation for Dictionary in C#?

I currently have a WebSocket between JavaScript and a server programmed in C#. In JavaScript, I can pass data easily using an associative array: var data = {‘test’: ‘val’, ‘test2’: ‘val2′}; To represent this data object on the server side, I use a Dictionary<string, string>, but this is more ‘typing-expensive’ than in JavaScript: Dictionary<string, string> … Read more

Why can’t Python’s raw string literals end with a single backslash?

Technically, any odd number of backslashes, as described in the documentation. >>> r’\’ File “<stdin>”, line 1 r’\’ ^ SyntaxError: EOL while scanning string literal >>> r’\\’ ‘\\\\’ >>> r’\\\’ File “<stdin>”, line 1 r’\\\’ ^ SyntaxError: EOL while scanning string literal It seems like the parser could just treat backslashes in raw strings as … Read more

(-2147483648> 0) returns true in C++?

-2147483648 is the smallest integer for integer type with 32 bits, but it seems that it will overflow in the if(…) sentence: if (-2147483648 > 0) std::cout << “true”; else std::cout << “false”; This will print true in my testing. However, if we cast -2147483648 to integer, the result will be different: if (int(-2147483648) > … Read more

Why does instanceof return false for some literals?

“foo” instanceof String //=> false “foo” instanceof Object //=> false true instanceof Boolean //=> false true instanceof Object //=> false false instanceof Boolean //=> false false instanceof Object //=> false 12.21 instanceof Number //=> false /foo/ instanceof RegExp //=> true // the tests against Object really don’t make sense Array literals and Object literals match… … Read more