Programming thread

Something that can really speed up your progress though is finding a project to build that will actually be useful to you.
That's the thing though I'm making something using Unity but it is taking forever and I don't feel like I was learning very much.


Freecodecamp
I'm going to try this and see how well it works for me
Thanks for the advice
 
Just curious, when should you create and use your own header files in C?
When you want to distribute shared libraries, for organizational purposes and because C (and C++) require the functions to be declared before they can be defined: the order of declaration is also important especially when a function depends on another function.
 
C (and C++) require the functions to be declared before they can be defined
Tiny nitpick: C requires the functions to be declared before they can be called. Definition can happen after declaration, or both can be done at the same time (e.g. int main(int argc, char **argv) {}).

The easiest way to think about header files using this principle is to look at what the preprocessor does with the #include directive. It takes the contents of the specified file and inserts it wherever the #include is placed in the file including it. Typically they are at the top, so the preprocessor effectively prepends all of the definitions from the included headers to the .c file.
 
Last edited:
I just thought I would inform anyone who cares Unity has a python package that allows you to make Python Scripts and those python scripts can call the Unity Engine. It is slower than C# but it is really good for setting up scenes. For example you can literally call game objects or the camera or whatever and edit their position or edit a lot about them.

I find this super useful because I don't have to learn an entirely new language, and I hate programming in C#. It is a better version of Java while still basically forcing you into Object Oriented programming.

Probably for performance reasons you'd still want to do things in C# while the game is running, but it is really useful for defining things that the engine will eventually call.
 
Last edited:
I just thought I would inform anyone who cares Unity has a python package that allows you to make Python Scripts and those python scripts can call the Unity Engine. It is slower than C# but it is really good for setting up scenes. For example you can literally call game objects or the camera or whatever and edit their position or edit a lot about them.

I find this super useful because I don't have to learn an entirely new language, and I hate programming in C#. It is a better version of Java while still basically forcing you into Object Oriented programming.

Probably for performance reasons you'd still want to do things in C# while the game is running, but it is really useful for defining things that the engine will eventually call.
Does it force C# specifically or can you go with any .net language? (Though I would imagine usually all the tooling is a lot better tested with C# and playing around with goofy alternative languages would be a pain in the ass at times.)
 
Alright this might seem like a strange request but does anyone here have any tutorials/exercises I can view/do that can explain the structure of C#? Since they are so similar something for Java would also work.

Like I kind of understand how the language does stuff like types, variables and functions but it is hard for me to put it in my head and actually work with it. I need a bit more of an intuitive understanding of the language.

I've written stuff that works but it has taken me like 2 or 3 hours just to do something really simple. And I don't entirely understand it. I know enough about programming concepts that I can get a decent understanding of different languages. The brief amount of time I've looked at something like C or Rust or etc I could basically grasp what was going on. All the boilerplate just makes it really difficult for me to grasp everything on a line at once.

I think what I need to do is just do something that forces me to figure it out and I won't get good I'll be bad or decent but that'll be good enough.
The difficult thing about these languages is that everything useful isn't in the main language so to say. Java.util and Java.io are packages which contain classes which will empower you to accomplish things which you would have difficulty doing with Arrays or variables alone. These need to be imported and the classes in those packages need to be memorized and understood for you to effectively write anything. I'm not sure the same goes for C#.
 
Does it force C# specifically or can you go with any .net language? (Though I would imagine usually all the tooling is a lot better tested with C# and playing around with goofy alternative languages would be a pain in the ass at times.)
I know F# and Visual Basic can do it decently easily and there are some third party tools for other languages. From what I have seen you are right and it can be a pain in the ass.
I'm not sure the same goes for C#.
From what I know there are equivalencies in C#. That is helpful I will probably have to write some small simple things in C# for when what I am doing is actually running but because it is not about making the editor do a bunch of simple stuff that C# overcomplicates I will be fine.

I think just based at looking at those two things that they would be useful. Thanks you may have saved me an hour or two or even significantly more than that.
 
  • Like
Reactions: y a t s
I know F# and Visual Basic can do it decently easily and there are some third party tools for other languages. From what I have seen you are right and it can be a pain in the ass.
F# is supposed to be cool as shit.

Completely useless for gamedev, but still cool as shit. (I'm a big fan of Ocaml, and it's basically Ocaml for .NET)
 
F# is supposed to be cool as shit.

Completely useless for gamedev, but still cool as shit. (I'm a big fan of Ocaml, and it's basically Ocaml for .NET)
I've heard of F# but never read about it. It says it is multi-paradigm how true is that? If you don't know about F# how good is Ocaml at doing a little bit of OOP.? After doing a bit of both I've come to the conclusion from my small baby time of like 250 hours of simple programming that Functional is good for nearly everything but sometimes you can make things simpler by adding a little bit of OOP.

