199 points · by pjmlp · 2y ago · 107 comments
Modern discrete logic chips can be tiny. A cursory browse through Digikey shows some single NAND gates in a 1x1.5mm package. You can probably get smaller if you want, but that's still ridiculously tiny.
Given that and the insane accuracy of modern PCB printing and pick and place machine assembly, you can design a very complex circuit in an extremely small footprint.
From there, the hard part is designing the logic. Today, you'd probably use something similar to an FPGA compiler that turns a program into a logic circuit. Which leaves the hardest part as laying out the circuit on the board.
So yes, you could do it and do it extremely small. But there's good reasons this isn't generally done anymore.
Would certainly be an interesting project though.
Between those four there isn't a whole lot that you couldn't make. I'm interested in these because my kids are of an age where toying around with hardware is something they fancy and this makes it all very much real-world, seeing an LED blink or a computer respond to a button press and move a servo is a completely different experience from what's happening on their screens of mobile computers and laptops and that half-way house between hard core electronics and software is a nice step for them to get more familiar with what computers really are (besides entertainment and homework).
Definitely going to try this game!
It doesn't need to be exactly as fast but similar ball-park would help. If it could, then it would indeed be a fantastic alternative.
Go isn't special, the world just happened to forget how fast AOT compiled languages with modules used to be, before C and C++ took over with their text file inclusion model.
No.
I love it. Cursed programming abominations are one of my favorite things to poke at.
I'd be extremely interested to see how the output binary compares to that of an equivalent C++ program. If the performance and code size optimization is anywhere close, we're just a few steps away from C# on microcontrollers.
Whether or not that's a good idea remains to be seen. It sure would be cool though.
My short fooray into Microcontrollers has shown that all the software development experience for them is absolute garbage.
The quality of IDE's is terrible, the quality of libraries is terrible, portability of libraries is terrible, community support and hope of finding existing library for some sensor is low, etc.
The actual programming language is only a small part of the problem.
So if we just replaced C++ with C# nothing would change.
But actually it would. Because expectations of developers of C#/Python/JS are different, they are not used to C hell of managing individual registers. They want libraries that actually work, their culture is that libraries should be portable.
So it would require a different attitude to work. It would force a different attitude.
Same applies to other compiled toolchains for embedded, even Pascal and BASIC.
https://www.mikroe.com/mikropascal-avr
https://www.mikroe.com/mikrobasic-avr
It has been a matter of attitude since C went mainstream.
Overall you really seem to not have a clue what you're talking about. If you use real grownup tools, the experience of developing firmware is not any different from any other domain. With the obvious exception of debugging being more difficult. Arduino and everything involved with that ecosystem is trash.
Good libraries are available. Good drivers exist. If you simply leave the arena of arduino trash libraries you end up in a world that looks extremely similar to the rest of the OSS world. Quality varies of course, but you'd be a fool to think that no one in the entire industry writes good code.
Besides that, writing a driver is usually a very trivial thing to do. I always write my own, and in the majority of cases it's simply copying registers from the datasheet into a nice C structure. It takes like an hour.
And your core argument is plainly wrong. If the language didn't matter, we'd still be writing straight C, if not direct assembly. Every embedded environment I've seen supports C++. Some even support the standard libraries.
Rust is also becoming quite popular for embedded. But clearly there's no reason or use for that, right?
I mean, if the language doesn't matter, why aren't we still writing COBOL? Why does any language higher than C exist at all?
And no, I don't think C# on a microcontroller would be practical. I want to see it because I think it'd be funny, precisely because it's so inappropriate.
>My short fooray into Microcontrollers has shown that all the software development experience for them is absolute garbage.
Read: I don't know anything about this industry, but I'm still gonna tell you it's all trash.
I'm not sure it's a very smart idea to attempt to dunk on something you admit you know very little about.
However, software is typically not portable between different bdands, and the avaliability of libraries is not the same as desktop / web development, it is significantly behind?
* latest version is 8.0, released Nov 2023
* cross-platform: Windows, macOS (incl. ARM64), and Linux
* can not only target desktop (Windows & macOS) and server, but also WASM, Android, iOS
* used in game development (Unity, Godot, MonoGame, Stride, FlatRedBall, Everyone, CryEngine, Unigine)
* can target embedded development ("IoT")
* developer tools (Visual Studio) that works across Windows, macOS, and Linux
(source: https://dotnet.microsoft.com/en-us/)
.NET was always built for showmanship, with somewhat disappointing results when actually tried.
What do you mean by that? I know what the term means but considering it's one of the most used programming stacks I don't understand what you mean when you use it.
https://developer.chrome.com/blog/wasmgc/
Kotlin's support is in Alpha right now, but works well, and it's one of the first language implementations that can target WasmGC:
https://blog.jetbrains.com/kotlin/2023/12/kotlin-for-webasse...
By comparison, .NET's Blazor targets LLVM, and they either AOT or JIT, however the client has to download a heavier runtime that has at least a garbage collector (nevermind the JIT), and is less than ideal. Basically, the original Wasm was designed for languages with linear memory and still makes a great target for C++ or Rust, but not for managed languages like Kotlin/Java. dotNET's WASM is there only to support Blazor, which is a web framework, a sort of successor to Web Forms and whose future is uncertain. Speaking of which, you're better off with MVC + HTMX, but I digress. So for more interesting use cases, Kotlin is actually ahead in their Wasm support.
For multi-platform support, the company behind it has a vested interest in targeting multiple platforms, and Kotlin Multi-platform support also has Google backing. So, for one, you can share business logic on iOS, as you can integrate Kotlin libraries into Swift applications:
https://kotlinlang.org/docs/multiplatform.html
And they have been porting Jetpack Compose to the desktop and to iOS (and can be used with Wasm in the browser, too):
https://github.com/JetBrains/compose-multiplatform
Also, see this year's keynote at KotlinConf:
https://www.youtube.com/watch?v=c4f4SCEYA5Q&t=2903s
Over on dotNET side, the blessed solution by Microsoft, for targeting iOS, Android, or the desktop, is right now .NET MAUI. So, where's Xamarin? Where's Silverlight for that matter? That's right, Microsoft changes multi-platform solutions like they change socks, and I don't understand how anyone could trust them for a multi-platform solution.
How so?
Dang I was really excited when I saw this because I thought I missed something, but still only support for Windows :(
Unfortunately it's being retired at the end of August next year. Thanks a bunch Microsoft.
is amazing and cross-platform. From the same authors of ReSharper plugin for Visual Studio.
If you're looking for a free alternative, VS Code with the most recent .NET/C# extensions is a very good experience. Good enough that I suspect it is the reason MS felt it no longer worth maintaining Visual Studio for Mac.
https://learn.microsoft.com/en-us/dotnet/api/system.runtime....
There is always C++ for those that don't want a tracing GC.
I want to be able allocate/deallocate C# objects.
Maybe I am missing something, but this doesn't seem like a very complicated ask. Granted, some developers would absolutely blow their feet off with this, but that's why you don't make it a default thing. Hide it behind a csproj flag and throw a runtime exception if the developer presses the GC.NapTime() red button without configuring the runtime appropriately.
There are a lot of use cases where you can strategically reorganize the problem and sidestep the need to meticulously clean your heaps. Running a supervisory process (which is allowed to GC itself) that periodically resets the principal ZGC process via business events or other heuristics is a pretty obvious path to me. Round-based multiplayer gaming seems well-aligned if you can keep allocations to a dull roar.
There is also API to temporarily suppress GC: https://learn.microsoft.com/en-us/dotnet/api/system.gc.tryst...
My use case is such that I have already done everything in my power to minimize allocations, but I have to use some parts of the framework which generate a small amount of ambient trash as a consequence of their operation. My desire to suppress GC is not so much about my own allocation story as it is keeping the gentle, gradual allocations from auxiliary framework items from triggering a nasty GC pause.
My biggest pain point - every time an HttpContext is used there is some degree of trash that accumulates. I have zero control over this unless I want to write my own HTTP+web socket implementation from zero.
The current solution for me is to GC as often as possible in workstation mode, but I would find a zero GC solution even better for this specific scenario. I suspect "rapid GC" is only sustainable while total working set remains small-ish. In the future, I may want to operate with working sets measured upwards of 10 gigabytes.
I can see something like this be useful in certain circumstances. But I would intuitively assume that gen0 collection is probably a better compromise.
Unless you have a remarkably specific need, disabling GC is almost always the wrong path.
The "correct" way is to manipulate GC. You can suspend, manually start a GC run, pin memory, exempt an object from GC, and a few other things I've never played with.
AFAIK the only thing you can't do is immediately deallocate an object. But honestly I can't come up with a situation where an object must be deallocated immediately. Depending on your exact use case, there's ways around that if you really, really need to.
In general, the GC will almost always perform better than any manual manipulation you'd do to it. The main "acceptable" use is suspending GC inside very hot code and deferring the collection until your program is less busy. Like suspending GC while processing one frame in a game, and manually running GC in the space between frames. Even then, this is still discouraged.
Out of curiosity, what's your use case here? I really can't think of any situation that doesn't have a better solution.
now that you can return refs instead of just passing them around, that's also really nice for cases where you want to pass around an interior pointer into some sort of data structure - you can use refs whether a value is allocated via the GC or malloc or stackalloc.
Is it impossible to prove memory safety in the general case due to the halting problem?
https://www.microsoft.com/en-us/research/publication/perceus...
It's interesting how much there still is to discover in this space, despite decades of research.
/memorymodel:scoped_refcounted
Typically you'd see a model that allows file-by-file transitions so that you can slowly clean up a codebase to make it 'safe' for a given model. This is (afaik) roughly how non-nullable references were added to C#.
If you look at it from that perspective, I don't think you would end up wanting the compiler to help you with this. You'd introduce some sort of 'refcounted pointer' type, maybe called Rc<T>, which wraps a T* + a deallocator. I can't imagine C# ever letting you overload the -> operator though so the ergonomics would be bad.
I ran across this link-hopping through GitHub repos after reading the article. Its x64 but might be closer to what you were hoping for.
I have a hard time imagining possible practicality from going lower level than that, it's really wild west.