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.
Anything related to game development (Shaders, physics, yada yada) I got the C language book but I can't manage to get an enviorment running to process my code...
If you want to make video games you can do the same as what I'm doing. Im learning C# though, not C.

I'll still give you a step by step real quick because it was a pain in the ass for me setting it all up.


Install the microsoft .Net SDK for C#.
Install Visual Studio, during installation it will ask you to pick which specific things you would like installed. I forget which specific options I clicked but there is tools specifically for .net C#, as well as C and C++.

Install VS Code, or any code editor of your choice.
Install Godot with C# support. You can find it on their website, its free and its just a zip file.

And then you can open up editor settings in godot and set it up to connect to VS code so you have a more robust coding editor than the one Godot comes with out of the box.
 
I legitimately don't remember when I last had to think about calling conventions in C despite using it daily for years.
If you're programming for 32-bit Windows you need to at least make a mental note of __stdcall vs __cdecl and remember who's expecting which (and what your default is).
My favorite (unfavorite) is how the Microsoft CRT has both cdecl and stdcall "create thread" functions :sighduck:
There are a lot less x86 stragglers these days though, now that Windows, Office, Visual Studio, and all the rest default to x64 - where everyone just uses the same calling convention.
 
No one sane gives a fuck about how much memory a program uses unless it's noticeably bad. They care about whether the program works or not. I wanted to give a story from The UNIX-HATERS Handbook about someone who wrote an optimized but incorrect program that wasted more time than it could possibly save, but I can't find it.
This philosophy folks, is why we have a software quality crisis. Microsoft teams "works", Spotify desktop app "works". Discord desktop app "works" . All it takes is a quick google search to find average users complaining about them becoming unacceptably slow with ridiculous memory usage.

As for the anecdote about the optimized but incorrect program. I would never be an advocate for over optimizing a program considering the fact you can slow down a program by forcing inlines causing the binary to be bigger having and when loaded will span over additional page boundaries.

I'm simply talking about for programming in a professional setting having an awareness of these fundamental comp sci concepts allows you subconsciously and naturally write better code in the first place.

It's still not true, then.
Oh come on. Now you are being a revisionist. There's an entire c family tree.
This is a mathematical topic above all else.
Disagree, solving problems recursively vs iteratively is a programmer's decision
Where are those in Forth?
Sorry, my mistake. Let's check how many Forth devs there are:
stackoverflow-dev-survey-2024-technology-most-popular-technologies-language-social.png

Forth bros... is it over?

char *str = "bugy";
Interesting snippet here. "bugy\0" will actually not be allocated on stack at all but simply point to the strings location in the binary hence why you should never overwrite any of the characters.

So now we're talking about strings. I actually dislike c strings. They should be
C:
struct String {

    size_t maxLength;

    size_t Length;

    char*  Buffer;
  
};

Much less error prone as now we don't have to worry about the existence of the null terminator and we get additional context of how big the string buffer actually is.

As for validating input as an example, user input should always be never trusted and sanitized - SQL injection anyone?. But you can simply truncate the supplied input at the size of your buffer - strncpy and co - not to mention there are stack canaries to ensure that the stack hasn't been clobbered to manipulate return addresses etc.

Unironically, why does array indexing need to be more complicated than pointer arithmetic? You have a defined amount of contiguous memory known to you, if you decide to index above the variable or constant that allocated your array with then that's your own stupid fault.
 
Last edited:
...on Windows. It's still a different convention used by the rest of the world, for reasons that were never really apparent.
The price they pay for their amazing backwards compatibility. At some point in the past Windows decided to make a good amount of it's API calls use that specific call convention, millions of binaries and libraries were compiled to use that call convention when calling the API, changing it now will completely break all of them.
 
The price they pay for their amazing backwards compatibility. At some point in the past Windows decided to make a good amount of it's API calls use that specific call convention, millions of binaries and libraries were compiled to use that call convention when calling the API, changing it now will completely break all of them.
No, they just fucked up when designing the amd64 Windows ABI. They ignored that AMD had already declared an official calling convention, to avoid the mess that was x86.
 
I actually dislike c strings. They should be
Well, your example has 16 bytes of overhead per string on x64 (to continue a theme). If we had actually gotten this back when C was being designed we probably would have ended up with Pascal-style strings with  one length byte and a maximum length of 255.

Of course, a C++ std::string will be that large or larger, so it's hardly unthinkable today.

Speaking of string nonsense: Microsoft BSTRs are prefixed with a 4-byte length (even on x64), but does anyone remember a predecessor that had only 2 bytes and was limited to 64K length? Maybe "OLE strings" or something. I could swear there was something like that but I can't find any references offhand.
 
You have a defined amount of contiguous memory known to you, if you decide to index above the variable or constant that allocated your array with then that's your own stupid fault.
Damn, it was that easy all along. All we had to do was always use the correct index, how did nobody think of this before?
 
