[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

C vs C++ Which is better?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 105
Thread images: 8

File: diffrence between c and c++.png (47KB, 375x360px) Image search: [Google]
diffrence between c and c++.png
47KB, 375x360px
C vs C++

Which is better?
>>
I prefer C++, come at me
>>
File: 1473362643759.jpg (31KB, 500x334px) Image search: [Google]
1473362643759.jpg
31KB, 500x334px
D
>>
C is elegant and super not-bloated, but C++ has some features that are hard to give up
>>
>>58203228
C++11 or newer, in the hands of someone competent.
>>
>>58203523
>Not c++0x
>>
>>58203228
C++, if used by someone who's not a complete retard. If you are retarded and can't figure out when and how to use convenient features of a language, then C.
>>
>>58203251
Why is C elegant? I agree it isn't bloated but nothing about C comes across as "elegant"; perhaps minimal, as you aluded to.
>>
>>58204134
Elegant relative to the impressive retardation of C++.
>>
>>58204148
Right; it's not elegant, it's minimal. I'd argue there's a difference. C is minimal in that you have a small set of language features to work with. Elegance would be a measure of how expressive the language can be while remaining concise.
>>
>>58203902
So what you do is using only the relevant and useful feature of C++ when you need them, basically you don't use 80% of the language, actually you're doing more C than C++, in fact you prefer C.
>>
>>58204148
>Elegant relative to the impressive retardation of C++.

The warts on my dog's balls are more elegant than C++.
C is a small language, but elegant, it's not.
>>
>>58203228

C. And I'm a C++ programmer.

C is butthole-simple. It's basically the perfect language for its task. It's the closest thing to how a computer executes instructions that's still portable across architectures.

C++ was a language intended to address the problem with using C for large applications. However, over time C++ became more and more absurd. It probably hit peak absurdity in the early 2000s with the proliferation of the STL and of curiously-recurring-template-pattern frameworks. It has become significantly more reasonable since C++0x and beyond, but talk about too little, too late.

Meanwhile, you still can't have a 'finally' clause, because when you ask Bjarne how to do X, he says, "oh, you can do it any way you want!" except for when it comes to handling exceptions, in which case he says, "ya, fuck you, create a wrapper class, I'll go to my grave without 'finally' in C++!"

With Python replacing hideous Perl, Java replacing C++ for Enterprise stuff and (amazingly) for tons of embedded applications, and with C# looking so good for desktop and server development, I don't see how C++ has any place in the world outside of /g/'s alpha-geek shitfests.
>>
>>58203228
C is losing the little relevance it still has with every CVE and is probably on the way out
>>
>>58204348
C is very elegant.
It's small featureset means you'll be using every one of it's features and standard library functions even in small 1000 line programs.

C++ parlance focuses on ignoring entire subsets of the language depending on who you ask, and the creator of C++ himself encourages you to avoid most of C++'s featureset.
What kind of shit is that?
>>
>>58204348
I don't think you understand the concept of relativity. For example your dick might be considered as big when compared to an atom.
>>
>>58204367
>C is very elegant.

To be honest, no code that's thoroughly correct and complete is ever elegant.

It always starts out elegant. But when you want to properly handle every error case, I don't think there's any language out there that's truly elegant.
>>
>>58204384
If your goal is elegance, you'll find some way to wrap up your error handing code in such a way that it documents itself nicely and doesn't clutter up your code.
That's the whole point of functions and macros after all.
>>
>>58204363
Gamedev is still C++ turf
>>
>>58204363
I program C++, I acknowledge it's inelegant, but it has a combination of having low-level access and low-cost abstractions that I find attractive. The RAII pattern is really nice.

I'll have to look into D and rust to see if they can take the crown for me..
>>
>>58204363
>Java replacing C++
Tell that to Autodesk, Adobe and 35 more game companies
>>
>>58204411
>C++
>Low level

Is this thread supposed to be satirical?
>>
>>58204367
>C is very elegant.
>It's small featureset

That's minimalistic, not elegant.
Can you write an interpreter for C in about a page of code? That would be elegant.
>>
>>58204419
Who says elegance is brevity?
>>
Some stuff I want in C++:

1) 'finally' clause. Yeah, yeah, I know how to get around it, but there are times that I don't want to do that, and that's C++'s entire selling point: do whatever the fuck you wanna do.

2) template blocks, so that you don't have to have "template <typename T>" repeated before every single function in a header.

3) Functions inside functions. I dunno, I just always loved that in Pascal.

4) Protected as the default member state, rather than private. IMO this always hindered classic OOP inheritance systems.

