News for hackers. Stuff that matters.
Re:What? More 8-Bit Microcontrollers? by atoav on Friday July 01, 2022 @05:12AM (#31944053)
I program C, Python, Rust and Javascript, Java, C#, C++, ... And I can assure you the reason I started using Rust is not that I find C too scary. It is an interesting language that has some seriously interesting concepts in it.

To rule out certain (very security relevant) classes of mistakes entirely is good as well.

That being said, learning Rust also made me a much better C programmer, because it forced me to deal with many problems and concepts that might bite even experienced C programmers once in a while all while using a language that just won't let you do the stupid stuff.

Of course that makes you angry and you curse at the compiler. And then you think about why this doesn't work and this is the moment where you pause and go: "Oh.."

For me the enlightenment came when a tech blogger asked for the fastest string tokenization program in any language and I sent him my 10 minute naive Rust thing and it won second place. The first place was hand crafted assembler. My thing could handle UTF-8, the other could not.

This is a real and tangible thing, not just some "shiny" thing.

Re:What? More 8-Bit Microcontrollers? by 2143 on Friday July 01, 2022 @05:38AM (#31944218)
> it won second place

Out of how many?

While I'm pretty sure you're a very competent programmer, there's a possibility others used non-optimal algorithms.

A good algorithm in a slow language can, on the limit, be faster than a bad algorithm in a faster language.

Case in point: Norvig's sudoku solver in Python blows everything else away in performance because he put a lot of thought into the algorithm [1]. I wrote a C program to solve sudoku (using a backtracking approach), and it was nowhere as fast as Norvig's python program. Can anybody conclude python is therefore faster than C? No! The only thing you can conclude from that is that I'm a lousy programmer :)

Sure you can reimplement Norvig's program in Rust or C or assembly or Brainfuck or whatever, but that's besides the point.

[1] https://norvig.com/sudoku.html

Re:What? More 8-Bit Microcontrollers? by atoav on Friday July 01, 2022 @06:22AM (#31944491)
> Out of how many?

20 or so.

It has been a while ago so I cannot recall the exact way I did it, but I certainly didn't implement any specific algorithm, I just did the straightforward thing using Rusts builtin functions as a realistic emulation of a lazy programmer.

The point of my comment was not to claim that Rust is the faster language. The point was that you can write mediocre Rust and still end up with extremely performant code that covers a lot of ground.

Re:What? More 8-Bit Microcontrollers? by randrews on Friday July 01, 2022 @06:55PM (#31954078)
My experience exactly. I wrote an emulator in Rust for a thing implemented on an FPGA that generates a video signal. For the first pass, I just ported the Verilog code to Rust, essentially: big loop over all the pixels every frame, figure out which color it should be, return that. There are a ton of ways to factor things out of that so you're not doing repeated reads of stuff, and I was going to gradually put them in until it was fast enough...

And then the naive solution ran at 100 fps.

So uh. Okay then. I see the value in Rust now.