Programming thread

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.
In my case, the program was designed to take a list of files in argv and work with them. But because of how C works, I can just leave all that data in the original argv array. Need string lengths? Iterate across argv subtracting the two pointers. This will break should argv be non-contiguous. This is not guaranteed by spec, but I haven't found a case where it breaks. And this is what it feels like to code in C: you come face to face with the difference between spec and reality. Because the project is hardly mission critical, ship it. When you can test and verify absolutely that this does not break on all the cases that you're responsible for, and you've documented the potential for breakage, and heavens, even added checking code to validate your assumption, is a different solution called for? Of course not. Is it "bad code"? Well, bad for what? Bad for other coders, sure. But it works, it's tight, and it wasn't hard to debug or reason about.
Yeah, this is mega-dumb. The time you save is going to be dwarfed by the time that you, or someone else, spends debugging this when it inevitably goes tits-up. Just do a strlen, it's not expensive.
 
Anyway, it's just a minor gripe. Mostly I just hate having a decent discussion only for some twentysomething to show up and start blathering about how C++ is going to kill my dog.
:agree::agree::agree:

I think I expressed something similar in Saddam's "How to learn programming" thread. Everything is becoming overspecialized to the point where only a select few losers in universities can effectively reason about such things. Now the keys to mankind have been given to people like the economists who said we wouldn't have inflation right now. I sense a big push for the masses to see most programming beyond simple JS Electron shit as some dark art, best left to professors and neckbearded engineers in their 60s. I'm confident there is a more insidious motive behind the push for mass ignorance, but I'm also confident an element of it is the sense of elitism the few who learn the advanced topics get to feel. It was such elitism that had me going on long exhausted tirades about the importance of good educators and educational resources in that thread.

I'm glad I'm out of academia, but I do miss teaching.

Yeah, this is mega-dumb. The time you save is going to be dwarfed by the time that you, or someone else, spends debugging this when it inevitably goes tits-up. Just do a strlen, it's not expensive.
lol I'm pretty sure strlen is just a for/while loop that runs over the char array until reaching a null terminator anyway. The most efficient and reliably safe strlen is going to be O(n). Stuff like memcpy and strcpy are similar, but memcpy does cool tricks with the size of primitives.

C without the null terminator simply wouldn't work. All hail the null byte.
 
Last edited:
Here we see a sufferer of Microsoft Stockholm Syndrome. Prolonged exposure to Microsoft's broken garbage APIs has warped this man's sense of taste to the point where he sees "calculate C string lengths" and reaches for a hack that only works through a flaky undocumented implementation detail despite the fact that lens[i] = strlen(argv[i]); is easier to read, easier to write, idiomatic, and guaranteed to be correct. And he likes it.

Microsoft: Not Even Once.
Missing the rhetorical point here. Literally trying to trawl my codebase for examples that don't self-dox. Ended up synthesizing something that was close to what I did that was close enough to make the point. You got me. Yes, this is poorly idiomatic and full of potential foot-guns. But the other details I included aren't. And what's more, a working solution that checks the validity of the assumptions you begin with is, at minimum, provably correct.

The point is just that the more you understand about what the computer is doing, the less you need to worry about what the exact implementation is, and the more readily you can reason your way through something lower-level. An empirically-proven and self-testing solution will always work. Barring concerns about code reuse (which are a non-issue as I'm the only one who will ever look at the code; otherwise you're absolutely correct to raise the alarum), this is how the most mature codebases work. You have code that works. You have code that tests the assumptions of the code that works. You have a developer who is informed enough about the intricacies of what the code does that he needs not depend on API details.

Everything is becoming overspecialized to the point where only a select few losers in universities can effectively reason about such things. Now the keys to mankind have been given to people like the economists who said we wouldn't have inflation right now.