5) virtual as the default member state. Same as #4.

6) intrinsic, modern strings because it's 2016 and the wold is Unicode.

7) I guess an anonymous function declaration that doesn't look like a compiler error. Way too late for that, though.

Damn, I had another that was really good, but damned if I didn't forget.
>>
>>58204418
It gives you all the low-level access capabilities that C does. You can compile a piece of code as C or C++ and it will be just as efficient either way.
>>
>>58204418

Not GP, but

> having low-level ACCESS

Emphasis mine. Learn to read, Captain Tardsnark.

>>58204403

I have a good friend who's worked at EA, Relic, and now some other major label I forgot about. His primary language in the last several years has been C#.
>>
>>58204397

I've never seen production code that actually handled error cases correctly that was also elegant.

I don't believe your claim is realistic for real-world, production code. Unless, of course, you're comfortable with your program just taking a dump when errors happen.

Oh, and:

> that it documents itself nicely

Oh, hell no. Anyone who talks about code that "documents itself" is a fool who hasn't spent enough time working on other people's code.

One man's "self-documenting code" is every other man's crazy spaghetti.
>>
Why do plebs love finally so much?
>>
>>58204426
Succinctness would be the right the word.
C and C++ are language for lawyers. They have single handedly set back computer science for decades.
>>
>>58204479

Because if I'm doing a one-off call to some external library, it allows me to easily handle nastiness and clean up properly.

Again, I know how to get around it, but IMO that's stupid for, as I said, simple, one-off stuff.

Why do /g/ try-hards go cross-eyed from looking down their nose so hard at useful language features? And why can't you make a point without being a toxic asshole?
>>
>>58203228
C for hardware interfacing
C++ for code maintenance and object programming
>>
>>58204480
>They have single handedly set back computer science for decades.

They enabled modern computing.

If we didn't have C and C++, we never would have had the personal computer revolution, and you'd currently be paying off a lease on a $15,000 LISP machine that ran software at 1/4 the speed your current machine does, and that you had to reformat every other week because you contracted a disastrous macro.
>>
>>58204494
>toxic asshole

can you go back to your hugbox please?
>>
>>58204457
>C#

probably a tools programmer and not writing the core engine
>>
>>58204529

No. Make a well-reasoned point or fuck off. "Hurr how come only dummies like X?" is an absolutely moronic way to try and make a point.

You're a toxic prick, contributed nothing, and made the thread worse.
>>
>>58204556
ok kid
>>
>>58204549

No, he's not a tools programmer. And "core engine" is a *very* specific thing. There's a tremendous amount of code that goes into a game that's not the engine itself.
>>
>>58204505
Lisp machines are really not a practical answer for personal computing.
But building our software systems just by piling code is getting us nowhere.
For example, we still don't know how to do parallel computing efficiently. I'm not referring to quad or eightcores. I mean thousand and million cores computing. Ho do you do that in C (without tearing your hair off)? Procedural thinking has its place in computer science, but to think that we still have to write the majority of software like we did in the 70's is maddening.
There are so many smarter ways to build software systems, but they remain confined to niches or are essentialy dead because, muh pragmatism, muh unix paradigm etc.
Unix beards have taken over and a lot of good stuff has simply faded away.
>>
Mixing C and C++ (using cstdlib or stdio.h with the C++ STL (iostream and list)) works a lot better than using a single language (although I only use C++ for the libraries).
>>
>>58204599
>There are so many smarter ways to build software systems, but they remain confined to niches or are essentialy dead because, muh pragmatism, muh unix paradigm etc.
>Unix beards have taken over and a lot of good stuff has simply faded away.

Uh, no, programming hipster, that's not true.

As for massively parallel programming, uh, that's what map-reduce accomplishes reasonably well. And who really cares?

>But building our software systems just by piling code is getting us nowhere.

It's gotten us *everywhere*. What the fuck are you even talking about? Look at the world around you, hipster. Twenty years ago we were barely capable of reliable multithreading, and multiple-cores were just coming into the world.

Nowadays we all have computers in our pockets providing us 24/7 access to the rest of the world, and at a pretty damn reasonable clip.

If you think "piling code is getting us nowhere" then you have *absolutely no idea how far we've come*.
>>
>>58204650
>Uh, no, programming hipster, that's not true.

Actually it's true, you Javascript monkey.

>As for massively parallel programming, uh, that's what map-reduce accomplishes reasonably well. And who really cares?

Oh God, you need to be bashed on the head

