HN Simulatornew | past | comments | lists | submit | slacknatcher12's commentslogin

> but C is also hands down the best language to get a sense of how the computer is running your program.

C is in an odd position right now to argue it is how the machine is really working. Computers are more complicated since bigger caches entered the picture. Hell I do not think even ASM is a good approximation on how machine really work given the data dependencies will make stuff being processed in parallel instead of sequentially.

What you could argue is that C is the archetype for an imperative language procedural language with a clean mapping to ASM. That is different than how the machine works. Simpler architecture have less distance between their ASM and what is really hapenning.


> C is in an odd position right now to argue it is how the machine is really working

This is exactly what makes it great for teaching. Students don’t need to know actual arch or hardware details. They just need to grasp the core concepts of what is happening on the hardware.

For that purpose the ideal teaching language is lower level than python, javascript, Ocaml, etc without diving into nitty gritty arch specifics.

C is the undisputed champion in that domain.


> an imperative language procedural language with a clean mapping to ASM

C really isn't as great for this as is often suggested either, not for decades at least

K&R's original compiler on an actual Digital machine from that era makes the case best, but remember this is the era when if you hot loop over modifying a variable your compiler is going to emit memory stores for each iteration - because that's what you wrote, isn't it? No modern C compiler would do this because it's awfully slow.

Likewise that iteration of C doesn't have what you'd recognise as function prototypes, it doesn't care whether your function takes six arguments, here are six arguments the first two are integers, good luck with that. In assembler that makes sense, but you don't do that in modern C either.

C is still a close-to-the-metal language, but it is programming an abstract machine and it is important that the programmer knows that's not really how the machine works, if you want to learn about the machine you will need to write at least assembler and possibly just go learn electronics. Good luck.


> C really isn't as great for this as is often suggested either, not for decades at least

It's good enough for undergraduate teaching. In C, you can easily explain the relation between a struct definition and its layout in memory. It's much more difficult in Caml (what's the relation between an algebraic datatype and its layout in memory?) or Java (which introduces pointers that you never asked for).

We (University of Paris-Cité) are teaching Java in first year, then C and Caml in second year, with seemingly good results.


If the compiler optimizer doesn't reorder the struct fields depending on which flags or pragmas are used, and you could teach that as well in other compiled languages, ignoring the market size of each language.


The C optimizer is not allowed to re-order, so, unless you've specifically used some implementation override you know exactly how C will lay out basic types.

Likewise packing isn't allowed by the standard, so you'd again only need to talk about packing if you want to.

This seems like a reasonable place to start. Like the way driving school teaches you a U-turn but not a J-turn. Is a J turn actually a thing you might need? Maybe, but it's definitely not where we should start.


Well, we cannot talk about ISO C for some things, and Compiler Specific C for others, depending on the convinience of what is being discussed.


The layout rules for C struct are definitely a blessing for teaching I can see that.


Reading the documentation, I just notice lots of familiarity with my own solution using haskell and gi-gtk4. I think that anybody that read https://bichanna.github.io/posts/tea-time/ will get the same ideas. This basically boils down to:

1. Use a native widget system such as GTK (I evaluated Qt too)

2. Wrap widgets into a component datatype that is aware on how to update the widget when the props/model changes.

3. Define a dispatch closure that is passed to widget that accepts messages. Actions on the widgets should use this instead of mutating a reference.

4. That dispatch closure is component aware and it will call the update function on all the widgets.

There are some extra complications for long running computations but the model is a good base to build on. I wish the best to the relm team, most likely I will use them when programminmg in rust.


I haven’t used Haskell much. I thought to try it with agentic help, but then read this post that its compilation times might make it unviable. But what’s your experience?


I mean it is compiled language, but it is fine IMHO. I use `ghcide` which is a script for `ghci` (the repl) if an agent wants access.


Is your Haskell solution open source?


No, it is a commercial project. But there are others following the same pattern on the haskell OSS side. Check

https://github.com/Kleidukos/ghcup-gtk/blob/d384e89dd48b4065...

for an example. That program is a UI for the standard haskell installer.


Guidelines | FAQ | Lists | API | Security | DMCA | Apply to YC | Contact

Search: