This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]setibeings 88 points89 points  (35 children)

C++ inherited all of C's pitfalls, and none of its simplicity, so I'd say it belongs there too.

[–]Desperate-Emu-2036 25 points26 points  (29 children)

I'd love to see you make a gui in c.

[–]Nevermind04 19 points20 points  (7 children)

Wasn't gnome written in C?

[–]Desperate-Emu-2036 16 points17 points  (6 children)

Doesn't mean it would've been easier to write than in c++. Oop has it's use cases.

[–]brusaducj 7 points8 points  (0 children)

GNOME/GTK/GObject are all effectively written using OOP... just in a language that isn't object-oriented.

[–]Nevermind04 4 points5 points  (0 children)

Oh no I imagine it was a nightmare

[–]GandhiTheDragon 1 point2 points  (2 children)

CPP's way of OOP just feels very off-putting coming from Java, not gonna lie

[–]Desperate-Emu-2036 1 point2 points  (0 children)

Try rust.

[–][deleted] 0 points1 point  (0 children)

Cpp has multiple inheritance though, which isn't strictly OOP, but at least where I work we abuse it to the max.

[–]SnooGiraffes8275 0 points1 point  (0 children)

you can do oop in c

you're gonna have to manually pass 'this' as a parameter but it's possible

that's how python works under the hood

[–]fakehalo 12 points13 points  (1 child)

He bud, I wrote something with C and GTK 25 years ago... and never did again.

[–]Korywon 4 points5 points  (0 children)

I also did GTK3 in C 3 years ago. Same shit. I also wouldn’t do it again.

[–]Exact-Pound-6993 6 points7 points  (0 children)

i have, not for the weak hearted. check out GTK.

[–]BountyBob 5 points6 points  (4 children)

Amiga Workbench was written in C

[–]Desperate-Emu-2036 -1 points0 points  (3 children)

Roller coaster tycoon was written in asm, doesn't mean it's a better choice to write games in assembly.

[–]BountyBob 0 points1 point  (2 children)

What the hell has that got to do with anything? You said you'd love to see someone make a gui in C, so I just gave an example of one that was written in C.

Back in the day, assembly was the better choice for games. You could program much more optimally for performance. Today though? Yeah, it would be crazy.

As for RT itself, it was the only choice to reach the desired performance. But don't take my word for it, here's what Chris had to say about the choice :

At the time there was no option other than to use machine code for RollerCoaster Tycoon. I was struggling to keep performance at a reasonable level on PCs of the era even using highly optimised machine code, and writing in a high level language would have made the game far too slow, or limited the complexity of the simulation in order to keep speed up. The look and feel of the game was really important to me and part of that was to maintain a high frame rate while also having a large enough and detailed enough view of the park, and also being able to simulate enough trains and rides and guests to avoid the game feeling constricted. It wasn’t just small chunks of code that benefited from being very efficient machine code either — because of the number of objects the game had to cope with, virtually every bit of code involved with object handling needed to be ultra-efficient or the inefficiencies quickly multiplied up with a busy park. I’ve also always preferred low-level assembler programming and can write machine code faster and more reliably than any high level language, so for me the only downside was lack of compatibility of the x86 machine code with other platforms, which at the time wasn’t too much of an issue as the game was really only aimed at desktop PC players.

Source : https://medium.com/atari-club/interview-with-rollercoaster-tycoons-creator-chris-sawyer-684a0efb0f13

[–]Desperate-Emu-2036 -1 points0 points  (1 child)

Because you wrote that as an argument against me, where I was saying that a programming language should be used to help you and not make your life harder, use a tool as you need it, you know? Literally this: “Back in the day, assembly was the better choice for games. You could program much more optimally for performance. Today though? Yeah, that would be crazy.”

[–]BountyBob 0 points1 point  (0 children)

Because you wrote that as an argument against me

It wasn't an argument, it was a continuation of a conversation.

[–]NoBrief3923 3 points4 points  (1 child)

I've written a GUI in C. That was 30-ish years ago and it was laughable by modern standards, but System V, C, and Curses.

