←back to thread

Svelte 5 Released

(www.npmjs.com)
390 points begoon | 1 comments | | HN request time: 0.367s | source
Show context
notpushkin ◴[] No.41890141[source]
Good work! I’m not really sold on the runes stuff though (tldr: https://svelte.dev/blog/runes)

The old way is a bit “magical” in a sense that it does some stuff under the hood to implement the intention behind your code, but it reads really straightforward:

  let counter = 0;
  // ...
  <div>{counter}</div>
`let` in a .svelte compoment makes a variable reactive. If your state is outside a component, you use stores.

With the `$store` rune, the way you make reactive stores inside and outside components is the same, but it only works in .svelte.js/ts. The unification is great – but why not just use `let` in .svelte.js, too?

  // counter.svelte.js
  export function createCounter() {
    let count = 0;
    return {
      get count() { return count },
      increment: () => count += 1
    };
  }

  // App.svelte
  <script>
    import { createCounter } from './counter.svelte.js';
    const counter = createCounter();
  </script>

  <button on:click={counter.increment}>
    clicks: {counter.count}
  </button>
I understand it can be really tricky – e.g. you might want to use let for things that are not modified in runtime and do not need reactivity, but it should be possible to determine in compile time. (Actually after writing this all up I think I know why Svelte went with runes instead, haha!)

But again – really good work and I hope to try it out on my next project!

replies(2): >>41890504 #>>41891025 #
1. youssefabdelm ◴[] No.41891025[source]
Same... It's just not ergonomic. I much preferred the simplicity as someone who loves Python for that same reason. I love code that looks like this:

  import whisper

  model = whisper.load_model("turbo")

  result = model.transcribe("audio.mp3")

  print(result["text"])
Or this (although this is slightly 'dirtier'):

  import eng_to_ipa as ipa
  def get_homophones(word):

      words_that_sound_the_same = []
      the_way_this_word_looks = word
      the_way_this_word_sounds = ipa.convert(word)
      words_that_contain_that_sound = 
  ipa.contains(the_way_this_word_sounds)
      for every_word in words_that_contain_that_sound:
          the_way_that_word_looks = every_word[0]
          the_way_that_word_sounds = every_word[1]
          
          if the_way_this_word_sounds == the_way_that_word_sounds:
              if the_way_that_word_looks != the_way_this_word_looks:
                  words_that_sound_the_same.append(every_word)

      return words_that_sound_the_same
                   
  get_homophones('their') #[['there', 'ðɛr'], ["they're", 'ðɛr']]

Or Raymond Hettinger style.

Chef's kiss. I hate code that overcomplicates.

Blah blah 'making stuff explicit'... I don't think that it's impossible to make things explicit while also making it ergonomic, and humane to use.

Anyway, programming as a whole is an old paradigm, sigh, might as well make the new thing myself.