HN user

ddfisher

145 karma

david.davidfisher@gmail.com

Posts2
Comments28
View on HN

This is exactly what mypy allows, actually! (Except for speedups -- types currently have no effect on runtime behavior, and it turns out they wouldn't make a big difference anyway.) The hybrid type system concept is called "gradual typing", and it's actually powered by some somewhat-recent developments in programming language theory. See this seminal paper by Jeremy Siek in 2006 if you're interested in the details: http://scheme2006.cs.uchicago.edu/13-siek.pdf

[Source: I'm a mypy core developer.]

Good question! There are separate capitalized types for List, Dict, etc provided as part of the `typing` module in order to let you specify element types. Types are all normal Python expressions, so if you wrote `list[int]` you'd get a runtime error, because `type` objects (i.e. the `list` class) aren't subscriptable.

It should work with the Python 3 syntax if you quote your type annotation. I.e.

  def f() -> "Bar": ...
instead of
  def f() -> Bar: ...
(This is normally used for forward references.) This makes it slightly less nice, but not a terrible workaround overall.

Yeah, you need to write `from typing import List` to get the generic List class that you can parameterize with an item type. As you pointed out, you can use the builtin lowercase-l list without importing anything, but that doesn't allow you to specify the item type.

This is intended behavior, actually! By default, mypy doesn't type check the interior of functions that don't have any type annotations. This lets you slowly introduce types to a large codebase without having to convert everything at once (or even file by file). Adding a type annotation to "bar" will cause mypy to check it:

  def foo(n: int):
      pass
  def bar() -> None:
      foo("123")

  >> main: note: In function "bar":
  >> main:4: error: Argument 1 to "foo" has incompatible type "str"; expected "int"

While I agree that being skeptical about self-help books is a good thing, I think you made a big mistake in your specific example. I have not looked at "The Feeling Good Handbook" that you linked to, but I am quite familiar its predecessor (by the same author), "Feeling Good", which is excellent. It has helped a couple of my friends, and at least one other HN reader.[1] Further, its efficacy is supported by at least one clinical study.[2]

You're right about the image, but the book is worthwhile.

[1] http://news.ycombinator.com/item?id=4509281

[2] http://www.ncbi.nlm.nih.gov/pubmed/2738212 (The book is not cited in the abstract, unfortunately, but I believe this is the correct study.)

I think "the root of all evil" is, in general, not a good choice of phrase. I understand the vehemence with with you speak, but I think it's a bit overly hyperbolic and creates quibbling over the word "all". Saying that religion is the cause of much evil (which far outweighs the good) would be sufficient.

> Anyone who can complete Tour de France at all or moderately but steadily grow an investment portfolio over the years should be extremely satisfied with just that already.

(I'm not certain what "should" means in that sentence - a moral judgement? - but I'll interpret it as advice.) I think that this is excellent advice for some people, but poor advice for others. I don't think there is anything wrong, per se, with wanting to be the very best at something. There's just a trade-off: you can be happily excellent, or you can take a chance and be perhaps the best but most likely just unhappy. But this decision is, in my opinion, a personal one: happiness does not have to be the ultimate goal of life.

I recently started using Phabricator (http://phabricator.org/), which is open-source, and find that it's quite easy to use/set up. It's also used and well regarded by a number of startups, including Facebook, Asana and Quora.

Disclaimer: I've made minor contributions to Phabricator and will be making larger ones shortly.

Spark 15 years ago

Because Haskell is evaluated lazily, two maps doesn't imply two iterations over the data. In this case, I would expect only one pass through the data for both of the maps. Out of curiosity, I did a quick criterion benchmark for both functions. Here's the result on a list of 100 elements:

  benchmarking spark_mggcl
  mean: 49.29483 us, lb 48.77776 us, ub 50.25594 us, ci 0.950
  std dev: 3.495423 us, lb 2.140951 us, ub 6.373469 us, ci 0.950

  benchmarking spark_ocharles
  mean: 60.12347 us, lb 58.95586 us, ub 61.48084 us, ci 0.950
  std dev: 6.434853 us, lb 5.529613 us, ub 7.824865 us, ci 0.950 
The simpler version appears to be faster.

(As an aside, is there something in particular you dislike about do syntax? I find that it often makes things more readable, though slightly more verbose.)

As someone considering paleo, I'd be interested to hear what studies you thought well supported the claim that saturated fats aren't the problem and why you thought those studies were more reliable than the ones that indicte the contrary.

While I too find it odd that your original comment was downmodded (has it been edited?), I don't think that a personal attack is an appropriate response. It doesn't seem like younata was being a jerk (from my reading of the comments), but your response is a bit vitriolic even if he was.

From your comment history, I speculate that you - like me - are a long-time reader and only an occasional poster. These posts stand out as being unusually negative. I'd urge you to strongly consider changing your tone (and perhaps deleting your posts in this thread). Don't let this one altercation drive you away from the community.

Best -- David

Perhaps I had the wrong impression, but I thought the correct response to a factually incorrect post was to point out the correct information in a reply, not to downmod the post. This is more inclusive (as everyone is misinformed at times) and is more useful to the community (because it provides them with the correct information).

FYI: you're probably not being downvoted because people think you are incorrect. (In fact, it is my understanding that incorrect information should generally be politely corrected, rather than downvoted.) Instead, the downvotes most likely result from the fact that a post saying only "dupe" adds nothing to the conversation. Noting duplicate articles can be useful when there were interesting comments on the previous version, but should then be accompanied by a link to that post and/or a summary of the interesting comments.

Edit: Sorry if this comes off as overly didactic: I incorrectly assumed you were new. However, my main point still stands.

"E.g. args.length returns 0, and they try to access the first element in the list (due to heritage from c pointers we start counting at 0) which is the 'zeroth' one, which doesn't exist"

I'm not sure if you're making some subtle point here that I'm missing, but it is not the case that any of the elements of array will be accessed by that code if args.length is 0. If args.length is 0, then the exit condition (which is evaluated before entering the loop body for the first time) will be false, and the loop body will not be executed at all.

The most recent edit to the article prepended "Nazi" to "Germany" and contributed nothing further. This seems rather unnecessary, as the sentence clearly specifies that this occurred during WWII. Did you make this change?