Re:Memzoom – view/monitor the raw memory of processes/files ...
by eatonphil on Tuesday July 05, 2022 @07:43PM
(#31995115)
First off, Justine is a better programmer than I. But, and I don't mean this as a humblebrag, the use of all global variables for state makes me uncomfortable. If this is good C code (not saying it isn't) then maybe that's why I'm not a C programmer. Whatever the case, Justine is great.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by jart on Tuesday July 05, 2022 @08:15PM
(#31995320)
That's a good instinct to have. 99% of the time we're writing something like an object library that's part of a much larger program. To use global variables in such code would impose difficulties on the application as a whole, with regard to things like threading, pollution of the linker symbol table, etc. But when you're writing small main.c programs like this one which don't use threads, globals can be a real advantage. In gdb, you can easy inspect their values. You can look at the linker output manifest listing to see how they're being arranged in your binary. If you look at a lot of the old original UNIX programs that were written back in the day, a lot of them looked very similar to this. So it's a great style. It's just not one that scales to large monolithic programs that most companies prefer to create. So over the years a cultural aversion to it was developed in many style guides.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by dekhn on Wednesday July 06, 2022 @11:29AM
(#32002409)
I typically split any single main.c app into two parts: a library which depends on no shared State and a driver program that wraps around it. It's a lot harder to build than a monolithic main.c but in my experience it allows more people to build off of your application.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by charcircuit on Tuesday July 05, 2022 @11:36PM
(#31996402)
>If you look at a lot of the old original UNIX programs that were written back in the day, a lot of them looked very similar to this. So it's a great style.
The original UNIX programs weren't known for good style or being big free
Re:Memzoom – view/monitor the raw memory of processes/files ...
by jart on Tuesday July 05, 2022 @11:46PM
(#31996459)
Then why is everything based on UNIX then? (Or at least fated to be, via WSL.) If you want a real jewel, check out the v6 rand() function. It's an example of a function so bad that world-class experts on the subject of randomness have been falling over themselves for decades in academic papers talking about how to fix it.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by donut on Wednesday July 06, 2022 @03:03AM
(#31997692)
I'm reminded of the thesis that worse is better:
https://www.dreamsongs.com/WorseIsBetter.html
:-)
Re:Memzoom – view/monitor the raw memory of processes/files ...
by charcircuit on Wednesday July 06, 2022 @04:38AM
(#31998312)
>Then why is everything based on UNIX then?
It's not based off UNIX's code. UNIX based system's popularity can essentially be attributed to network effects. For most use cases it's good enough that it's not worth switching to something better because you lose the mountain of resources (both technological and human) that exist in the UNIX ecosystem.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by charcircuit on Wednesday July 06, 2022 @04:32AM
(#31998272)
bug free
Re:Memzoom – view/monitor the raw memory of processes/files ...
by elteto on Tuesday July 05, 2022 @08:47PM
(#31995533)
The "rule" that I've sort of figured out from reading old C code is that global state in the file that contains main() is ok.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by marcodiego on Wednesday July 06, 2022 @10:01AM
(#32001036)
For a well written code that is less than 1000 lines in a single file using very few abstractions, that number of global variables is not a problem.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by chris1993 on Tuesday July 05, 2022 @06:14PM
(#31994425)
It's a work of beautiful clarity
Re:Memzoom – view/monitor the raw memory of processes/files ...
by mcdonje on Tuesday July 05, 2022 @04:20PM
(#31993187)
Really digging the retro vibe of the code, man.
Re:Memzoom – view/monitor the raw memory of processes/files ...
by naikrovek on Tuesday July 05, 2022 @05:22PM
(#31993875)
if you mean the straight-forward nature of the code, I agree.
I think we over-complicate code today because we are promised ease of maintenance, or high-level declaration, or something else, and I don't think those promises have ever come true, except in very small textbook-type examples.
Feels really old school. Looks like something from people used to write DOS programs.