Well, your example has 16 bytes of overhead per string on x64 (to continue a theme). If we had actually gotten this back when C was being designed we probably would have ended up with Pascal-style strings with  one length byte and a maximum length of 255.
Yes, that is true (although you do save a single character by not needing a null terminator).

Although there's nothing stopping you from recycling your buffers though and through other good practices easily offsetting the extra cost.
 
I can give specific recommendations if you tell me what you want to achieve with coding.
Not your re:user but
I want to make a visual novel / choose your own adventure thing with various fun graphical presentations for the text (landscape scene + text box, character portraits, scrolling text over landscape) without wresting with Ren'Py's gay sexdoll shit. No physics.

Aspirational art quality:
jesus-campos-nerkin-the-last-blade-mockup-grande-artstation.jpg
Expected art quality:
rabenstein.jpg
7268249-darklands-dos.png
(but hopefully less buggy)

The Linux build of an empty Ren'Py project is 60 MB unzipped (no art, no music).
Anvil of Dawn (a complete DOS RPG from 1995, with music) is 60 MB without the few cutscenes.
Bloodstained Curse of the Moon, the whole game, is 20 MB installed.

I've seen impressive-looking Ren'Py games. However, on peddit, whenever someone asks how to do something that should be easy, the proposed solution is usually stupid and gay. Doing something genuinely cool in Ren'Py is probably more effort than doing it from scratch, definitely less broadly applicable, significantly less illuminating to learn, and will turn into a pumpkin come next major release.
 
Not your re:user but
I want to make a visual novel / choose your own adventure thing with various fun graphical presentations for the text (landscape scene + text box, character portraits, scrolling text over landscape) without wresting with Ren'Py's gay sexdoll shit. No physics.

Aspirational art quality:
View attachment 6564779
Expected art quality:
View attachment 6564893
View attachment 6564803
(but hopefully less buggy)

The Linux build of an empty Ren'Py project is 60 MB unzipped (no art, no music).
Anvil of Dawn (a complete DOS RPG from 1995, with music) is 60 MB without the few cutscenes.
Bloodstained Curse of the Moon, the whole game, is 20 MB installed.

I've seen impressive-looking Ren'Py games. However, on peddit, whenever someone asks how to do something that should be easy, the proposed solution is usually stupid and gay. Doing something genuinely cool in Ren'Py is probably more effort than doing it from scratch, definitely less broadly applicable, significantly less illuminating to learn, and will turn into a pumpkin come next major release.
Try the Game dev thread , but from scratch I would go with sdl2 for c/c++
 
So now we're talking about strings. I actually dislike c strings. They should be
You know what would be better? Something like this in C:
C:
// Of course this is not valid C as you may have noticed.
struct Array<T> {
    size_t length;
    T* data;
};
But since in C there is no support for C++ style generics, you are forced to do this for a generic array data structure.
C:
struct Array {
    size_t length;
    void* data;
};
You might have noticed that this structure has a fatal flaw: it uses a void pointer which still requires runtime casting when dereferencing it, which is very error prone.
 
Godot has a built in animation player and I kept trying to write a script so it loads all of the frames of the animations on startup and it wasnt fucking working so I coded up the animations from scratch and its dynamic. All you have to do is plug in sprite sheets and coordinates and it handles almost everything else automatically.

I was able to make a sprite I ripped from fallout 2 walk around with wasd keys and run when you hold shift and it works exactly as I intended.

I wonder if that is something worth showing to employers.
 
  • Like
Reactions: Vecr and Marvin
You know what would be better? Something like this in C:
C:
// Of course this is not valid C as you may have noticed.
struct Array<T> {
    size_t length;
    T* data;
};
But since in C there is no support for C++ style generics, you are forced to do this for a generic array data structure.
C:
struct Array {
    size_t length;
    void* data;
};
You might have noticed that this structure has a fatal flaw: it uses a void pointer which still requires runtime casting when dereferencing it, which is very error prone.
ITT we reinvent std::string_view and std::span
 
Godot has a built in animation player and I kept trying to write a script so it loads all of the frames of the animations on startup and it wasnt fucking working so I coded up the animations from scratch and its dynamic. All you have to do is plug in sprite sheets and coordinates and it handles almost everything else automatically.

I was able to make a sprite I ripped from fallout 2 walk around with wasd keys and run when you hold shift and it works exactly as I intended.

I wonder if that is something worth showing to employers.
Spriting is the worst thing in the world. I've abandoned projects with fully functional engines I coded myself from scratch because I got to the spriting stage and was like "fuck this, I hate it". As ugly as I find almost all 2.5d games, I fully understand why that became the norm as soon as consoles could handle it.
 
  • Feels
Reactions: y a t s and Safir
Back