C or C++?

Objectively which language is better: C or C++?
C has WAYY less bloat and is able to run faster code, but with C++, you can generalize more readily than you can in C and write one source file that can handle all cases using templates. I also find it's standard libraries to be useful than C's just because it has things like , , , and , which (while not hard to implement in C or C++ by hand) saves a lot of time when you are programming. I always felt torn that I learned C++ before I knew C, but looking at C now, I can appreciate it and I like working with it but I want to know which is the language that's designed better. I've heard so much good and bad about both of them that I can't make a decision on which to use for my personal projects.

Attached: Confused Major.png (1000x1000 64.69 KB, 92.22K)

Other urls found in this thread:

youtube.com/watch?v=zBkNBP00wJE
en.wikipedia.org/wiki/ATS_(programming_language)
archive.adaic.com/standards/83rat/html/ratl-12-04.html
m.poemhunter.com/poem/church-going/
twitter.com/NSFWRedditGif

Which is better a car or a bike?

cars

It depends on what you want. DO you want a brisk exercise and/or don't want to deal with traffic? Use a bike. DO you want to get where you are going faster and/or more safely? Use a car.

How banal.
It is clear that you know neither one.
If you really must make a choice, then simply use C++ for all of your low-class proletarian "personal projects". Though do make an effort to consult up-to-date literature on the subject, rather than descend into this fetid pit and trawl the filthy dregs of the Programming profession for advice.

OP here. I realize that I am a massive faggot and ought to really rephrase my conjecture better because I went completely off the rails: My real question is why C has no template struct analogue to C++'s template classes. It seems like a more efficient way to write code, seeing that you don't have to write the same code over and over again for handling a completely different type (like rewriting code for "int"s instead of "cstring"s). How come no modern version of C has this after 40 something (almost 50 now) years?


K

Attached: alerted catgirl.png (775x861, 313.04K)

Because C++ exists

C doesn't even support function overloading, so it's a bit hard to bolt on templates. I don't think it's worth adding to C though, better languages exist. Like Ada and C++.

C#

...

C-

Assembly

Objective-C

Seriously though, C++ has a lot of great features, but they have all been bolted onto C, making the language ugly and a clusterfuck of backwards compatibility. I have tried learning it several times, but in the end I always say "fuck it, I'm going back to C".

C++ proponents like pointing out how it has the same (or better) performance as C, but just today I was talking with a professor of mine and he said that his C++ code always ended up slower than his C code. It could be that he doesn't know "proper" C++ (whatever that means), but I'd say if on top of learning a language you also have to learn which subset of it to actually use, then that's quite poor design.

You'll probably end up using both if you end up working in software engineer or in open source.

What C++ users fail to understand is that templates really are not very useful. If you have a different type, you have a different problem, so you write a different function. Something like a template could NEVER resolve a function that operates on integers into a function that operates on strings. What I think you are experiencing is that you know how templates work, and so you spend a lot of time inventing problems for your templates to solve. If you try writing a complicated project in C you will notice that this is not a problem at all. C++ and other languages put people into a mindset where they try and think of how to glue several high level concepts together into a solution, instead of using a much simpler, more direct solution. If you use C, it will feel more difficult because you are used to writing bad solutions. But it becomes easier when you take a step back and think about what you are actually trying to do.

In ATS you can get completely free apart from object bloat higher-order functions with templates. You get the exact equivalent of a tight, hand-crafted loop without function-call overhead, with the ease and abstraction of higher-level code. I assume that's true of C++ too, since ATS templates were inspired by C++ templates.

I'm not talking about how the code is compiled. Just how the language feature is not needed and can trap programmers in that kind of mindset I was talking about.

Vastly different philosophies. Both of the languages themselves, and the standards committees in charge of them.

The C committee is known to be very conservative in terms of changes and features they will accept, as they are concerned with keeping C simple/portable. Templates are seen as pointless as you can duplicate code, rely on weakly/variably typed interfaces/data, or resort to macros if you really must.

The fact that templates are associate with sepples also probably plays a part in the committee being dead against it.

What templates do is act as a generic type. It's no different to any other language that make use of generic types like C# and Java.

This. The question is wrong. People lump C and C++ together because one grew out of the other, but C++ has gone way off and changed so much that it's hardly comparable to C anymore.


Do what's comfortable. I've written "C++" code that is almost all C except it uses one C++ feature where I needed it.

