5
AlgoRythm
89d

I gotta say. Zig generics / comptime code gen remind me of old (pre-prototype) JavaScript code where you construct an object using parameters and return that object to be used as a class (except in this case it's actually turned into a class at comptime instead of an object masquerading as class)

Comments
  • 2
    That being said: I'm on my way to creating something that lets me resolve URLs (for web server routing) completely on the stack!
  • 2
    @jestdotty Honestly I am very glad I skipped rust. My least favorite part of c++ by FAR was template classes and when I think of Rust, I just think of being unable to avoid crazy template-like syntax as part of my everyday usage whereas even in c++ I only had like 2 legitimate reasons to make a template.

    Zig has a certain beauty about it. They treat classes like first-class citizens. As long as your task can be done at comptime, they allow a squish and soft interpretation of the type system and it's a little wonky at first, but absolutely freeing once you get the hang of it.
  • 2
    @AlgoRythm yeah I'm not used to this

    *grumble grumble*
  • 2
    @jestdotty never too late to trade in rust for zig :)
  • 0
    I can't tell if it's a full-fledged language or a TypeScript equivalent (wrt C)
  • 1
    @azuredivay it doesn’t transpile to c. They’re actually, I believe, even looking into ditching LLVM and making something in-house to get even better results.
  • 2
    @AlgoRythm Swift is also a great language which lets you compute and synthesize things at compile time.

    When the zig-fan youtuber ThePrimeTime first tried Swift, he instantly fell in love with it 😂
  • 2
    I love this kind of posts. Pure dev and educational. Learned smth.

    It's like the old JS indeed. In that time - i was going hardcore on ExtJS (People wouldn't learn this because of steep learning curve. Those people should see React now. ExtJS was way ahead of it's time). ExtJS wasn't free, but to be fair, there was no framework comparable to this. Don't 'mootools' me or even worse - 'jquery ui' me. Wrote huge frontend application in it. So heavy, chrome was in that time way faster than IE so every company computer upgraded to chrome.

    I think this complete OO stuff worked pure by coincidence btw :P

    @Lensflare Swift sounds like a nice looking but slow car my mom would buy. She did
  • 1
    @retoor in case you wanted to imply that Swift is slow, it isn’t. 🙂

    Swift is the awesome looking and lightning fast car. Also quite beginner friendly. More so than C# or Rust for example.
  • 0
    @Lensflare I try not to steal idea's from other regex interpreters but I did read the C# source code from the .Net RegexInterpreter today and I was really like "Hmm, what is C# actually a nice language". I compiled my C interpreter to a so lib and benchmark it against C#. Mine is a LITTLE bit faster. Don't know if external lib slows down a bit. I was amazed that such fast interpreter was written in C#, it doesn't use the C implementation as backend.

    Ok, back to the Swift. Dude, it's really slow. But besides that, it doesn't feel by far as decent like a VW Polo which is in the same class for example while just being a few thousand cheaper. A swift is 21.000 or smth.

    The Sport Swift is just darn beautiful.

    Interesting how the VW UP!, Aygo and Mii disappeared while they were so popular huh? They didn't make enough monneeh on dem. Now we're back to cars worth 21.000. Bastards
  • 2
    @retoor the fastest regex engine I have ever used was in Node.JS

    There must be years of intense optimization there. Interested in adding that to the benchmark mix.
  • 2
    @Lensflare I’m glad prime promotes Zig so much. Not only does it get me hype, but it adds recognition to the language.

    I found it originally from davepl’s prime number sieve benchmark between every programming language. Zig came ahead of even ASM.
  • 0
    @AlgoRythm my regex beats the original C one AFTER compilation. The C has a slow compiler but executes batshit fast. All my focus was on beating that one. I did. Challenge accepted! Will try the node one. I wonder if i can load an so in node. I'll be back with updates about this where nobody asked for
  • 0
    @AlgoRythm tsoding got even paid to promote the language. IIRC he liked it more than Rust since the good language binding with C
  • 1
    @retoor I’m not sure about c binary compatibility with node without some sort of binding layer. Never tried.

    I believe that the node regex engine is googles RE2 engine based off the knowledge that Google maintains v8. I know the default c++ and even the boost c++ regex engines both are awful. Never tried c regex though.
  • 1
    @retoor yeah zig and c are best friends whereas rust and c are like mutuals. Not a great look for a machine language IMO
  • 1
    @AlgoRythm I won't try the boost one. I'm one hundred percent sure I beat that one. Boost is so sickly bloated. I do know that just recently it was updated not to hang in infinite loop anymore. But mine can do that too with some faulty expression I guess.

    It was hard to find a balance between code quality and performance to beat the C interpreter. I couldn't believe how fast it was compared to mine at the beginning but then - i found out it uses the libc dynamic library which was compiled with optimizations and my application wasn't. The C interpreter get's faster every time you execute it. A few times it optimizes or something during parse time. Not only compile time. Writing a FULL featured regex is quite an art. Most fun thing I ever coded tho
  • 1
    @retoor after I finished my HTML parser, I started on a query interpreter a la document.querySelector[All]. At that point I got bored of c++ and state machines.
  • 0
    @AlgoRythm you used a state machine for that? I wrote one too in C. I was very annoyed by the non-closing tags. The code was so nice but then had to rape it with that exception. Did you write your own lexer? Did you support only valid html or also dirty ones? Using single quote / no quotes at all for attributes? Mine did only perfect HTML IIRC, double quotes and stuff. It also supported kinda XPath IIRC. I do remember that it was a lot of fun
  • 2
    @retoor I used a state machine for both the lexer and parser. It handled self closing tags and was lenient with dirty HTML such as automatically filling in missing end tags. It’s a great project honestly! Too bad I hate c++
  • 0
    @Algorythm I tried to install ffi-napi which is the binding of choice between an so-lib and node. After trying: node 22, 18, 12 and 8, compiling ffi-napi from source and then finding a `-1`-ed closed question from 12 days ago on SO I decided that i had enough. This is a clean install ffs and all compilation tools are available fffs. For now, I lost interest, I kinda expected it to have it working in a hour since I already have a working so-lib. In dotnet I had it working in a hour including installation. Also, that installation didn't work out of the box. Couldn't find sdk's without some kungfu. Installation of node with nvm was more comfortable tough
  • 1
    @retoor nvm is a blessing. I’ve never bound Node.JS to anything before though.
  • 0
    @Algorythm I never miss smth from C++ when writing C. I do like some typing. My keyboard goes like an AK47. Rakketakketak. Only namespaces are really missing in C
  • 3
    @retoor the global namespace in c is ten thousand miles long. Zig solved this oh so nicely with its import system.

    Though I will admit I am a OOP lover. Inheritance is highly overused but it’s beautiful when used correctly. The rest of OOP kinda sucks though.
  • 1
    @retoor why do you keep saying that Swift is slow? 🥺

    It’s faster than C# because it’s compiled to machine code, not to byte code which is then interpreted. It doesn’t have GC to slow it down and has a lot of value semantic primitives which avoids slow heap allocation. It doesn’t have a notoriously expensive and slow exception mechanism like C# does, because again, value semantics and GC.
    It relies on the type system to encode many things right into it at compile time rather than relying on dynamic resolution at compile time which slows C# down.
    And it has a macro system which allows code execution at compile time.

    It’s a perfect blend of convenient and elegant syntax and high speed that you would only expect from a low level language like C.
  • 1
    @Lensflare I'm only talking about the car and I only said that Swift sounds like a slow car. I didn't make any comment about the programming language :P But thanks for this great review. I seriously appreciate. Doesn't take away that Swift also sounds like smth you could clean floors with using soft tissues tho
  • 1
  • 1
    @lensflare / @algorythm deno is awesome! Fixed it in no time to load c extension in TS:

    ```

    const lib = Deno.dlopen(

    "./librmatch.so",

    {

    match: { parameters: ["pointer", "pointer"], result: "i32" },

    }

    );

    ```

    Now i can just do:

    ```

    const res = lib.symbols.match(arg1,arg2);

    ```

    But you have to run deno with --unstable-ffi flag.

    Deno is cool in general, live TS compiling, compiling to binary, build in ffi...And the installation is a one liner
Add Comment