Live data from Hacker News

I coded something dumb and I'm proud of it

plbrault.com

81–88 of 88 posts

Re: I coded something dumb and I'm proud of it

#81

Earlier quoted context omitted.

To be fair, this (like many applications of reactivity) is conceptually very different from embracing mutability. And at least at a glance, it looks conceptually much closer to React than that. Where React differs isn’t immutability, but where the mutation of state/effect boundary is (at the component/hooks-rules, versus something more fine grained). In every possible approach, a state change needs some orchestration…

Solid's proxy-based approach was indeed one of the major influences. It's also similar to reactive() in VueJS. There's one novel thing in mutraction that's not in either though, which is the undo/redo log. It might not be very useful in practice. I'm not under the impression that I really created anything fundamentally new here. I just scratched my own itch. Really, I think the main difference is that there's nothing…

> There's one novel thing in mutraction that's not in either though, which is the undo/redo log. It might not be very useful in practice.

On the contrary! That alone is cause for me to give it another look. Stuff like state history is sorely lacking in the industry in general, and can enable powerful things like time travel debugging. I’m super curious to look into how it works when I get a chance.

> Really, I think the main difference is that there's nothing in mutraction like a virtual DOM.

Clarification (as I presume you know this, but in case anyone else isn’t familiar): this is also how Solid works.

> I've seen the word "orchestration" used before with respect to UI framework architecture. I must confess, I don't understand what it means. By default, in mutraction, most mutations are immediately applied to the corresponding DOM elements.

That’s exactly what I meant in this context. Without something like reactive Proxy tracking and binding to the produced DOM nodes, you’ll have:

1. Some mutable state, like objects and arrays and reassignable variable bindings.

2. Some view DOM.

3. Some code that manually assigns 1 to 2.

4. Some code that manually handles events in 2 and applies mutations to 1.

5. Recurse.

This can be as “bare metal” as direct DOM interaction, but usually tends to look more like jQuery. As popular as that is in HN comments, it’s really hard to manage in applications beyond a certain level of complexity (interactivity, feature scope, etc).

Re: I coded something dumb and I'm proud of it

#82
post #36

Earlier quoted context omitted.

How would they have learned a contraction if everything is based on glyphs/ images?

You don't need to know how to write to speak.

No, but languages that use glyphs that are monophonemic and non-phonetic (one-sound per-glyph/character) don't have contractions, which are a function of removing some component part of a word when combining them.

For instance, both Chinese and Japanese use kanji/hanzi, but Chinese is monophonemic, and does not have a phonetic alphabet that characters can be broken into (radicals aside, which are not related to sound). Japanese does (kana).

As a result, combining 2 characters in Chinese never changes the sound of some sub-portion of a character; it's either the whole sound that changes, or nothing. In Japanese, on the other hand, individual kana within a character can change (e.g. Rendaku), so for instance 'hito' (person) put twice in a row becomes hitobito instead of hitohito, because hito is comprised of 2 kana characters: 'hi' and 'to', and 'hi' becomes 'bi'.

Emoji have no subcomponent characters, so you either would need an emoji for a contraction word in addition to the source words, or, more realistically, you just wouldn't have them at all.

Re: I coded something dumb and I'm proud of it

#83

Earlier quoted context omitted.

How would they have learned a contraction if everything is based on glyphs/ images?

Plenty of words are contractions or otherwise combinations of other words that you don't know about unless you're particularly interested in language. "Goodbye" = "God be with ye" for example You don't think "will not" when you say "won't", "won't" is just a word you use with a meaning you understand long before you can write.

See my other comment below, but all the things you're talking about work because English has a phonetic alphabet.

You can break 'be with ye' into 'b', 'y', and 'e', and drop the rest. In languages like Chinese which do not have a phonetic writing system, you cannot drop individual sounds within a word/character in a rule-based way like contractions.

Emojis are not a phonetic system, so unless you created an emoji for "they're", separate from the emojis for "they" and "are", you wouldn't have it as a word.

Re: I coded something dumb and I'm proud of it

#84

Earlier quoted context omitted.