And this partly is why I'm trying to make my point. Here is what the institutions are teaching: Instead of accepting an empirically-proven codebase that documents its presuppositions, let someone else's "idiomatic" code do the job. (I'm harping on "idiomatic" here simply for contrast. I'm sure there are other trends I could pick out. I'm not meaning to be adversarial here.)

So, ought software development to follow empirical scientific methodologies, or ought it to follow the traditions of men? The economists and inflation example is great, as it has a direct parallel in the discourse between the few (empirical) Austrian economists, who have been screaming that the economic degeneracies of the Keynesians are going to cause inflation, and the (now-traditional) Keynesians who insist that governments can print money without negative repercussions.
 
Last edited:
Missing the rhetorical point here. Literally trying to trawl my codebase for examples that don't self-dox. Ended up synthesizing something that was close to what I did that was close enough to make the point. You got me. Yes, this is poorly idiomatic and full of potential foot-guns. But the other details I included aren't. And what's more, a working solution that checks the validity of the assumptions you begin with is, at minimum, provably correct.

The point is just that the more you understand about what the computer is doing, the less you need to worry about what the exact implementation is, and the more readily you can reason your way through something lower-level. An empirically-proven and self-testing solution will always work.
I have no idea what your rhetorical point is, honestly. In your example, the self-test would basically involve doing it right, and then using the more cumbersome wrong implementation anyway. From experience, I expect this to be the case pretty often. Even if the test + wrong impl are sufficiently easier than a correct impl to make going for it worth it somehow, relying on cute coincidences like this requires you to worry more about the exact implementation if anything, simply by virtue of your code going tits up if the implementation ever changes out from under you. To stick with the example, handling argv properly will work on any conforming C implementation, and how argv is implemented is of absolutely no concern.

lol I'm pretty sure strlen is just a for/while loop that runs over the char array until reaching a null terminator anyway. The most efficient and reliably safe strlen is going to be O(n). Stuff like memcpy and strcpy are similar, but memcpy does cool tricks with the size of primitives.
A C implementation can use similar tricks for strlen and strcpy. Assure that all allocations are aligned to some multiple of e.g. 8 bytes, check the alignment of your input pointers, and then access and check for null bytes in multiples of 8 bytes, which can't segfault by the first point.
 
A C implementation can use similar tricks for strlen and strcpy. Assure that all allocations are aligned to some multiple of e.g. 8 bytes, check the alignment of your input pointers, and then access and check for null bytes in multiples of 8 bytes, which can't segfault by the first point.
Plus you can do various tricks involving SSE etc.

I think it's an important skill for a competent C programmer to at least have a rough idea of what the specs allow, and what's undefined behaviour, unspecified behaviour, platform-specific behaviour, implementation-defined behaviour, and so on. I'd only ever rely on implementation-defined behaviour if it's a bottleneck, and even then it would have a hefty /* HERE THERE BE DRAGONS */ comment above it.
 
As someone who have basic knowledge in python but still want to become better, does coursera offer good vaule?
They have some python courses and machine learning.
 
As someone who have basic knowledge in python but still want to become better, does coursera offer good vaule?
They have some python courses and machine learning.
If you have basic knowledge already, maybe you should try making some simple real projects of your own. Courses are good for showing you the ropes but the majority of your real knowledge of programming will come from getting over problems in your own codebase, working on your own problems.
 
Thanks for the advise.
I will keep thinking about some projects I can do.
 
The funny thing is, it used to be even worse:
1708813548504.png
(archive.org)
If you show the average user where they would get the .EXE in this screenshot absolutely all of them would assume it's the "Download ZIP" button, when in fact it's that inconspicuous "36 Releases" tab. Later on they renamed the button to "Clone or Download" and made it bright green, which didn't help at all. It took years of idiots opening useless issues because they didn't find where to download the actual binaries before we finally ended up with the current UI:
1708813863260.png
The releases are still a bit hard to find but at the very least it's now really clear what that green button does. And it only took being acquired by a trillion dollar company and a couple of years of trial and error.
 
BSP is probably the place to start. Doom-era tech. https://en.wikipedia.org/wiki/Binary_space_partitioning

Not familiar enough with the tech you're using and the approach in general to specify more. There are Rust crates that do BSP pathfinding, allegedly.
I was thinking more in the direction of octrees, but still exploring various options. It's for navigation and dynamic obstacle avoidance in 3D space.
 
  • Like
Reactions: Neo-Nazi Rich Evans
The releases are still a bit hard to find but at the very least it's now really clear what that green button does.
In an ideal world that button would take you to the latest stable release.

Every developer knows how to clone a git repo. End users who land on your github page via google are the ones who need an obvious shiny button to click.
 
  • Agree
Reactions: Nitro! and y a t s
A really interesting read that I come back to every so often is Andy Gavin's blog on the development of Crash Bandicoot. They did some crazy stuff technically to pull it off.
God, I've been doing some kernel dev.

I've been updating some old 5.X ethernet drivers to work with 6.X interfaces. The lack of documentation and the sloppy bullshit I'm seeing is horrifying. The drivers... work... I think. I just hope I haven't truncated any important features of my cards.
 
Back