kilink
Bitcoin Cash Trading Now Available on GDAX
These Guys Want to Lend You Money Against Your Bitcoin
https://github.com/msgpack/msgpack-python/blob/2481c64cf162d...
[1] https://github.com/Kotlin/KEEP/blob/master/proposals/data-cl...
In python you can go from attribute access to using a property (getter/setter) without breaking anything.
The same is not true in a language like Java where obj.foo is always a direct field access distinct from calling a method like obj.getFoo(), so going from public fields to getters is not backwards compatible and can be painful.
import ctypes
def tuple_setitem(t, index, item):
obj = ctypes.py_object(t)
item = ctypes.py_object(item)
ref_count = ctypes.c_long.from_address(id(t))
original_count = ref_count.value
if original_count != 1:
ref_count.value = 1
ctypes.pythonapi.Py_IncRef(item)
ctypes.pythonapi.PyTuple_SetItem(obj, ctypes.c_ssize_t(index), item)
ref_count.value = original_count
>>> x = (1, 2, 3,)
>>> tuple_setitem(x, 1, "foo")
>>> x
(1, "foo", 3)
Disclaimer: for entertainment purposes only, do not try this at home!Anyway, both languages use value-based hashing for dictionaries. I am not a Rubyist, but I guess you are just expected to not mutate the keys? Ruby's dictionary implementation also has a rehash method to deal with this case [1], if for some reason you are purposely mutating the keys I suppose...
[1] http://docs.ruby-lang.org/en/2.0.0/Hash.html#method-i-rehash
Hulu is eliminating its free, ad-supported streaming service
Tesla’s Big Loss Reflects Its Costly Ambitions
And if the study is to be believed, checked exception are almost always dropped on the floor, just with more boilerplate and ceremony.
One benefit of not throwing an exception is that you can maintain referential transparency, which exceptions generally break. You can't substitute a function call with its value because throwing an exception will have different effects depending on the context, which consequently hinders the composability of such functions.
Exceptions are also generally not type-safe, e.g. the return type of a function tells you nothing about what exceptions it may throw. If you go the checked exception route like Java, you do get some degree of type safety, but you do so at the expense of higher-order functions, which can't reasonably be expected to know about the specific exception types its arguments may throw.
On the other hand, ADTs are composable. They work for functions that aren't defined for some inputs (maybe an input type that can't be constrained by the type system). They avoid bugs because they force the caller to deal with the exceptional case (unlike returning null, a sentinel value, or throwing a RuntimeException), but without the boilerplate of exceptions, particularly in languages with pattern matching. The caller gets to decide when, if, and how to handle the exceptional case.
Many languages support multiple return values, algebraic data types, or box types, allowing you to return an error value out of band.
- IonValues are mutable by default. I saw bugs where cached IonValues were accidentally changed, which is easy to do: IonSequence.extract clears the sequence [1], adding an IonValue to a container mutates the value (!) [2], etc.
- IonValues are not thread-safe [3]. You can call makeReadOnly() to make them immutable, but then you'll be calling clone since doing anything useful (like adding it to a list) will need to mutate the value. While it says IonValues are not even thread-safe for reading, I believe this is not strictly true. There was an internal implementation that would lazily materialize values on read, but it doesn't look like it's included in the open source version.
- IonStruct can have multiple fields with the same name, which means it can't implement Map. I've never seen anyone use this (mis)feature in practice, and I don't know where it would be useful.
- Since IonStruct can't implement Map, you don't get the Java 8 default methods like forEach, getOrDefault, etc.
- IonStruct doesn't implement keySet, values, spliterator, or stream, and thus doesn't play well with the Java 8 Stream API.
- Calling get(fieldName) on an IonStruct returns null if the field isn't present. But the value might also be there and be null, so you end up having to do a null check AND call isNullValue(). I'm not convinced it's a worthwhile distinction, and would have preferred a single way of doing it. You can already call containsKey to check for the presence of a field.
- In practice most code that dealt with Ion was nearly as tedious and verbose as pulling values out of an old-school JSONObject. Every project seemed to have a slightly different IonUtils class for doing mundane things like pulling values out of structs, doing all the null checks, casting, etc. There was some kind of adapter for Jackson that would allow you to deserialize to a POJO, but it didn't seem like it was widely used.
[1] https://github.com/amznlabs/ion-java/blob/master/src/softwar...
[2] https://github.com/amznlabs/ion-java/blob/master/src/softwar...
[3] https://github.com/amznlabs/ion-java/blob/master/src/softwar...
Why Kotlin is my next programming language
A Plan in Case Robots Take the Jobs: Give Everyone a Paycheck
Kotlin and Ceylon
Zenefits' new CEO just banned employees from drinking alcohol at the office
>>> collections.namedtuple("test", "$")
Traceback (most recent call last):
...
ValueError: Type names and field names can only contain alphanumeric characters and underscores: '$'Super Bowl 50 Further Divides San Francisco
[1] https://blogs.oracle.com/jonthecollector/entry/the_second_mo...