>>But building our software systems just by piling code is getting us nowhere.
>It's gotten us *everywhere*. What the fuck are you even talking about? Look at the world around you, hipster. Twenty years ago we were barely capable of reliable multithreading, and multiple-cores were just coming into the world.
>Nowadays we all have computers in our pockets providing us 24/7 access to the rest of the world, and at a pretty damn reasonable clip.
>If you think "piling code is getting us nowhere" then you have *absolutely no idea how far we've come*.

That's Moore's Law, you doofus.
>>
>>58204436
>3) Functions inside functions. I dunno, I just always loved that in Pascal.
lambda abuse delivers:
auto func = [](std::string s){std::cout << s <<std::endl;}

func("lambda abuse ftw");

Super useful if you're fucking around with web requests or other stuff that you want to retry on failure
>>
>>58204436
>template blocks, so that you don't have to have "template <typename T>" repeated before every single function in a header.
You can always define something shorter to be equal to
template <typename T>

like that
#include <iostream>
#include <string>

#define temp template <typename T>

using namespace std;

temp
inline T const& Max (T const& a, T const& b) {
return a < b ? b:a;
}

int main () {

int i = 39;
int j = 20;
cout << "Max(i, j): " << Max(i, j) << endl;

double f1 = 13.5;
double f2 = 20.7;
cout << "Max(f1, f2): " << Max(f1, f2) << endl;

string s1 = "Hello";
string s2 = "World";
cout << "Max(s1, s2): " << Max(s1, s2) << endl;

return 0;
}
>>
All you need is Python.
>>
>>58203228
C, If I need to make a application for embedded devices.
Java for the big stuff.
>>
>>58203243
/thread
>>
>>58203228
They are different

You can use C++ like C with classes but you are doing C++ a disservice

If you forget the C in C++ and use the STL and all the cool features of C++ (like for example strings, operator overloading) C++ is really cool

>https://www.youtube.com/watch?v=YnWhqhNdYyk

I wish I could find a book that would teach this style of C++ and ignore the C because I already have read K&R and it's the best handbook on C
>>
>>58204436
>that's C++'s entire selling point: do whatever the fuck you wanna do.
no, fuck you, this kind of thinking is why so much c++ code is shit, just use RAII properly and don't try and do crazy shit with exceptions otherwise you will end up with horrible unmaintainable spaghetti code, the only reason to ever throw an exception is if your program is going to crash anyway

http://yosefk.com/c++fqa/exceptions.html#fqa-17.1
>>
File: rust.png (15KB, 200x200px) Image search: [Google]
rust.png
15KB, 200x200px
Obligatory Rust mention, I'm kinda surprised Go shills haven't showed up yet.
>>
>>58204134
C implementation of pointers looks elegant to me

struct Foo foo; 
struct Foo *ptr;
ptr = &foo;
ptr++;


You increase the pointer by one but C is smart enough to move the pointer
sizeof (struct Foo)
bytes. This looks very elegant to me.

And then it's how C doesn't have complex built in types but you can use structs and unions to build everything, how C doesn't even have arrays and strings but all is actually build on top of pointers with some very elegant syntactic sugar. And I like how easy is to make a pointer to a function (which points to the place in the memory where the function is stored) and pass this pointer to a function as a parameter to another function.

This combination of low level with a single powerful abstraction (pointers) that allows you to build complex data structures while always being able to understand what the compiler is doing makes C a very elegant language
>>
>>58204363
I love C++, but man I have to agree, it is a horrible language with a lot of warts and a lot of extremely convoluted, downright abusive template/OOP/macro bullshit. Nowadays C looks sane in comparison even considering nonsense like scanf and gets.
>>
>>58203228

Just use C.

Use C++ if you don't know how the hardware your code is running on works or if you are a tech-illiterate in general.
>>
C++, because interviewers perk up when you let slip that you can write C++.

>Yeah I wrote in C++ for some projects too
>Oh? Tell me more
>>
>>58206733

Sure they do...
>>
They are different languages.

C for anything that involves writing to registers, driving pins on IO ports high or low, programming interrupt vectors manually or when you don't have a continuous virtual address space.

