Remix.run Logo
eru 2 days ago

You'd probably want 'return len(str)', if this is Python?

In any case, for some applications this is indeed a great hash function. Programs like rmlint use it as part of their checks for duplicate files: if files have different lengths, they can't have the same content after all.

Sharlin 2 days ago | parent | next [-]

Yes, too much Rust :D Eliding the `return` becomes so intuitive after a while that you sort of forget that most other languages require it.

eru 2 days ago | parent [-]

Haskell and the Lisps also work like this.

Sharlin 2 days ago | parent [-]

Yes, I know, it's the natural way to do it in functional programming. Honestly I doubt there are any FP languages that don't do it like that.

eru a day ago | parent [-]

I like that Rust, just like Lisp and Haskell et al also allow any block to return a value, not just functions. So if-then-else and loops etc can do that. It be nice if Python could do that.

Perhaps I should hack up Python to allow that. Would be an interesting little project.

andai 2 days ago | parent | prev [-]

Re: missing return keyword

Actually, in Python, None is a valid key...

(I'm so sorry. JavaScript has ruined me.)

tetha 2 days ago | parent | next [-]

Any `return c` for some constant is a valid and correct hash function. It just has a lot of collisions and degenerates hash-maps to terrible performance. That was in fact my first thought when I read "simplest hash functions".

eru 2 days ago | parent | prev [-]

That's why I said "probably".