I've only done like 20 or so hours of extremely inefficient work with OOP in something that is like something like Game dev. My impression is that you should still do a lot of Functional, but it can benefit from more OOP than other forms of programming. I have heard similar from Jonathon Blow, who is an Indie game dev who wrote his own language for game dev.
 
  • Like
Reactions: y a t s
I've heard of F# but never read about it. It says it is multi-paradigm how true is that? If you don't know about F# how good is Ocaml at doing a little bit of OOP.? After doing a bit of both I've come to the conclusion from my small baby time of like 250 hours of simple programming that Functional is good for nearly everything but sometimes you can make things simpler by adding a little bit of OOP.

I've only done like 20 or so hours of extremely inefficient work with OOP in something that is like something like Game dev. My impression is that you should still do a lot of Functional, but it can benefit from more OOP than other forms of programming. I have heard similar from Jonathon Blow, who is an Indie game dev who wrote his own language for game dev.
The O in Ocaml is supposed to be Objective, as in OOP, but its OOP features are basically useless (in my opinion) and the language's main value is as the main ML family language still in active development and use.

Part of ML's appeal is its functional aspects. Functional programming makes a lot of things far more straightforward and saves headaches later, when it's applicable.

But the other big part of why I like ML languages are the type system, which is far more sophisticated than what you see in other mainstream languages.

Gamedev at its core is a bunch of different entities interacting with each other and affecting each others state. From that perspective, it's not super conducive to functional programming.

But there's still lots of opportunities for functional programming. Like if you need to find the center of a collection of game objects, you might do averageXY(objects.map(function(obj) { return obj.position })) (to use a JS-esque syntax), and averageXY might itself be defined fairly functionally.

For an example of a type of program that maps well to functional programming, here's a little example of a program written once in SML (an ML family language, obviously) and then the same program written in C++ for comparison.
 
I find this super useful because I don't have to learn an entirely new language, and I hate programming in C#. It is a better version of Java while still basically forcing you into Object Oriented programming.
Do you mean in the sense that you have to define a class just to print "Hello world"?
 
Do you mean in the sense that you have to define a class just to print "Hello world"?
Yeah basically.

I also hate that sometimes it can be really hard to get objects to do exactly what I want without changing a bunch of stuff.
I was doing OOP within a simulation software and it was fucking nightmare because it is nearly impossible to get stuff to work exactly as you would want it.

OOP can be good if it is relatively simple and it arises out of a situation where it makes sense. I like just a little bit of it sometimes.

But anything that requires it exclusively makes me really hate it. I also think you should try and avoid it unless you either have a lot of experience in doing a particular thing or you have made enough of what you are doing that you can make a good implementation of it.
 
  • Like
Reactions: Umikot and y a t s
Yeah basically.

I also hate that sometimes it can be really hard to get objects to do exactly what I want without changing a bunch of stuff.
I was doing OOP within a simulation software and it was fucking nightmare because it is nearly impossible to get stuff to work exactly as you would want it.

OOP can be good if it is relatively simple and it arises out of a situation where it makes sense. I like just a little bit of it sometimes.

But anything that requires it exclusively makes me really hate it. I also think you should try and avoid it unless you either have a lot of experience in doing a particular thing or you have made enough of what you are doing that you can make a good implementation of it.
Not sure if it helps but I seem to recall recent versions of dotnet let you write C# code without all the boilerplate.

In other news, I’m the pointers and arrays part of K&R and I’m starting to get lost. I get the basic premise of pointers and how they can be used with arrays (reminds me of a foreach loop which is useful). But I feel like I’m missing some stuff. Any good supplemental material on pointers?
 
In other news, I’m the pointers and arrays part of K&R and I’m starting to get lost. I get the basic premise of pointers and how they can be used with arrays (reminds me of a foreach loop which is useful). But I feel like I’m missing some stuff. Any good supplemental material on pointers?
This video is pretty good:

imo, pointers start making the most sense once you start using them with functions to pass by reference (i.e. pass a pointer to an array instead of the whole array), also when you start implementing custom data structures like trees, and when you need to dynamically allocate buffers using things like malloc. Comfort with pointers comes with time and practice; don't sweat it too much.
 
Any good supplemental material on pointers?
Not really. I will say that this is one of the most important things to remember about how C works: Pointer accesses with the list_of_things[index] syntax are actually just *(list_of_things + index) in disguise. Also read what @y a t s said because it's solid advice.

I'll add an idea for a simple place where pointers could help: Try making an image buffer struct with several functions to create, destroy, and access specific pixels. (Think a function like uint8_t* image_get_pixel(image img, x, y) that returns a pointer to a specific place in your array corresponding to that pixel, which can be indexed like so: image_get_pixel(img, 3, 4)[2] and suddenly you have pixel 4, 5's blue channel. Maybe that isn't too readable so maybe you could do image_get_blue(img, 3, 4)? I don't really know. Programming is hard.) Try to make it use only one malloc() call when creating/freeing the image data pointer. Also try making it with a split header / file combination so you can use it more like a library.