How would they have learned a contraction if everything is based on glyphs/ images?

Haven’t read it, but society is quite changed in The Diamond Age, I think. In the protagonist even speaking English? If not, we could assume it is sort of “translated” into English (in the sense that most fiction that doesn’t take place on modern day Earth is).

This actually makes the most sense out of any of the replies, honestly.

Re: I coded something dumb and I'm proud of it

#85
post #36

Earlier quoted context omitted.

You don't need to know how to write to speak.

No, but languages that use glyphs that are monophonemic and non-phonetic (one-sound per-glyph/character) don't have contractions, which are a function of removing some component part of a word when combining them. For instance, both Chinese and Japanese use kanji/hanzi, but Chinese is monophonemic, and does not have a phonetic alphabet that characters can be broken into (radicals aside, which are not related to sound…

And you're saying that in Japanese and Chinese no word is ever informally pronounced in abbreviated fashion by eliding some phoneme(s)?

Re: I coded something dumb and I'm proud of it

#86
I know this is exactly the opposite of the point OP wanted to make, but wouldn't this be the perfect use case for generators?

You could modify the quicksort in python like this:

  def quicksort_with_steps(arr: [Process]):
      # Standard Quicksort operations
      if len(arr)  pivot.sort_key]

      # the magic happens here:
      # sort each half and pass through the intermediate results of the "sub-sorters" to our own caller, 
      # after modifying them so they contain the entire array again:

      # left half:
      left_final = None
      for left_intermediate in quicksort_with_steps(left):  # we're iterating over the "yield" calls here, not the sorted array.
          yield left_intermediate + middle + right  # pass on the intermediate result to our own caller. 
          left_final = left_intermediate  # the last iteration has the "final" result for the left side, so store it.
    
      assert left_final is not None  # the generator always yields at least one result, so this shouldn't happen.

      # right half: (shorter because we don't have to store anything)
      for right_intermediate in quicksort_with_steps(right):
          yield left_final + middle + right_intermediate

      # the last "yield" returns the fully sorted array.
Then if you call the function, it will return an iterator over all the steps of the algorithm. You could either put it in a for loop like in the recursive calls, or "manually" advance it one step using python's next() function, e.g. inside a frame callback.

I'm pretty sure, if you're insane enough, you could also whip up something using async/await where the algorithm literally "awaits" the end of the animation...

Re: I coded something dumb and I'm proud of it

#87
post #85

Earlier quoted context omitted.

No, but languages that use glyphs that are monophonemic and non-phonetic (one-sound per-glyph/character) don't have contractions, which are a function of removing some component part of a word when combining them. For instance, both Chinese and Japanese use kanji/hanzi, but Chinese is monophonemic, and does not have a phonetic alphabet that characters can be broken into (radicals aside, which are not related to sound…

And you're saying that in Japanese and Chinese no word is ever informally pronounced in abbreviated fashion by eliding some phoneme(s)?

In Japanese, yes, because it has a phonetic alphabet. For example, "konnichiwa" is often shortened as "kon'chiwa".

In Chinese, there is shorthand slang, but not shortening of words in writing based on spoken sounds (since it's not phonetic).

So even if "wo shi" (I am) might be spoken more quickly, there's no way to write that shortened version out in Chinese. You will actually see Chinese speakers use Latin characters and Arabic numerals for phonetic shorthand, (e.g. '88' for "bye bye", because 8 is pronounced 'ba'/'bai'.

Re: I coded something dumb and I'm proud of it

#88
post #78
post #27

Another way to describe what has been done: implement a pure function and avoid storing additional state. It sounds way less dumb that way. It is not really a pure function but the spirit is here. I've done the same during a refactoring of a side-project recently. It handles the input/output to a MIDI controller with many buttons, knobs and matching LEDs. Instead of computing what LED should change at regular interva…

While this sounds elegant, its also computationally more expensive.

In my MIDI controller case, the "compute state and send update" code takes about 8µs, up to a spike of 15µs. The worst case of the code in article is a sort on each frame on a 100ish array, it sounds safe to ignore. Profile before optimizing.
Post reply on HN