put your thesaurus away

C+=

Templates allow c++ to be turing complete.

You mean my onomasticon? I will not.

No honey
youtube.com/watch?v=zBkNBP00wJE

Attached: 1540940534.jpg (583x358, 60K)

>>>/g/

Need to do complex stuff without micro-managing every aspect? C++
Want to micro-manage and fine tune every detail of your project? C

They also encourage your code to become an unreadable pile of bloat and cancer worse than feminism and communism combined.

Still more readable than rust :^)

Dumb citycucks

Which version of the C++ standard should I use?, I've been using C++11 so far but it's not for any particular reason.

Fucking turing complete. Do you understand?

Objectively C++. C either has no atomics (pre-C11) or absolute shit-tier syntax (C11). C++ has atomics without diarrhea syntax. Can weebs stop asking stupid questions now?

c++ is good if you dont want to be disciplined and be lazy and abuse the STL library . should be good for any thing you will ever do. The advantages of C probably wont effect you that much if you have to ask this question.

If you don't know why you should use a certain standard you're better off playing with the other C VARP monkeys.

C++20

C for simple fast stuff, D for big OOP stuff.
C++ belongs in the trash.

if you're using D at all, why not use betterC for "simple fast stuff"?

BetterC just complicates things, if I want simple fast stuff I'd rather not have to deal with the differences between two languages.

...

c + some meta programming lib > c++
all meta programming facilities on c++ are extremely retarded and poorly written, it would be better to literally generate code on the run than to contaminate a codebase with c++

shit video

Objectively incorrect, C++ is backwards compatibly linkable with C, so it's at least as fast as C.
Sure, you'll just end up with severely underperforming code that's not worth using at all.
C++, its standard library laughably dwarfs C's meaning you can better express your intentions in code.

C is a legacy and niche language with only a few concrete use cases. C++ is for making big software.

LOL

Stroutsup is clearly not a good programmer, just a yes man who lets a committee decide what goes in (which means everything). That makes a language so big it's easier to list what it can do than what it can't, with a syntax so overloaded and a grammar so ambiguous it flatters Perl and a gigantic standard library and compiler (you won't find something like tcc/pcc for C++).

vs
Yep, they're safer.

Again, objectively incorrect. Bjarne has been the biggest opponent to the standards committe. He is the one single person who rejected the acceptance of many slow and crappy concepts such as garbage collection.
C++ is big but that's entirely the compiler's problem to deal with.
Since the compiler takes all of this syntax burden, all is left is for the programmer to simply write semantics in text form and C++17 allows for that.

In much the same way that you can trivially link Visual Basic 6 to C which makes it at least as fast as C
Just like in all those other cases where excessively generalized solutions to highly specific problems are faster
Perls standard library dwarfs C++'s, making it clearly the bestest mostliest superiorest language


And naturally, it doesn't actually matter if it's practically impossible to write a compiler for your language as long as someone else has already done it once.

Not a superset of C.
Templates that replace runtime type checks are considerably faster, yes. And that's just one example.
It is entirely possible, I have 4 on my PC at time of writing.
Or are hugely underperforming DIY solutions a thing among C programmers?

Neither is C++
Faster than runtime checks, sure. Faster than writing exactly what you need in C? Dream on. Mind you also generally a bigger pain in the neck to use than just writing the interface you want.
Given statements like these, I don't believe for a second that you've ever written anything performance critical in any language, or run a profiler, or have even the faintest idea of how to optimize anything. If you had, you'd at the very least understand that real world problems are practically never solved optimally or quickly by STL constructs. Add multithreading to make leukemia preferable to using STL.
The reason no one container library has ever seen language-wide adoption in C is because if you're using complex containers in C you're doing so within very specific parameters. If you have very specific parameters you can optimize for those. For example, std::queue is dog slow when what you need is a low-contention MPSC FIFO, which can be implemented in a lock-free manner. Any STL container will allocate like a jonesing crack baby, costing you more performance than you realize. What if I need my whatever to be in 2 lists? Not an uncommon thing. With STL I will cause two list insertions causing 2 mallocs to happen and another level of indirection, where in any sensible custom solution you can both have the data and list handling crap stored right next to each other and avoid mallocing anything on insert at all. And so on and so on.
Try writing a 2D rasterizer with STL and see what happens.

C++ is literally designed as a superset to C and to replace it in most cases.
for_each, find_all, partition, lambdas, etc... All of this saves hours of manual labor. Again DIY foolery.
I literally integrate and optimise algorithms for a living, mostly relying on SIMD extensions and intel's IPP. Guaranteed I know more about you since I use C as well as three dialects of assembly.
I genuinely don't see a problem with having 0.5% your codebase written in C (as it should be with a niche language). But given C++ contains C, you're always writing C++. Oops!

Are you going to keep going off on a tangent with your anecdotal edge cases or just admit the statistics are right about C++?

C++ contains a stale, incompatible variant of C. You stop writing C++ as soon as you don't explicitly cast malloc()'s return.

C++ is deprecated.

There's nothing noteworthy in C11.
And that's a good thing

sour grapes.

; gcc -c -x c++ -std=c++17 foo.cppfoo.cpp:6:1: sorry, unimplemented: non-trivial designated initializers not supported }; ^; gcc -c -x c foo.cpp; cat foo.cppstruct { int i, j;} x[] = { { .i = 1 }, { .j = 2 },};
And Microsoft has a C compiler because they sort of support C89 but not really.
Sure, and they're dog slow at run time because they, in order to be a generic as possible, cannot make any assumptions about the data they're operating on. Python makes for a much better prototyping language.
Then how have you never actually benchmarked your beloved language?
Actually, it's not even really the language's fault, as much as it's OOP in general that's completely incapable of performing well.
Come on, man. FORTRAN programmers knew this in the '70s and increasing memory access latencies have made it several orders of magnitude worse since then.