Fucking around with multidimensional data like images will make you become really comfortable with pointer arithmetic very quickly.
 
I was doing OOP within a simulation software and it was fucking nightmare because it is nearly impossible to get stuff to work exactly as you would want it.
I feel like that means it was poorly designed or poorly documented. Really any OOP system should be designed by contract so that any behaviour can be overridden. I didn't like OOP heavy programs until I really got patterns like dependency injection and ran into examples of inheritance that weren't the useless tutorial "both Car and Truck inherit the Vehicle class" pablum.
 
I'll add an idea for a simple place where pointers could help: Try making an image buffer struct with several functions to create, destroy, and access specific pixels. (Think a function like uint8_t* image_get_pixel(image img, x, y) that returns a pointer to a specific place in your array corresponding to that pixel, which can be indexed like so: image_get_pixel(img, 3, 4)[2] and suddenly you have pixel 4, 5's blue channel. Maybe that isn't too readable so maybe you could do image_get_blue(img, 3, 4)? I don't really know. Programming is hard.) Try to make it use only one malloc() call when creating/freeing the image data pointer. Also try making it with a split header / file combination so you can use it more like a library.

Fucking around with multidimensional data like images will make you become really comfortable with pointer arithmetic very quickly.
This reminds me of a common assignment given to 1st year uni students. The assignment is to implement a flood fill algorithm using a 2D image buffer containing pixels that are considered empty if they are set to 0. You fill outwards from a given set of (x, y) coordinates until reaching some edge/boundary using simple recursion.
 
Last edited:
Not sure if it helps but I seem to recall recent versions of dotnet let you write C# code without all the boilerplate.

In other news, I’m the pointers and arrays part of K&R and I’m starting to get lost. I get the basic premise of pointers and how they can be used with arrays (reminds me of a foreach loop which is useful). But I feel like I’m missing some stuff. Any good supplemental material on pointers?
Pointers are simple. No object can be modified or accessed without knowing its address. With the exception of primitives, Values are a copy of the original object. Values do not contain the original's address and thus anything passed by value cannot modify or access the original.
The large amount of confusion with pointers arises from a lack of knowledge of how programs function on a technical level. Specifically the stack and subfunctions.
When you pass anything into a function call, you are copying it transiently to another location in memory in which the function executes. That copy has no knowledge of the originals address in memory. It cannot be used to modify the original. When you pass a pointer, you are passing access to the original.

Edit: the previous section describes c.

P.S., for the java fags out there your language is pass by reference, no matter how much your thought leaders kvetch about primitives which are largely deprecated in the current era.
 
  • Informative
Reactions: Napoleon III
Part of ML's appeal is its functional aspects. Functional programming makes a lot of things far more straightforward and saves headaches later, when it's applicable.

But the other big part of why I like ML languages are the type system, which is far more sophisticated than what you see in other mainstream languages.

Gamedev at its core is a bunch of different entities interacting with each other and affecting each others state. From that perspective, it's not super conducive to functional programming.

But there's still lots of opportunities for functional programming. Like if you need to find the center of a collection of game objects, you might do averageXY(objects.map(function(obj) { return obj.position })) (to use a JS-esque syntax), and averageXY might itself be defined fairly functionall
WRT functional programming and game development, I recall John Carmack talking about Haskell positively a while back; IIRC he was messing around with porting Wolfenstein 3D into Haskell. He was pretty positive on it. But comparing John Carmack to the average coder is like comparing Jimi Hendrix or Dimebag Darrell to the average 15 year old dicking around in Guitar Center.
 
WRT functional programming and game development, I recall John Carmack talking about Haskell positively a while back; IIRC he was messing around with porting Wolfenstein 3D into Haskell. He was pretty positive on it. But comparing John Carmack to the average coder is like comparing Jimi Hendrix or Dimebag Darrell to the average 15 year old dicking around in Guitar Center.
Yeah, you could do it. And it's probably a lot easier / understandable if you're rewriting an existing old game with well known logic.

Basically the whole game would be modeled as a function that takes the whole world state as a tree of various objects, and an event, and returns a copy of the old world state but with whatever changes that event would prompt. And one type of event might just be a time tick, so if the player didn't do anything, the update function would still tick things along.

Something like:
Code:
function update(state, event) {
  // ... updates state with event
  return { ... updated state stuff based on event }
}

// infinitely recursive loop
function main(state) {
  main(update(state, next_event()));
}

// start off with initial state
main({ ... });
(javascript like syntax though, obviously, not haskell)

I wouldn't want to do a new game idea in Haskell though. You're going to want the flexibility of being able to change stuff on the fly, which inherently involves messy, sketchy changes that might not be the best coding practices by engineering standards.

If I was going to gamedev in a functional-ish language, I'd use Scheme with a CLOS-style OOP system.
 
Back