1227 points · by elvis70 · 3y ago · 323 comments
Justine’s APE [0] project is one of the few things to induce in me true, nostalgic, nerdful glee in the last few years.
For the uniformed
Older C compilers will let you get away with a lot of sins which a modern C compiler will (correctly) call you out for.
Under some very old C standards, maybe. But C99 requires that you at least declare a function before calling it.
if(*(Ptr = argv[i]) == '-') {
Older C compilers did let you get away with more, like using integers as pointers, and dereferencing pointers as though they were struct pointers when they aren't. But I don't see that in this code.In older C compilers (maybe pre-ANSI, or later, can't remember), you could literally write i[a] instead of a[i], where a was an array and i was an int, and it would work equivalently, i.e. no compiler error, and give the same result as a[i]. This was because a was the address of the start of the array, and i was an offset, so a[i] actually meant *(a + i), which, by the commutative property of arithmetic, was equivalent to *(i + a), which was equivalent to i[a].
I had read this in some C book, maybe K&R or the Waite Group C Microsoft Bible.
Never forgot it, because it was counter-intuitive, unless you knew the above reason.
And tried it out in one or more C compilers at that approximate period, and it worked as stated.
Cargo pulled in something like 105 dependencies to build it.
Although, as an apples to apples comparison, it does only have 2 use statements.
Here is a http health check in 19 lines using only the rust standard library.
There’s a happy medium to be had.
I’d also disagree this is not at all a language problem - I think it’s both, in that the language has moved an awful lot of core functionality into the crate ecosystem, where there are a bewildering array of options for almost any need. The resulting explosion in the dependency graph is an entirely foreseeable consequence — partially of that language design decision and partially due to the “npm culture” (for lack of a better description.)
The list goes on. While I'm not a Rust developer, there's probably hundreds of libraries because the problem is structured into a lot of small parts, and frameworks are expected to be able to satisfy the functionality you expect without needing to bypass it.
- True=7 -
Having lots of very low-level code and hardware experience, I developed a bit
of tendancy to "minimize what can go wrong at low levels" - C treats 0==FALSE
and !0==TRUE - most people use 0/1 ... but thats only 1 bit "difference". I
sometimes use 7=TRUE as thats 3 bits with no more chars to type (and of course
foolish as such a 1 bit hardware error would "trash" pretty much any system -
but I do tend to be a creature of habit :)
I have never heard of this convention before! Was "random bitflips messing with your conditionals" a common problem back in the day?Or will you assume that one of the branches is safe to execute during failure?
Or will you count the number of bits in each conditional and assume more ones than zeroes is a true, with no error correction? Will you log that a bit has flipped or otherwise alert the operator? Will you consider that as evidence that an int has changed value too?
Will you store ints with three bits per bits also?
Error detecting codes have their place, but it takes more than just saying that true is 7.
Learning hardware just for the sake of it is tough to keep motivated and perhaps you would never use the skills you learn? Hardware adds a tougher level to debugging - but software experience gives you a fantastic start - a logical mind and rational drilling down.
If you can fix your car you have the skills to start on electronics!
A lot of skilled people grew up through the hardware generations e.g. I began learning basic electronics because on an Apple ][ everything was simpler and we were all at the same stage. My first job was writing low level serial driver code and regularly dealing with serial devices (e.g. on PC). Our modern context is just not the same. The internet is hard to learn from. It is difficult to write good articles to help - the experienced like me just know a huge variety of implicitly learned knowledge.
I suggest you concentrate on a useful or fun outcome - I believe it's good life practice (and good engineering) to stay focused on the outcome and not get too side-tracked by explicitly trying to learn. We implicitly learn just by doing!
i was sending pixel data out from an Arduino (ESP32 really but using Arduino IDE) to a bunch of shift registers that seemed to be 74x595 (but couldnt know for sure) to resurrect an LED display for a local art project, and reading the data coming back out from the last register let me know I was at least getting back what I was putting in, which helped me troubleshoot a few wire length and speed/stability issues
to get started with electronics and hardware in general, I wrote a short tutorial: https://news.ycombinator.com/item?id=35116705
if (var == TRUE)
; // It was 7
else if (var == FALSE)
; // it was zero
else
??? what do I do here?
And you need to solve that "what do I do here" for every single conditional on a boolean, and have the extra lines of code to handle it and not crash.But, you know, what if it was a variable that you used in a switch statement instead? Or just "if (i > 17)"? Bit flips can affect your logic all over the place, not just when it's a boolean variable.
And then, if a bit flip can affect a boolean, it can also affect a pointer. Or the return address on the stack (or the link to the previous stack frame).
Or it can flip a bit in the code.
So this is, at best, a very very partial solution, and it's non-trivial to implement. So this was very much not standard practice or a "convention".
Any team that realizes that the compiler may choose to optimize out a shit-ton of such code gets an extra gold star.
#define FALSE 0
#define TRUE (!FALSE)
ASSERT( TRUE != FALSE );
and let the compiler worry about which bits to use for TRUE
Until you added the 2nd test and the 2nd else case, there is no scenario under which both paths of an if/else would fail to execute due to a bit flip of the test variable, because with ‘if (boolean_condition) {} else {}’ there is only 1 conditional test. A bit flip could have caused the wrong branch to execute, but it could not have skipped both branches. A bit flip could change the jump instruction to something else, but in that case your imagined else case still wouldn’t help.
> this is, at best, a very very partial solution
FWIW, the author said this, and fairly succinctly, saying this TRUE=7 thing is “of course foolish as such a 1 bit hardware error would "trash" pretty much any system”. He was only having a bit of fun that cost nothing, and nowhere suggested this is a solution to cosmic rays or other data errors.
It meant that you didn't need the distinction of "logical operators" (like && in C) and "bitwise operators" (like & in C). You could just use bitwise operators, e.g. the bitwise NOT operator would convert 0 (all bits clear) was -1 (all bits set) so there was no need for "logical operators".
I always felt that was more elegant than C (but of course required a two's compliment machine, which BBC/Archimedes was, but C didn't require).
This implies that old hardware always worked, which I strongly doubt (what year did hardware go from always working to not?).
Of course, trying to work around it in software is utterly futile.
I thought they (from cosmic rays, etc.) were always a thing, but so rare that you needed a very large system (in scope or time or both) to have a substantial chance of encountering one (outside of noisy comm channels, which use error correction protocols for exactly that reason.)
https://en.wikipedia.org/wiki/Qantas_Flight_72#Conclusion
Cosmic rays were suspected but unconfirmed (kind of hard to confirm after the fact).
"All the aircaft in the world" for sixty years is kind of a large system given that currently there are on the order of one million people in the air at any moment.
Bits flipping due to hardware that didn’t work well was what caused Xerox PARC to implement an error correcting memory for MAXC, fifty years ago.
> Bit flips due to buggy software was a thing though.
No kidding.
https://learn.microsoft.com/en-us/dotnet/visual-basic/langua...
Edit: "Gained" no "Earned"
Unless you can stop cosmic rays.
Luckily it doesn't happen THAT often. I forget the exact metric but I recall various Google Engineers saying that something like one out of a million test run failures is a random bitflip?
Also, you can definitely stop cosmic rays, that was part of how they eliminated them as the source.
As I understand it, bit flipping in RAM is mitigated by error correction, via auxilliary and redundant bits.
https://en.wikipedia.org/wiki/Dynamic_random-access_memory#R...
Due to RAM/CPU failures? I don't think so (though I have seen it, fwiw). With weird serial protocols that don't have proper checksums/digests, running over sketchy wiring? Yeah, and that might be part of "very low-level code and hardware experience".
If 7 == true and anything other than 7 == false, then one bitflip will still change the meaning. If 7 == true and 0 == false, then you could have code that does `if (mybool == 7) { ... }` and later `if (mybool == 0) { ... }` and end up with a situation where code path invariants are broken (i.e. mybool is neither true nor false.
If you use `>= 7` to mean true and `< 7` to mean false, while a 0 false value won't randomly become true if one of 3 bits randomly flips, a `7` true value will become false if any of those bits flip. And if any of the other bits flip, 0 will become > 7.
Logical nots would then work.
And youre still an inc/Dec away from the opposite.
a) Two's complement representation
and
b) Wraparound on arithmetic, which is still UB in low-level languages.
Not doesn't rely on wrap around arithmetic.
Wrap around arithmetic is only undefined for signed values.
What platform doesn't wrap around signed integers?
Just because c has some undefined behaviour, doesn't make it some natural law of the universe.
Take good care of your code kids!
Got really depressed by it at the time, as it included most of the projects I worked on at the time. After that I got super paranoid about having backups.
I do enjoy going back and looking at the code I still have though. Being self-taught it's mostly not terribly great, but I do have fond memories of finally cracking a certain nut or figuring out some neat trick.
Many a person has had to learn it the hard way.
He is still alive today, he has a normal life and he even manages to go for a run in the beach every saturday. His exams haven't improved, he is always out of breath, but he just refuses to die. It's like what the physician said in the link above: "You look a lot better than what's in the paper".
Anyone know why doctors do this? They did the same thing with my father when he wasn't getting better (leukemia with pneumonia) and they couldn't get him off the breathing tube. They were very adamant he'd be disabled for life.
Still, if something happens to me or loved ones I hope I get doctors who can distinguish between zero and one in a thousand.
We hear a lot about all the times they're wrong, because they're tragic or frustrating or confusing, and because biology is super non-deterministic they're probably wrong more often than say physicists, but they're also right a lot of the time too, enough of the time that we consider it worth having them. We just don't get as many articles and anecdotes about a doctor correctly predicting someone's disability, because it's not as interesting.
This is a bit like receiving an inheritance from your grandparents. There will be true gems and novelties mixed in with a lot of knick knacks and rubbish. But the totality of that tells a story of real people living rich and interesting lives that only a handful of highlights would not do justice to.
There's a vibrant retrocomputing community.
Today’s trendy development practices are shockingly ephemeral and fragile. Very little of today’s projects would survive one decade left fallow, let alone four.
A few years ago we tried to rebuild some safety critical code from sometime back and were unable to because the certificates had expired and so the machine that can build the source code refused to connect to our version control system.
It takes a lot more effort to package stuff, since you can't just download your dependencies from the internet. But you also create something that isn't as ephemeral.
My fellow human, you have just nailed what is wrong with today's software.
go makes this extremely easy to do
https://go.dev/ref/mod#go-mod-vendor
rust tool chain also includes a vendor dependency process
> Very little of today’s projects would survive one decade left fallow, let alone four.
I hate to break it to you. 2040 is less than half as distant as you think it is.Thinking about the "dependency tree" for any modern convenience is truly staggering. I can't even start to think about how you can make a factory without first having a factory.
They already are, if something has been hijacked and is now malicious.
They already are, if you need to install something offline somewhere.
They already are.
But languages like go and rust have had the ability to “vendor dependencies” for awhile now.
Don’t need an active internet connection. Just need to have the toolchain.
Much of the old software found on bitsavers.org (and archive.org) was recovered using this utility.
You've made a contribution to the hoard that someone will benefit from, whether tomorrow or in 5,000 years.
----
One last bugfix before retirement (this is a joke):
I wanted to look at micro-cad it generates a 404.
URL: https://dunfield.themindfactory.com/dnld/sc/MICROCAD.ZIP Expected: I can download the .zip file.
Looking through some of these though, I think I'm inspired. Super cool idea, I would donate to the retirement project financially to say thanks if possible.
And what are the organizing processes you learned; I’m always eager to learn productivity tips/software from others
[1] https://archive.org/details/Programmers_Heaven_InfoMagic_Mar...
# we require more vespene gas; unix consensus; kNtErrorOutofmemory;
And slyly tells you the “password” to get past his spam filter
[It might be more a ShowHN if you are?]
I'm interested if all of the code is self-written? If you wrote any of it under contract and so had special terms to allow you to eventually release it? Which piece of code there that you are most proud of and/or gonna most useful?
If you're the author, please please release into the public domain (CC0) if your purpose is educational. That makes it so anyone can learn from it and build on it without any fear of infringement.
Man how far people are brainwashed.
Curious as to why you consider that a bad thing.
Its UI for presenting large number of software projects sucks, too.
The presence of use restrictions does also disqualify it from being Open Source (OSI trademark) or Free Software (GNU/FSF).
If a standard license was adopted instead, such as MIT (permissive and I believe well-aligned with the intent of the author), then any concern would go away.
> This file is NOT included in the demo version of this product.
> For more information, please contact Dunfield Development Systems
I admire the effort, but if you're not going to make the source freely available, what's the point? What is somebody going to do 100 years from now when they get your .zip off archive.org and you're long gone?
The author seems quite aware of this. He calls it out specifically: it's for learning and curiosity purposes.
Confusion on your part regarding what the other commenter's complaint is. The complaint is that the source code archive they downloaded did not contain the source code. It contained an old copy of a shareware notice instructing the reader to write to Dunfield for access to the source.
Confusion on Dunfield's part: specifically, the belief that he had included the correct version of RINGSW.C when republishing this stuff to celebrate his retirement.
Finally, confusion on the part of the other commenter here, involving an assumption that Dunfield's oversight was a deliberate decision.
> my goal now is to release 40+ years of source code
And there was no code in the .zip. Shrug.
(I do regret giving too much of my time to free projects, yet have found a satisfying balance by including source with purchases of software I sell.)
Otherwise AI will be the end of anything open - which we can already see in stackoverflow now.
I share what I do freely. If someone integrates that trivia and shares it with someone else, so much the better. I offer a fractional shoulder to stand on. Getting hovered up into an AI that then goes on to help someone else isn’t much different than having something random posted on the internet that solves someone else’s stumbling block.
But that’s just me.
Is there no such thing as "done" anymore?
It does not.
> Is there no such thing as "done" anymore?
Is there no such thing as "building upon it" anymore?
I wonder if the code manages be so clean because it's only aimed at a single compiler and a single platform. Multi-platform C code tends to be messy with preprocessor goo.
if it was on GitHub, and it made it to the HN front page, "tomorrow everyone forgets about it" would still apply.