Anecdotal edge cases? Can you honestly say that you've ever encountered one thing that wasn't more efficiently solved (at run time) by optimizing your data structure (you know, the thing you can't do when using STL)?
You should know full well that intrusive data structures are faster to access than non-intrusive ones, or that your use pattern determines what tradeoffs you can make without sacrificing performance. FFS if you're actually doing SIMD as you claim then you know full well that it's entirely incompatible with anything above an std::vector, which is just a more noisy (and slower, thanks to O(n) size adjustments) version of a regular C array.

Not an argument

It's an hour of c++ shottery, that supposedly contains a benchmark hidden in it somewhere. The benchmark probably shows that when you write optimized code in c++ and unoptimized c code, c++ wins. Post the fucking benchmark or get out.

int main ( ) {
int typename;
return 0;
}
is a valid C program and is not a valid C++ program.

C++
Javascript

C++ is better just because polymorphism.

Both are unsafe and using these languages to develop new software should be outlawed.

What should be used instead? Scheme? HAHAHAHAHAHAHAAHAHAHAH

scheme isn't a safe language either really, it still has state, and it has no type checking. What you're looking for is ATS, manual memory management, full type safety, unboxed datastructures, etc: en.wikipedia.org/wiki/ATS_(programming_language)

Dumb citycucks

C, just because you don't have to consult the spec every time you move onto the next line of code
function pointers in C are literally more convenient than any niggermorphism you can get in C++.

...

oh okay, thank you reddit for another enlightened contrarian statistic based argument. kill yourself faggot

This. WTF? What's wrong with this place?

I sure love getting into accidents on my bicycle, I enjoy going fast and getting hurt. Going full speed down a sloped freeway to crash into a curb sounds like my kind of a good time.

Attached: .jpg (960x636, 85.44K)

in a few posts someone's going to explain that risk homeostasis means that the benefits of a better language than C or C++ are lost in the more reckless code that you write.
"Since I'm writing Ada, I'll do a 70 in this 45."

...

nah dude I do it for fun, I like getting injured. I believe you had confused my statements for sarcasm.

It's easy to imitate templates in C11, though. You'll just need to do a preprocessing tool in the language of your choice.

...

imagein the prog prowess u acheev when u turn a few million juden kids into lampshades and soap bars after summoning a bunch of pagan deitys into ur bodie.

java

max.c+---------------------------+| #define _TYPE int || #include "max_template.c" || #undef _TYPE || #define _TYPE double || #include "max_template.c" |+---------------------------+max.h+---------------------------------------------------+| #pragma once || || #define _TYPE int || #include "max_template.h" || #undef _TYPE || #define _TYPE double || #include "max_template.h" || || #define max(a, b) _Generic((a), \ || int: _int_max((a), (b)), \ || double: _double_max((a), (b))) |+---------------------------------------------------+max.template.c+----------------------------------------+| #include "template_common.h" || || _TYPE FUNC_NAME(max)(_TYPE a, _TYPE b) || { || return a > b ? a : b; || } |+----------------------------------------+max.template.h+-----------------------------------------+| #include "template_common.h" || || _TYPE FUNC_NAME(max)(_TYPE a, _TYPE b); |+-----------------------------------------+template_common.h+----------------------------------------------------------+| #define FUNC_NAME(name) _FUNC_NAME(name, _TYPE) || #define _FUNC_NAME(name, type) __FUNC_NAME(name, type) || #define __FUNC_NAME(name, type) _ ## type ## _ ## name |+----------------------------------------------------------+
Just gotta make a tool to automatize the creation.

hey hug you too pal
I hope your SAN points trip and fall down the stairs
this kind of shit doesn't create "C with Templates"; it creates "a language nobody knows" and "a project that will be immediately rewritten to the sound of angry curses of your name".
This is code. Code has bugs. This therefore will have bugs. Nobody wants to troubleshoot that shit.

That's why you automatize it and just have to write the "max_template.c" file. Templates are retarded, anyway; trying to solve genericity with metaprogramming lead to more horror than the C preprocessor could ever produce (which is pretty horrible, already).

Entirely inadequate comparison

I think there are a few C coders who are good enough to make money in embedded. I can do it, but I always wind up rewriting C++ language facilities inside it. I make good money as a C++ consultant and it's a much easier language to write effective, mid-sized programs in.

GCC

void func_int(int stuff);void func_float(float stuff);
As simple as that. Only thing C++ does is making it broken and removing requirement for _datatype.

lol'd
>C++: just implement operator< for the type and use std::max. You get std::min and std::sort (among others) for free as a bonus.
which can't be overloaded in C, then manually insert your special case into a _Generic abomination in some header file you shouldn't need to touch. You get nothing else.


void func_int_int_int(int stuff1, int stuff2, int stuff3);void func_float_int_int(float stuff1, int stuff2, int stuff3);void func_int_float_int(int stuff1, float stuff2, int stuff3);void func_float_float_int(float stuff1, float stuff2, int stuff3);void func_int_int_float(int stuff1, int stuff2, float stuff3);void func_float_int_float(float stuff1, int stuff2, float stuff3);void func_int_float_float(int stuff1, float stuff2, float stuff3);void func_float_float_float(float stuff1, float stuff2, float stuff3); template void func(T1 stuff1, T2 stuff2, T3 stuff3);

:^)

