Unreasonable Effectiveness of Abstractions

Sdílet
Vložit
  • čas přidán 10. 02. 2024
  • Previous Episode: • Raylib.js
    References:
    - raylib.js - github.com/tsoding/raylib.js
    - Tsoding - Snake - tsoding.github.io/snake-c-wasm/
  • Věda a technologie

Komentáře • 64

  • @valshaped
    @valshaped Před 5 měsíci +100

    20:15 Hi! Infosec people here: if you use
    printf(s)
    You're passing s as the format string parameter. The function uses the format string to interpret *raw bytes on the stack* as types of data to be formatted, and one format specifier in particular, %n, will actually write the number of characters printed so far to a variable on the stack. If you allow arbitrary user input as a format string parameter, that user input can print some garbage and then *write the printed length to the return address,* jumping to (nearly) arbitrary memory addresses.

    • @TsodingDaily
      @TsodingDaily  Před 5 měsíci +64

      Damn, I should try to do that!

    • @phitc4242
      @phitc4242 Před 5 měsíci +1

      on termux %n doesn't work

    • @benisrood
      @benisrood Před 5 měsíci

      wheeeeeeeeee

    • @tekno679
      @tekno679 Před 4 měsíci +1

      This %n can be used together with a buffer overflow and an index x like this `%x$n` to write arbitrary data to any arbitrary address(es?). This is a common challenge in pwn ctf challenges.

  • @nulligor
    @nulligor Před 5 měsíci +63

    sounds good
    sounds gud
    sounds gucci
    sounds a-tamagutchi
    a-letsa-go

    • @jesusmgw
      @jesusmgw Před 5 měsíci +6

      Compile mutha flippa!

    • @jamesmay2083
      @jamesmay2083 Před 5 měsíci +4

      *dabs*

    • @SlinkyD
      @SlinkyD Před 5 měsíci +8

      can your $insert_noun_here do that?

  • @thenwhoami
    @thenwhoami Před 5 měsíci +8

    For someone who is interested in grasping a lower level understanding of the stack, your channel is a gold mine.

  • @John-yg1cq
    @John-yg1cq Před 5 měsíci +9

    What I love about the philosophical question is how it highlights so many interesting points.
    Firstly, something I noticed that I am seeing more and more is how header files really are just interfaces, and that the underlying implementation is the platform specific code and never had to be C specifically. This is so brilliant because you could implement any C interface in any language that can go through some unified assembly.
    Then with the GLFW duplication, we really see how the browser is a sandbox and something like Emscriptem is a sandbox, and since you're going with a sandbox on top of a sandbox, you need the same abstraction. While just going browser native (which is JavaScript) you can skip the second sandbox.
    Furthermore this approach also highlights how we should maybe break up the C standard library into more unified single header files (ala STB) so that it's even more portable. Maybe even something like the D language modules combined with native JavaScript becomes super interesting for file size.
    Man, this little idea is SO COOL!

  • @guillemgarcia3630
    @guillemgarcia3630 Před 5 měsíci +6

    Im loving the thumbnails ❤

  • @Wilfried-uw2uu
    @Wilfried-uw2uu Před 3 měsíci

    This channel is so underrated. I tell about hi to everyone I l know. time to bring bakc the good old days of people truly understanding the code they write

  • @soniablanche5672
    @soniablanche5672 Před 5 měsíci +18

    fun fact: You can do type punning in javascript with typedarrays

    • @gerooq
      @gerooq Před 23 dny

      thats childs play, you can multiply a Class with a function in javascript to get a string 😏

  • @flexzuu
    @flexzuu Před 5 měsíci +4

    I wonder how this whole thing would look if you try to move the cut line one layer down (to the platform thing in your drawing). And maybe have a WEB_CANVAS platform or a a WEB_GPU platform. But i maybe the issue may be that platform in raylib depends on too much stuff you would need to implement then.

  • @potatopassingby
    @potatopassingby Před 5 měsíci +2

    nice thumbnail! definitely pulled me 😂

  • @ihspan6892
    @ihspan6892 Před 5 měsíci +1

    Sir, you are a great wizard!

  • @xesau
    @xesau Před 5 měsíci +8

    Honestly your channel is just one big tutorial on refactoring

  • @SlinkyD
    @SlinkyD Před 5 měsíci +5

    Filled 'em
    rect 'um

  • @berndeckenfels
    @berndeckenfels Před 5 měsíci

    I don’t like to move the font logic into the abstract game engine, since it will not know about all platform capabilities (like why not use browsers alignment which might be aware of micro kerning)

  • @Vulto166
    @Vulto166 Před 5 měsíci +5

    I'm interested to know how much Tsoding cares about reverse engineer programs.

  • @GK-rl5du
    @GK-rl5du Před 5 měsíci +2

    @Tsoding building a process sandbox from scratch.. sounds like a cool idea 💡?😊

  • @AntonioDellaRovere
    @AntonioDellaRovere Před 5 měsíci

    const char *s is not a pointer to a string per se, it is rather a pointer to unsigned bytes in memory. With "%s" you instruct printf() how to treat those bytes. It will print them out one byte after the other as ascii character until it reaches a zero termination byte.

  • @hwstar9416
    @hwstar9416 Před 5 měsíci +4

    1:00:18 btw Rust (also added in C23) have unreachable. Which basically tells the compiler this branch is never reached and the compiler can make optimizations based on that. For example:
    void foo(int *ptr) {
    if( ptr == NULL )
    unreachable();
    /* rest of function */
    }

    • @GuerreroMisterioso95
      @GuerreroMisterioso95 Před 5 měsíci +2

      Why add a branch condition that will never be reached?

    • @origamitraveler7425
      @origamitraveler7425 Před 5 měsíci +5

      you're basically telling the compiler to induce undefined behavior in the case of it happening, for optimization purposes, I think

    • @origamitraveler7425
      @origamitraveler7425 Před 5 měsíci +2

      like, formally it should never happen, but in practice it might

    • @hailuong9295
      @hailuong9295 Před 5 měsíci +1

      Btw Zig has unreachable keyword long before Rust and C even introduce them, the goal is tell the compiller in release mode "remove this check as i already sure this code cannot be reach, and i fine undefined behaviour happpen if this branch get execute"

    • @hwstar9416
      @hwstar9416 Před 5 měsíci +1

      @@origamitraveler7425 yup that's exactly it.

  • @matteovalentino4890
    @matteovalentino4890 Před 5 měsíci +1

    Nice

  • @ltxr9973
    @ltxr9973 Před 5 měsíci

    Oh ok, the thumbnail made me think you've written a C compiler in javascript

  • @blackhaze3856
    @blackhaze3856 Před 5 měsíci

    Where is the discord announcement? Sad 😔

  • @Nextdesu
    @Nextdesu Před 2 měsíci

    About type punning, i dont know c but shouldnt your color type be a union? Than you can treat it as both a struct and u32 and explicitly indicate this.

  • @vanviccardi7553
    @vanviccardi7553 Před 5 měsíci +1

    nice

  • @KoltPenny
    @KoltPenny Před 4 měsíci

    24:50 They also didn't know about how basic memory handling works so they invented "a memory safe language". The result is a complainer (like them), not a compiler.

  • @mr.j0159
    @mr.j0159 Před 5 měsíci

    Tsoding is a proud romanian.

  • @D-V-O-R-A-K
    @D-V-O-R-A-K Před 5 měsíci +3

    Why not make a C program that transpiles raylib to js automatically?

    • @anonymousanon4822
      @anonymousanon4822 Před 5 měsíci +7

      Because that's magbitudes harder than just doing it by hand

    • @homelessrobot
      @homelessrobot Před 5 měsíci +2

      or a js program that just transpiles c to javascript. then we can just transpile linux to ms-edge

  • @Seedwreck
    @Seedwreck Před 5 měsíci

    Susha moment

  • @alh-xj6gt
    @alh-xj6gt Před 5 měsíci

    13:40 .. ohh man .. here I am for your merit in C code, emacs magic, approach and explanation. If I want to see someone read or nearly scream way waaay too much chat with a loud clown voice - like those hyper hotel kindergarten entertainers - I would watch thePrimeagen. Irony aside if there is a slight hint of pressure to perform like a class clown, please don't feel pressured, there will be viewers that appreciate your work more than pulling up chat every 200-400 seconds - like a bad advertisement reel that is unskippable - with the streamer nearly peaking the mic every 10-30 seconds throughout the 1-4 Minute "chat interaction".

  • @zero3juan
    @zero3juan Před 5 měsíci

    lol includes a library to downcase a letter instead of subtracting 26? love your videos, btw

  • @anon_y_mousse
    @anon_y_mousse Před 5 měsíci +1

    I think a lot of newer developers don't bother to study history or any tech that they consider "outdated", so of course they won't know of type punning. The sad thing is that it also makes them inferior developers who continuously reinvent the wheel. That's a thin needle to thread, especially given that creating a new programming language is often viewed as reinventing the wheel even when it's not, but the most obvious example I can think of is when a solution has to be reverse engineered for a problem that has already been solved by another language. If you just copy their solution and then move on from that point, then great, but it's when a programmer doesn't know the solution already exists that causes problems. As a corollary to that problem, you also have developers that don't keep up to date with their skills and try to solve problems in a new way when a better way exists in another language. Consider every developer that tells me C doesn't do this or that and then says their language of choice solves that issue that was already solved in an earlier C standard, sometimes C99, oftentimes C11, but the most ridiculous is when it involves C++ and they've never even heard of Boost, never mind what the committee has been doing in the past 25 years.

    • @TheMelopeus
      @TheMelopeus Před 5 měsíci +1

      Is it the fault of new developers when there is just so much to learn it's impossible to know what you need to know to become a good developer without being a good developer so there's that :)) People go to what brings them money, if they didn't do that since childhood and played with the pieces for so long they know the lower level stuff it's really difficult for someone just starting out

    • @anon_y_mousse
      @anon_y_mousse Před 5 měsíci +1

      @@TheMelopeus Consider every new language developed in the past decade and a half. Most implementers don't study other languages, even the ones they claim they want to replace, then they end up coming up with an awful solution that was already solved in the language they're attempting to replace and much more eloquently than their new attempt at the problem. Only makes it worse when they claim that language X doesn't do what their fancy new language Y does even when it could already do it for a decade.
      If a language designer doesn't study history then they'll be doomed to reinvent the wheel and make it square because they like squares more and have to learn what those who came before them learned that a round wheel works better.

  • @friren_elf
    @friren_elf Před 5 měsíci

    1:39:33 rand2 :)

  • @johnm3066
    @johnm3066 Před 5 měsíci

    This is Tsoding, of course he's Russian. The dude is a beast!

  • @gerooq
    @gerooq Před 23 dny

    “newer generation reinventing their own wheels” you mean like what you’re doing here and every other video? 😂

  • @ariemelans7817
    @ariemelans7817 Před 5 měsíci +8

    Hi Tsoding, i would like to appreciate that if you could make a video of Problems Solving on Codeforces. It would help a lot, thank you...

    • @matthewchampagne9621
      @matthewchampagne9621 Před 5 měsíci +14

      Sounds pretty boring

    • @vxcute0
      @vxcute0 Před 5 měsíci +1

      WHAT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!, I want to say to tsoding to calm down if you saw that comment

    • @ariemelans7817
      @ariemelans7817 Před 5 měsíci

      @@matthewchampagne9621 nah, solving problems are required in this present time bruh

  •  Před 5 měsíci +1

    j ass

  • @lolcat69
    @lolcat69 Před 5 měsíci +2

    FINALLY EARLY TO THE VID!!! (First btw )

  • @forayer
    @forayer Před 5 měsíci

    Nice