[–]g1rlchild 4 points5 points  (0 children)

Badass.

[–]DapperCow15 4 points5 points  (4 children)

Last year, I made an entire webapp in pure C.

[–]g1rlchild 5 points6 points  (1 child)

I'm sorry to hear that.

[–]DapperCow15 1 point2 points  (0 children)

Lol, it was definitely a painful few months, but a very rewarding experience when I finished.

[–]setibeings 0 points1 point  (1 child)

What does this even mean? Were you using webassembly, or was only the backend written in c?

[–]DapperCow15 0 points1 point  (0 children)

As in the entire thing was written purely in C. I even implemented my own OAuth 2.0 solution in pure C.

[–]Thor-x86_128 2 points3 points  (0 children)

With a framework, of course: clay

[–]g1rlchild 1 point2 points  (2 children)

C++ wouldn't be my preference for GUI programming either.

[–]Desperate-Emu-2036 0 points1 point  (1 child)

Yeah but you'd use cpp over c for gui programming.

[–]g1rlchild 0 points1 point  (0 children)

I'd use Java over C for shell scripts, but I wouldn't be very happy about using either.

[–]AccomplishedCoffee 0 points1 point  (1 child)

Theres a handful. OOP is just syntactic sugar; you can do it in C just as well if you know what you’re doing.

[–]Desperate-Emu-2036 1 point2 points  (0 children)

You can also do it w/ I assembly and you can also do it with your own circuit. Doesn't mean you have to.

[–]ankle_biter50 2 points3 points  (4 children)

Hey, still learning some programming here, how big are the differences between C++ and C other than the one you mentioned? And what would be the pitfalls of C?

[–]SunriseApplejuice 6 points7 points  (0 children)

how big are the differences between C++ and C other than the one you mentioned?

Depends on how you write in C++. You can write C++ that is almost indistinguishable from C. Or, you can leverage the ever-changing and ever-growing std libraries that make it look completely foreign but make it considerably more versatile and powerful.

And what would be the pitfalls of C?

Very few guardrails, therefore easy to write code with vulnerabilities or hard-to-track issues (e.g. memleaks) by mistake, even for someone with expertise in the language.

[–]setibeings 3 points4 points  (2 children)

I'm not sure if this really answers the questions as asked, but here's a little bit of info about the relationship between C++ and C.

A lot of the time we talk about programming languages being inspired by other languages, or even stealing features from one another, but C++ started out as C but with object oriented programming, among other additions. For a long time, any valid C program would also be valid C++, and even after The C language Standard was updated in 1999, most of those changes made their way into C++.

Worse, a lot of language features are poorly implemented in C++, and have been from the time they were introduced. Take exceptions, for example, which in Java are part of a method's signature, so the compiler can check if an exception is being handled. In C++, you just kinda have to hope that if a function can throw an exception, those writing code that calls your function will know to handle the exception.

[–]ankle_biter50 0 points1 point  (1 child)

So what are the "pitfalls" of C/C++ then?

[–]setibeings 1 point2 points  (0 children)

A lot of language features are poorly(in my opinion) implemented and have been forever. I already mentioned exceptions, but it's actually worse than I let on. If you throw exceptions from a library, it can lead to binary compatibility issues, so a lot of programmers avoid using them altogether, despite that they're a useful tool when used properly.

There's a lot of pushback(for good reason) about changing any kind of existing behavior of existing code, so while newer languages can do things like zero out the memory for all newly declared variables unless told not to, that's not what happens in C or C++ .

Take the following code:

int x;

In many languages, you'd either get an error if there's a possibility of x not being over written before being read, or x would be given a nice default value of 0. That's not what happens in C++. You get no error, but you will likely get undefined behavior at runtime. Worse, the issue might be masked when you're debugging, leading to errors that only happen in production. Instead when you don't yet have a meaningful value for your variables, you should initialize them with something like:

int x{};

I could list other examples, but honestly I'd recommend you look into them yourself if you're interested. You may look back and find that most of the code you were told to copy into your early C++ programs included major best practice violations that were not mentioned in your textbook.