gas the bikes race car now

Ada has 'Max and 'Min attributes for every scalar type, but you can use a generic if you need it for other types. Ada generics have to be explicitly instantiated and the rationale explains why it was done that way.

archive.adaic.com/standards/83rat/html/ratl-12-04.html

with Ada.Text_IO, Ada.Integer_Text_IO;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Max is generic type T() is limited private; with function ">"(X, Y : T) return Boolean is ; function Generic_Max(X, Y : T) return T; function Generic_Max(X, Y : T) return T is (if X > Y then X else Y); function Max is new Generic_Max(String); function Max is new Generic_Max(Integer); function Max is new Generic_Max(Float); function Min is new Generic_Max(String, ">" => "

Car doesn't rhyme with war ESL faggot.

They're slant rhymes. See eg m.poemhunter.com/poem/church-going/

C is for feminine soyboys, C++ is for true programmers, as illustrated by pic related.

Attached: C-C .png (785x678, 463.24K)

No. When used the same way, they produce the same code. The only reason that C++ would be slower is that you can't hand-optimize the STL. Then again, you had to write all of that code by hand in C. Every time you want a resizable array in C, you have to reinvent it.

That said, C is a shit language and C++ was garbage bolted onto C. Which language is designed better? C++. Anything that stands with a foundation of shit is better than the shit it is built upon.

C: a worthless whore who looks pretty
C++: probably a mechanic; maybe a little mentally ill, but has more human capital than "having a vagina"

What did the thesaurus brainlet mean by this?

It doesn't have a vagina, user.

I think he meant to say that he was whining about people even having the opportunity to choose between programming languages, and do personal projects, as he himself is wage cucking and has no free time left whatsoever.

C++ is just a worse version of D

top cake

into the trash it goes

C++17 if you can get away with it.

If you hate GC use Rust, it's still better than the abortion that is C++