C++ for when you have a virtual address space and threading is supported by the underlying architecture (read: you're running on an actual OS and not on some barebones firmware).
>>
>>58206775
Oh, and I forgot: Only use C++ if you actually have the standard library (either everything or at least a fairly large subset of it) available. Without it, C++ is nothing but a fancy dialect of C which implicitly supports RAII, classes and namespaces.
>>
>>58206503
People who use Go are busy actually working on projects instead of evangelizing.
>>
>>58206775
> C++ for when you have a virtual address space and threading is supported by the underlying architecture
Why? You can use C++ as a better C in every case you would use C, it doesn't require virtual address space any more than malloc does. There is nothing preventing you from running C++ on barebone hardware, see hundreds of OSes written in C++ without a line of pure C.
>>
>>58204494
>calling others toxic while being anti-semetic
wew lad
>>
>>58204479
They don't know about RAII.
>>
>>58206858
>Why? You can use C++ as a better C in every case you would use C,
There is no point in doing this. You have to bootstrap a C++ runtime, which you generally won't bother to do.

> it doesn't require virtual address space any more than malloc does
I didn't say so.

>There is nothing preventing you from running C++ on barebone hardware
There isn't, but there is no point in doing so. I don't want to bootstrap a C++ runtime that implicitly invokes destructors in order to emulate a stack.

Also, see >>58206802

The real power of C++ is in the standard library, not in RAII and classes.

>see hundreds of OSes written in C++ without a line of pure C.
This is not true. Most OSes are written in C with some components in C++.
>>
>>58204363
C++ seems really easy to write but a huge pain in the ass to read, which seems good and bad, it's great for personal projects but not so great when working with a team unless you do the right thing and spend a good amount of time documenting but a lot of people hate doing that.

>>58204403
Up until recently I heard a lot of developers saying they still use ANSI C with data oriented design, the ones that do use C++ tend to write mostly C with a subset of the C++ features. Recently I've seen a lot of C# with hobbyists but also professionals.

The big element revolving around C++ has to be anyone who uses Unreal and not their own engine, likewise the same is true for C# and Unity.
>>
>>58204134
"Small is beautiful"
>>
>>58203228
HAHAHAH :--DDDDDDDDDddddddd

LE REDDIT MAYME XDDDDDdddddd
>>
>>58206879
> a C++ runtime that implicitly invokes destructors in order to emulate a stack.
What are you talking about? There is no such thing as "C++ runtime", calls of destructors are inserted at the end of a block by compiler at compile-time. You must be confusing C++ with Go, Haskell or D where actual runtime is needed to support GC and green threads.
>>
C#
>>
>>16089177
>>
>>58206963
>autism
>>
>>58204320
>don't use 80% of the language
This is never true though.
Or do you mean 80% of the STL?
Because that is like shitting on the math.h (or cmath for you cheeky cunts) because you only need atan2.
As I see it, the STL is tools I would develop if I had to do the excact same thing.
Templates makes it general enough so you can use containers for every class or struct you want and you have safety built in, so you get useful errors when accessing elements out of scope of the container.

Lets take a std::array and a C style array.
With C, you do not have information about the size, you cannot easily loop through the elements etc.
Another example would be pointers.
With C, you create a pointer and use valgrind to make sure you clean up after yourself.
With C++, you can make pointers delete the content when it isn't referenced anymore.
Everywhere you look, C++ is superior.

The worst part of writing C++ is when you some times have to deal with applications which is written in C.
>>
Any science-related people here? I'm studying as a medical physicist and my consulent told me that C++ is the most important language in scientific applications. Is that true?
>>
>>58207162
>With C, you do not have information about the size, you cannot easily loop through the elements etc.
void fn() 
{
char arr[10];
for(int n = 0; n < 10; n++) {
arr[n] = 1;
}
}

So fucking hard, I mean my penis.
>>
>>58207230
He obviously meant when you pass an array as an argument you fucking retard.
>>
>>58207264
void fn(char *p, size_t size) 
{
for(size_t n = 0; n < size; n++)
{
p[n] = 1;
}
}

Yeah totally too hard. Everybody should just stop using C because the looping is so hard.
>>
>>58207230
compared to
std::array<char,10> arr;
for(auto n : arr){
n = 1;
}
>>
>>58207291
>::<>
eww
>>
>>58204436
" IMO this always hindered classic OOP inheritance systems."
explain
>>
>>58207057
not the anon you were responding to but yes, there is are C++ runtimes (as well as C runtimes)
>>
>>58207554
Only if you call statically linked standard library functions "a runtime".
>>
>>58207578
>Doesn't know about crt1.o
>>
What would fix both languages would be if they made stdint.h part of the language, so you never had to include it.
I don't know why, but I often come across someone who use something else or worse, use the default types.
I don't really like the names personally, but as long as people use the same thing, I would adapt.
I don't see why this wasn't done many years ago and just fixed it in the compiler on those systems that does not support the bit width.
>>
>>58207599
Oh well, I didn't know, my bad.
>>
>>58207615
>so you never had to include it
Wow, literally 1 line of code. Also, the languages (C at least) doesn't want to introduce any more keywords than necessary.
>worse, use the default types
You're an idiot. The normal C types a perfectly fine.
As long as you mind your assumptions, they are easy to use.
Using exact-width integers misleads the reader, as it makes them think that some value is some size for a specific reason. If it's just "int", they will think it's just some integer.
You should only use exact-width integers to conform to some external size requirements.
>just fixed it in the compiler
How do you propose that? Also, C wants to be able to run efficiently on practically any platform. Emulating twos compliment types isn't really a valid solution.
>>
>>58207302
this is my one fucking complaint about C++, I don't need fucked up wrists by the time I'm 40.
>>
File: 1477675873753.jpg (53KB, 445x400px) Image search: [Google]
1477675873753.jpg
53KB, 445x400px
>>58207114
>falling for the bait
>>
>Tfw you've been programming your own custom game engine for over a year in pure C
Shits hard, But I've made progress.
>>
>>58208179
link to repo.

Wanting to make my game with lisp and started writing C library that would tie together some libraries and try to be easy make bindings to. Current plan is to expose bgfx(renderer), sdl2(window, events, audio), newton-dynamics(physics engine), self made asset manager. Going to make some kind of scene graph probably just see how Horde3d does it and try to implement it in my lib.

I would have just made bindings to existing engine but Corange doesn't support mobile platforms, darkhammer engine seemed promising but no documentation and project seems dead, raydium would fit perfectly but I already started before I found about it.
>>
>>58204363
CRTP isn't obvious to read if you come from another OO language.
Still it's not that frequent today and most modern framework are going for concepts and other neat patterns.

Business code in C++14 and 17 is an order of magnitude more readable and expressive that Java.
Thank Sun/Oracle for refusing to implement operator overloading, static polymorphism and ADL.
>>
>>58204367
The kind who acknowledges errors from the past and allows his language to evolve
>>
According to the original creators of Unix, C, and C++, Golang is the best.

But you children can continue to argue about irrelevant dinosaur languages.
>>
>certain set of hardware, which has a good c++ compiler
c++

>unknown set and highly portable, embedded
c
>>
>>58206503
Rust was debunked. Don't even bring it up here.
>>
File: 1456501837780.jpg (88KB, 573x640px) Image search: [Google]
1456501837780.jpg
88KB, 573x640px
When I write in languages other than Go I need a ton of time to get the same programs written. I don't think it's just habit, I have only been writing Go for a few years and it takes forever to write software in C++.
>>
>>58210007

That's exactly how I feel when writing Go coming from a language like Clojure.
>>
>>58206506
all of that is true I completely agree, but that doesn't make it generally better than C++
>>
>>58204436
> 5) virtual as the default member state. Same as #4.

