Better HN
topnewbestaskshowjobs
Log inSign up

kilink

104 karma · joined Aug 13, 2011 (15y ago) · 60 submissions

Submissions

comment 2mo ago · link · parent

That's less of a thing nowadays if you use the newer APIs that accept Charset instances instead of the charset name as a String.

2.

LendingClub Founder, Ousted in 2016, Settles Fraud Charges(nytimes.com ↗)

1 points · by kilink · 8y ago · discuss

3.

Bitcoin Cash Trading Now Available on GDAX(blog.gdax.com ↗)

5 points · by kilink · 8y ago · discuss

4.

These Guys Want to Lend You Money Against Your Bitcoin(bloomberg.com ↗)

3 points · by kilink · 8y ago · discuss

comment 9y ago · link · parent

They mentioned msgpack was calling gc.enable(), but it looks like that issue was fixed quite a while ago in version 0.2.2:

https://github.com/msgpack/msgpack-python/blob/2481c64cf162d...

comment 10y ago · link · parent

Maybe they mean data class inheritance, instead of subclassing? That's the only thing I know of that is planned for Kotlin 1.1 [1], and it's primarily useful for sealed classes (I've wanted this).

[1] https://github.com/Kotlin/KEEP/blob/master/proposals/data-cl...

comment 10y ago · link · parent

I think the advice is more relevant in the context of the specific language; it's not universal.

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.

comment 10y ago · link · parent

...Or can you?

  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!

comment 10y ago · link · parent

I'm not sure if you are asking about Python, or Ruby.

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

comment 10y ago · link · parent

This is a Python specific restriction. Ruby for example allows mutable keys in dictionaries.

11.

Hulu is eliminating its free, ad-supported streaming service(theverge.com ↗)

30 points · by kilink · 10y ago · 53 comments

12.

Tesla’s Big Loss Reflects Its Costly Ambitions(nytimes.com ↗)

6 points · by kilink · 10y ago · discuss

comment 10y ago · link · parent

What about null?

comment 10y ago · link · parent

I'm not sure what you mean by error values being dropped on the floor by default. In Go or languages with ADTs you would have to consciously ignore an exception. Languages where pattern matching is prevalent force you to deal with the exceptional case to unpack anything useful from an Either for instance.

And if the study is to be believed, checked exception are almost always dropped on the floor, just with more boilerplate and ceremony.

comment 10y ago · link · parent

I was addressing your specific assertion with regard to encoding error conditions as reserved values in your return type's codomain, which I agree is ugly.

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.

comment 10y ago · link · parent

> The problem usually is: What is the error code if your return type is int? Sure, you can define all negative ints as errors, or you provide a reference which is set when an error is encountered and so on, but that ends up being just another type of "very ugly".

Many languages support multiple return values, algebraic data types, or box types, allowing you to return an error value out of band.

comment 10y ago · link · parent

Things I dislike about Ion, having used it while at Amazon:

- 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...

comment 10y ago · link · parent

That also wouldn't even compile. I also write in multiple languages, and for languages for which this is an issue I use a linter. This isn't even an issue in C if you compile everything with the appropriate flags (-Wall or -Wparentheses).

comment 10y ago · link · parent

Sorry, it's just not practical to keep lines under 80 characters in some languages.

comment 10y ago · link · parent

For me it's not that it's confusing, it's annoying to read because it indicates that the programmer didn't actually take the time to learn the language, and is instead writing it as C/PHP something else where expressions in if statements don't need to be explicitly boolean (the examples in the article are Java). If they wrote that, what else do they not understand about the language?

comment 10y ago · link · parent

Java if statements only allow boolean expressions, so the thing that the Yoda condition is supposed to protect against isn't even possible. I think this is precisely what the author is talking about, as this style is a totally unnecessary holdover from C.

22.

Why Kotlin is my next programming language(medium.com ↗)

4 points · by kilink · 10y ago · discuss

23.

A Plan in Case Robots Take the Jobs: Give Everyone a Paycheck(nytimes.com ↗)

2 points · by kilink · 10y ago · discuss

24.

Kotlin and Ceylon(medium.com ↗)

3 points · by kilink · 10y ago · discuss

25.

Zenefits' new CEO just banned employees from drinking alcohol at the office(businessinsider.com ↗)

7 points · by kilink · 10y ago · 1 comment

comment 10y ago · link · parent

That may true for Go, a language which still does not have a great dependency management story. I'm not sure this proverb is universal though.

comment 10y ago · link · parent

The parent was talking about namedtuple.

    >>> collections.namedtuple("test", "$")
    Traceback (most recent call last):
    ...
    ValueError: Type names and field names can only contain alphanumeric characters and underscores: '$'

comment 10y ago · link · parent

If this were a big deal, it could be optimized using something like a key-sharing dict implementation [1]. You can keep the dict interface to accommodate column names that aren't valid identifiers, and avoid most of the memory overhead.

[1] https://www.python.org/dev/peps/pep-0412/

12