HNHacker News
TopNewBestAskShowJobs

mrgriffin

189 karma · joined May 30, 2016

submissionscomments
mrgriffin··on Type inference has usability problems
Not OP but I think hurt is correct. My understanding is that if you're passing return values directly into functions then there's nowhere to annotate the types of those values, but many (most?) people are perfectly okay with that even though you could argue that the types are being inferred (in that they're being left implicit, just as they are when you say:

  var gxy = g(x, y)
  var abc = a(b(c))
  f(gxy, abc)
mrgriffin··on Type inference has usability problems
Like many things in life, it depends.

I quite like type inference when it's clear from context what the type will be, e.g.:

  var xs = new List<Int>();
  for (var x in xs) { ... }
I'm pretty happy for it when the type "doesn't matter" because you don't do anything with the value except pass it elsewhere.

  // Presumably refactored from processSomething(x, y, z, getSomething()) because the line got too long.
  var something = getSomething();
  processSomething(x, y, z, something);
And sometimes the type can be sufficiently unwieldy to name, most famously in C++ taking advantage of templates, but also can show up in other languages such as Haskell that encourage this behavior.

Finally there's this comment:

> A weaker argument I have heard is that you have less code to type with type inference!

I'd say that I agree with it as stated, but I'd hope the people making that argument are actually trying to say "it's less code to read/be distracted by". IMO omitting the "less important" type information draws the reader's attention to the ones you did write, which are presumably the more interesting parts of the code.

Having said all that, I think my brain is a bit quirky because even in languages like Python I automatically/internally infer all the types based on the names of variables and roughly how/where they're used as I read through. Maybe it's an experience thing (or maybe I don't work with bad/differently-thinking developers), but I find that my first or second guess is right 99% of the time.

mrgriffin··on Go makes it easier to write correct, clear and efficient code
FWIW I read

> Why bother protesting you imperfect hypocrite?

As a thing that people are saying to the hypothetical Greenpeace protester, not a thing that GP is directing at you.

mrgriffin··on All extensions disabled due to expiration of intermediate signing cert
Thanks for this! My NixOs build of Firefox was apparently built without support for studies, but your link worked fine.
mrgriffin··on Microsoft proves the critics right: We’re heading toward a Chrome-only Web
I downloaded an extension to spoof my user agent this morning, haven't tried doing much yet, but messages certainly seem to work and that's 99% of what I do anyway.

I don't know why I couldn't have be treated to a "this might not work 100% warning" instead of being completely locked out.

mrgriffin··on Practical Go: Real-world advice for writing maintainable Go programs
For GCD? I would find those names very misleading since semantically the order of the arguments to GCD is irrelevant (even if in the implementation you typically mod by b there's no reason you couldn't mod by a).
mrgriffin··on What's next for SemVer
> 3. I need clarification. Are you saying that a major version >= 1 of a dependency you rely upon in production returns a sorted list, but then a new bugfix version now outputs an unsorted list?

Not OP, but I believe they are saying that the API happens to return a sorted list (either for their particular inputs, or in general), but this was never a guarantee of the API (and was presumably not covered by tests), and so the package maintainers changed the implementation to no longer return a sorted list (maybe they found a faster algorithm).

I have to say that I think this is a good case for having tests that are tied to particular versions, like in this comment: https://news.ycombinator.com/item?id=19138853

Or perhaps in this specific case the user of the library will add the test (to their own codebase) that checks the output is always sorted, and it will fail to upgrade to a version where this isn't true. In general I'd be pretty happy to see people write tests for the subset of behavior they require from a library, although I appreciate that's potentially a whole lot of work, particularly in ecosystems without property-based testing.

mrgriffin··on What's next for SemVer
I'd think the problem with bumping the version number if you're remaining compatible is that it signals to the end-user that you're not compatible. i.e. when I start using 2.x the constraints I'll put in my list of libraries is < 3.0 (because otherwise my project could randomly break upon 3.0's release, depending on whether it's compatible or not).
mrgriffin··on About V, the language Volt is written in
If you allow shadowing then surely the local definition of the name will take precedence over the new name introduced in the stdlib (or wherever), and thus the program will keep behaving how it did before the new builtin was introduced.

I think I must be misreading you, because it sounds like you're arguing for the idea that adding new names to an API should be considered a breaking change? I'll accept that maybe reflection will catch those changes, but with that exception why would any code even notice?

mrgriffin··on About V, the language Volt is written in
I agree that modifying Chicken's output like you would handwritten C code would be an exercise in madness. But it's possible to design a language to have a nice transpilation story, for example PureScript deliberately puts restrictions on the names of types and operators so that they have a sane name in JS. Of course there's still a likely style mismatch, but what can you do?

I suspect you already know this, but for the benefit of others.

mrgriffin··on Monorepos: Please don’t
Oh God! I had forgotten how much frustration was in my old Python team until I checked the docs and discovered that you can make pip "install" your local copy of one repo as the dependency for another. The poor developer who prompted me to check was testing by doing CI builds and pulling down the new eggs.

Of course this isn't really a point against polyrepos, since it had a solution, but it's definitely something that I could imagine catching out lots of juniors.

mrgriffin··on Monorepos: Please don’t
My problem with polyrepos is that often organizations end up splitting things too finely, and now I'm unable to make a single commit to introduce a feature because my changes have to live across several repositories. Which makes code review more annoying because you have to tab back and forth to see all the context. It's doubly frustrating when I'm (or my team is) the only people working on those repositories, because now it doesn't feel like it gained any advantages. I know the author addresses this, but I can't imagine projects are typically at the scale they're describing. Certainly it's not my experience.

Also I definitely miss the ability to make changes to fundamental (internal) libraries used by every project. It's too much hassle to track down all the uses of a particular function, so I end up putting that change elsewhere, which means someone else will do it a little different in their corner of the world, which utterly confuses the first person who's unlucky enough to work in both code bases (at the same time, or after moving teams).

mrgriffin··on Please do not attempt to simplify this code
One of my favorite features of Haskell is that I can use where to write the auxiliary function definitions after the code that use them, but keep them scoped inside of a single function.

A relatively bad example here: https://wiki.haskell.org/Worker_wrapper#Hiding_the_worker

mrgriffin··on Gluten Free Antarctica
As a vegan with coeliac disease I am very grateful that the fad somehow decided to pair these things together.

I got very sick some years ago when I moved from a vegetarian diet to a vegan one and discovered that most specifically-marked-for-vegan protein dishes contain gluten.

mrgriffin··on Skip – A programming language to skip the things you have already computed
I might be misremembering, but isn't overloading on immutability what C++ does with the const keyword on member functions? e.g.

    struct Foo {
      A bar(); // If the instance is non-const.
      A bar() const; // If the instance is const.
    };
Of course this is C++ so it's up to you to make sure that all the types contained in your object are also immutable when they're const-ed (e.g. avoid pointers). And the mutable keyword is a backdoor.

Or perhaps you wanted to be able to change the representation (e.g. member variables) of your type based on whether it's mutable or not? Although in that case I'd probably go with an interface.

mrgriffin··on Man sues over Google’s “Location History” fiasco, case could affect millions
Skimresources is probably an affiliate link thing (although they also try to sell your data to power targeted advertising), see: https://skimlinks.com/

Source: I used to work there.

mrgriffin··on Representing the Impractical and Impossible with JDK 10 “var”
I disagree that this is a good style in general.

If I commit to returning an ArrayList then it's not backwards compatible if I want to change to a different concrete List. My experience has been that if you return a concrete class then people will rely on those details even when they don't need to. And if you're writing a library that others depend on then you don't even know how they're using your returned value.

Of course if people are doing unsafe downcasts because they need the guarantees of a particular implementation then you should just return the ArrayList directly. And fortunately this change is backwards compatible, so there's no need to worry!

mrgriffin··on Some obscure C features
That's true, and in the event that you're actually using __COUNTER__ for something you could build something similar out of #include with a header that increments an internal number.

  // COUNTER.h
  #if !defined(COUNTER)
  #define COUNTER 0
  #elif COUNTER == 0
  #undef COUNTER
  #define COUNTER 1
  #elif COUNTER == 1
  #undef COUNTER
  #define COUNTER 2
  ...
  #end if
And then change each invocation of ELEMENT to have a leading #include "COUNTER".

  #include "COUNTER.h"
  ELEMENT(x)

  #include "COUNTER.h"
  ELEMENT(y)
Note that if you take this approach then (as far as I know) you're actually writing standard C!
mrgriffin··on Some obscure C features
Yeah, it's a weird one! I discovered the idea while building my own toy unit test library, but I never got around to finishing it.

The biggest downside is that (as far as I know) it's impossible to get this approach to coordinate across translation units, so you're forced to define a main in each test file (via the library's header file?). But I doubt that matters too much in practice.

mrgriffin··on Some obscure C features
The author tried using __COUNTER__ and a static array of function pointers, and narrowly missed a workable idea—a static linked list! Forward declarations pun definitions, and can be used roughly as follows:

  struct Element {
    int value;
    struct Element *next;
  }

  #define ELEMENT(value) _ELEMENT(value, __COUNTER__)
  #define _ELEMENT(value, n) \
    struct Element CAT(e, SUCC(n)); \
    struct Element CAT(e, n) = { (value), &CAT(e, SUCC(n)) }
You can then walk from e0 through the linked list, but because of how the initialization works, you're done when the current element has `next == 0`.

  int main(void)
  {
    struct Element *e = &e0;
    while (e->next) {
      printf("%d\n", e->value);
      e = e->next;
    }
  }
Here's a repl.it: https://repl.it/repls/DetailedYoungAsianconstablebutterfly
mrgriffin··on Allocation is cheap in .NET until it is not
> Cpython has non-moving GC so this is not an issue.

I believe the GP was referring to PyPy.

From https://morepypy.blogspot.co.uk/2009/10/gc-improvements.html

> The hash field is not necessarily there; it is only present in classes whose hash is ever taken in the RPython program (which includes being keys in a dictionary). It is an "identity hash": it works like object.__hash__() in Python, but it cannot just be the address of the object in case of a GC that moves objects around.

mrgriffin··on Why we switched from Python to Go
How about Requests?

https://github.com/requests/requests/search?utf8=%E2%9C%93&q...

mrgriffin··on How to Do Code Reviews Like a Human
This one hundred times.

I once had a reviewer who took this even further, asking for changes in code that were unrelated to my changeset but appeared in the diff. e.g. I add a parameter Y and get a comment like "parameter X should support feature Z".

Please just let me get my feature out!

mrgriffin··on How to Do Code Reviews Like a Human
We're pretty conservative with the things we add, it's 95% correcting comments/documentation and the other 5% minor (behavior-preserving) transformations.

We work in Python, so those transformations are things like using `collections.defaultdict` instead of a plain dictionary where it makes sense etc etc.

mrgriffin··on How to Do Code Reviews Like a Human
Similar to dmoy our code review workflow supports making a (small) change while reviewing. We use GitHub PRs, and the edit function combined with choosing a commit message like "!fixup <original commit message>" and `git rebase --autosquash` (or `git merge --squash` when merging the PR) works well.

It's funny that you mention not wanting people to drop what they're doing as IMO that's one of the advantages of the approach I'm describing. The reviewer is already in the code, whereas the person being reviewed has often moved on to something else.

mrgriffin··on How to Do Code Reviews Like a Human
I mostly agree, with one exception: the author prefers "sucessfully -> successfully" to "You misspelled ‘successfully.’". We have a lot of these kinds of comments at work and I find both equally frustrating. I wish reviewers would just make those simple changes themselves, it's almost the same amount of effort as writing a comment.
mrgriffin··on JavaScript: The Curious Case of null &gt;= 0
I find this behavior surprising:

  >>> d = {0: "int"}
  >>> d[False] = "bool"
  >>> d
  {0: 'bool'}
  >>> nan = float('nan')
  >>> d[nan] = 0
  >>> d[nan] = 1
  >>> d
  {0: 'bool', nan: 0, nan: 1}
Yes, yes, it's because issubclass(bool, int) == True, and nan != nan, but weird.

And if we include Python 2 you get the truly ridiculous:

  >>> dict() < set()
  True
  >>> dict < set()
  False
  >>> 0 < dict
  True
  >>> 0 < 1j
  TypeError: no ordering relation is defined for complex numbers
To compare e.g. a dictionary and set we compare the _names_ of the types! Except complex numbers, because they don't have an ordering. I actually have come across this as a bug in production.

Personally I'd just make any comparison involving different types an error. That probably interacts poorly with subtyping, but it's a price I'm willing to pay.

← PreviousPage 2 of 2