Live data from Hacker News

I write games in C (yes, C) (2016)

jonathanwhiting.com

211–220 of 288 posts

Re: I write games in C (yes, C) (2016)

#211
post #20

I write mostly like I would in C, but use C++ features as needed. It ends up looking similar to Rust if you squint. All these "I write games in C" people complain about C++ features, and then end up reimplementing virtual interfaces manually with struct headers or massive switch statements, just to feel better about themselves. Writing games in C is not harder, you just have to implement modern language features by h…

C++ reimplements a lot of the things we do in C with function pointers, while hiding what's actually happening behind topheavy syntax that implies a 1990s object oriented paradigm that's dead now.

how is OOP dead if tons of code keep being written using OOP these days? From anything corporate in Java/C# to Hyprland C++

Re: I write games in C (yes, C) (2016)

#212

Earlier quoted context omitted.

C relies on the programmer to understand the lifetime of every object in the program, which is global structure. When the programmer is multiple people, it's easy to get out of sync. unique_ptr from C++ solves 90% of this.

Ever use a leak detector? Even my graphics engines (with shared resources) uses a leak detector in debug mode. The monent you forget to release a resource, assertion at program termination. Leaks are trapped with tooling, and all you need is one dev in the team to be diligant to run valgrind or visual leak detector or similar.

Do you think the best way to avoid bugs is to thoroughly test your code, or does understanding the code while you write it also help?

Re: I write games in C (yes, C) (2016)

#213
post #18

Literally thousands of games have been written in C, and all graphics APIs (OpenGL, Vulkan, DX) are C APIs, so it isn't weird at all. All major game engines are also written in C/C++.

DirectX is C++ (technically a set of COM interfaces) and most game engines are also C++. Unlike, say, Linux programming where C is the standard, almost all games have been written exclusively in C++ for a long time now, probably three decades.

> DirectX is C++ (technically a set of COM interfaces) and most game engines are also C++.

So? Their interface is via C, just like OpenGL was.

Re: I write games in C (yes, C) (2016)

#214
post #188

Earlier quoted context omitted.

Automatic memory accounting — construct/copy/destruct. You can't abstract these in C. You always have to call i_copied_the_string(&string) after copying the string and you always have to call the_string_is_out_of_scope_now(&string) just before it goes out of scope

This seems orthogonal to std::string. People who pick C do not want automatic memory management, but might want better strings.

Automatic memory management is literally what makes them better

Re: I write games in C (yes, C) (2016)

#215
post #165

Earlier quoted context omitted.

How did your equivalent assembly program without a definition of _main to? You're doing that thing. I think it's called "trolling". It goes like "hurr durr, they said take one, but they wouldn't let me take one plate" or "hurr durr, I filled my gas tank with nitrogen, which is a gas, but my car doesn't go" or "hurr durr, they said C++ features are all optional, but I don't want to use letters, how can I write C++ wit…

> your equivalent assembly program Right now, hlt jmp $0 I intend to add more later, of course, but I until I get past this hurdle I am unable to start. Does that help narrow things down for you?

It doesn't link. Something about undefined symbol _main. Can you help?

Re: I write games in C (yes, C) (2016)

#216

Earlier quoted context omitted.

How did your equivalent assembly program without a definition of _main to? You're doing that thing. I think it's called "trolling". It goes like "hurr durr, they said take one, but they wouldn't let me take one plate" or "hurr durr, I filled my gas tank with nitrogen, which is a gas, but my car doesn't go" or "hurr durr, they said C++ features are all optional, but I don't want to use letters, how can I write C++ wit…

> that guy asked Stack Overflow how to make gcc compile his .png Do you have a link to this? All the search results I'm getting are related to libpng.

I can't find it with a more specific search on SO, maybe it was deleted.

The question was like: I wrote "hello world" but I get some compile errors, followed by an image embed of a handwritten hello world program, followed by a compiler command where the input file had a .png extension and an error related to the compiler not being able to read PNG files, followed by quoting the part of the standard where it says the input file shall be readable text and this is obviously readable text because I can read it.

Re: I write games in C (yes, C) (2016)

#217
post #200

Earlier quoted context omitted.

C++ nudges you to think in terms of single elements. Operator overloading, ctors/dtors, references, etc. you pay that cost all over the place. C programs tend to nudge you into thinking in terms of arrays of data. For game development you generally want to think this way. The cost of vtables and all the cache misses doesn’t have to be paid. A game has to stream bytes. Many things at once. Rarely single elements at a…

Only if devs lack the skills to understand what to actually use. There is this anti-C++ bias that keeps forgetting that using C++ doesn't mean use every feature. Just like many keep using C as if C89 was latest, and never adopt anything added in the last 30 years.

What this comment looks like to a C programmer:

>> C89

> agree :D

Re: I write games in C (yes, C) (2016)

#218
post #188

Earlier quoted context omitted.

This seems orthogonal to std::string. People who pick C do not want automatic memory management, but might want better strings.

Automatic memory management is literally what makes them better

For many string operations such as appending, inserting, overwriting etc. the memory management can be made automatic as well in C, and I think this is the main advantage. Just automatic free at scope end does not work (without extensions).

Re: I write games in C (yes, C) (2016)

#219
post #165

Earlier quoted context omitted.

> your equivalent assembly program Right now, hlt jmp $0 I intend to add more later, of course, but I until I get past this hurdle I am unable to start. Does that help narrow things down for you?

It doesn't link. Something about undefined symbol _main. Can you help?

It doesn't need to link. That is the complete program. Are you suggesting I need to pass a flag to the C++ compiler to disable the linker? How do I do that?

Re: I write games in C (yes, C) (2016)

#220
post #74

Earlier quoted context omitted.

Searching "site:news.ycombinator.com go" on Google didn't yield any results that weren't about the Go programming language even after going several pages deep. What kind of search problems are you having, exactly? And why is it unique to Go? I am sure there are comments on HN about metal oxidization, making sharp changes in direction, Norse gods, and letters of the alphabet.

But if you go to the search box at the bottom of the HN page and type in 'go' the first hit is "Julian Assange has reached a plea deal with the U.S., allowing him to go free," In the top 10 results, only _two_ are about Go, the language. Whereas the first 50 golang hits are all about the language. You might have your preferred approach, but there are good reasons for using golang.

> but there are good reasons for using golang.

Such as? If you type in 'C' into HN's search box, the first result is about the F.C.C., followed by C.E.O., then USB-C. Even once we finally see one about a programming language, it is about C#.

If the earlier list was instead 'Clangclang, Golang, Odinlang and Ziglang' then I could maybe understand where you are coming from, but that is not what we saw. Clearly there was no effort put into aiding searchers universally.

Are you trying to suggest that Go is the only language worth reading about? Let me try to restate the earlier question in your tongue: Why is it unique to 'golang'?

Post reply on HN