6 ms·
There's this absolutely mind bending idea that is - every single function should have a unique identifier. Which is to say: def square(x: Int): Int = x * x sh
by roflc0ptic 6y ago
There's this absolutely mind bending idea that is - every single function should have a unique identifier. Which is to say:
def square(x: Int): Int = x * x
should get hashed (and if it has dependencies, they should get hashed in there, too), and your programming language should track the unique identity of this function, and keep a list of names separately from the hashes.
This totally solves the localization problem: you can just write localizations in one place, and whenever you need to represent them, use the hash to look up your representation. This lets everyone (compatibly) name their functions/variables whatever they want.
Less intuitively, it also basically removes the need for builds. Every function has a verifiable unique identity, so your compiler can tell with 100% certainty whether or not something needs to be rebuilt. When you modify a function, it changes the hash, so you end up with both the old and the new function. Any code which requires the old function can still access it.
This has been implemented in the Unison programming language (https://unisonweb.org/ https://unisonweb.org/) which is very much in alpha. I don't know if there are other platforms implementing it.
It is so elegant and freeing. I am really stoked for the future of programming languages, when localization is just a matter of translating some words.
- efferifick 6y agoDo you know how they would hash a recursive function? Or where I can learn about this? Thanks! EDIT: I am asking more about the hashing function than about the language. Because if there is a recursive function, that means that one would need the hash of itself in order to compute its own hash. One can probably try to compute a hash iteratively until a fixed-point is achieved. EDIT2: but... it is probably a bad idea to do that.
- roflc0ptic 6y agoIt's an interesting question that I don't have an answer to. I don't actually know what this technique is called - I heard about in passing at lambda conf, and just saw last week that Unison is using it. The unison crew is super friendly (Runar once patiently spent 20 minutes trying to explain adjunctions to me, a perfect stranger). I'll ask in their slack channel if this has a name.
- efferifick 6y agoThanks! I'll try to join their slack after work :)
- deleted 6y ago[deleted]
- dmurray 6y agoI also was interested in the answer to this, which turns out to be here: https://www.unisonweb.org/docs/faq/#how-does-hashing-work-for-mutually-recursive-definitions https://www.unisonweb.org/docs/faq/#how-does-hashing-work-fo... Tldr: A singly-recursive function works just fine: the current function has a name at hashing time which it can use to refer to itself. A set of mutually recursive functions gets hashed all together as a "cycle", and to refer to one of those functions you need the hash of the cycle plus an index representing which function in the cycle you want to call.
- rubber_duck 6y ago> I am really stoked for the future of programming languages, when localization is just a matter of translating some words. My experience with localised codebases (in my native language) have been horrifying - like it or not terminology is developed in EN, you either get unnatural sounding "borrow" words and the translation is pointless or worse you get people coining new terminology nobody but them understands. Not to mention fragmented communities, knowledge bases, etc. IMO localised codebases would be a regression not progress and I dread every time I see Chinese in a codebase (simply because they are a large enough market to split the dev community)
- est31 6y agoYeah world languages like Chinese, Russian, Arabic have a chance of building their own thriving developer communities, but for a language like Italian, or even German, forget it. It's too small to be up to a language with 10 times as many speakers. Writing in the local language would put you at a disadvantage far more than you are at a disadvantage by being second speaker of a language.
- Pet_Ant 6y ago> I dread every time I see Chinese in a codebase (simply because they are a large enough market to split the dev community) They aren't going to split it, the rest of us will adapt. English was arbitrary, so was French and Latin and Greek before it. Probably in the form of some Romaji-like equivalent (ideograms are too high a bar) but we will start to adopt it. The largest economy dictates the lingua franca because they produce the most output.
- xxpor 6y agoIt's a pretty amazing coincidence how it just so happens that English is (one of) the most convenient languages to encode into bytes.
- tinco 6y agoHow is that? I don't know about Chinese, but surely Japanese has much better entropy in bytes? As would other languages with more expressive character sets.
- twic 6y agoSo these functions get the same name then: def following_index(i: Int) = i + 1 def item_count_with_free_gift(n: Int) = i + 1
- roflc0ptic 6y agoIt would be easy enough to have multiple aliases for the same function. They can be named whatever you want, they just have the same identity
- JadeNB 6y ago> So these functions get the same name then: > def following_index(i: Int) = i + 1 > def item_count_with_free_gift(n: Int) = i + 1 They'd better not get the same name, since one increments its argument and the other one increments an auxiliary variable ….
- twic 6y agoI am very good professional programmer A++++.
- fermienrico 6y agoLocalization of code language is a horrible idea, no matter how nice the intention sounds. English is as sort of like an international ISO standard to write code in - most people can read it, comment on it, audit it, etc. If people feel, they can write comments in their native language. The entire reason why we have had such a great open source collaboration on global scale is because everyone is speaking the same code language.
- htor 6y agolocalization problem? i believe that is an invented problem. why would anyone write code in his/her native language?
- rhizome31 6y ago> why would anyone write code in his/her native language? Well, actually, a lot of people already do.
- goto11 6y agoI think VBA does this. E.g. the name of excel functions are localized.
- nwmcsween 6y agoeven better make the hash a rolling locality sensitive hash based on the input to the function to find similar functions, etc.
- zubairq 6y agoYes, appshare.co stores code as a hash as well. We were inspired by Unison so full credit goes to them