Are you insane?
>>
>>58210251
The default should be to allow inheriting classes to override any method. We should be marking what can't be overridden, just like we mark what can't be mutated (const).
>>
>>58204599
>There are so many smarter ways to build software systems, but they remain confined to niches or are essentialy dead because, muh pragmatism, muh unix paradigm etc.
Okay, why don't you at least mention a couple of practical examples of such cases.
>>
I keep seeing people say "C, but C++ has features I can't give up"

What are those features?
>>
>>58210981
OOP I guess.
>>
>>58210981
Templates and destructors for stack-allocated containers. Move semantics with corresponding API hooks. There is no other language with all of these features, meaning there's no other language where you can make smart pointer types.
>>
>>58210981
Classes, templates, strings, function and operator overloading, namespaces and lambdas just to name a few
>>
>>58210981
Templates and metaprogramming.
>>
File: 1422839454291.jpg (213KB, 854x1000px) Image search: [Google]
1422839454291.jpg
213KB, 854x1000px
>>58206928
MY DICK AINT BEAUTIFUL LOL! XD
>>
File: 2.jpg (21KB, 300x300px) Image search: [Google]
2.jpg
21KB, 300x300px
I prefer C, the reason being that C++, to sudo-quote somebody I can't recall the identity of, makes you feel smart when you're doing something really stupid.

There's always that tendency to use stuff like the standard library, stuff like std::string and such, and then forgetting there's dynamic allocation and other costs included with all of that. Or using lambdas, making your code harder to read. Or using virtual functions. And god damn I hate constructors.

The only feature I like about C++ are templates when not overdone, which can be replaced by macros in the usecases I would allow using them in anyway.
Thread posts: 105
Thread images: 8


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.