[–]▶ No.1004454>>1005557 >>1005896 >>1007058 >>1007377 >>1009684 >>1015021 [Watch Thread][Show All Posts]
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 <vector>, <list>, <deque>, <set> and <stack>, 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.
▶ No.1004467>>1004469 >>1004474 >>1011286 >>1012830
Which is better a car or a bike?
▶ No.1004469
▶ No.1004474>>1005951 >>1009746
>>1004467
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.
▶ No.1004475>>1004481 >>1005828 >>1015076
>Objectively which language is better: C or C++?
How banal.
>I always felt torn that I learned C++ before I knew C
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.
▶ No.1004481>>1004486 >>1004489 >>1005582 >>1005683 >>1010442
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?
>>1004475
K
▶ No.1004486
>>1004481
Because C++ exists
▶ No.1004489
>>1004481
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++.
▶ No.1005532>>1005539
▶ No.1005539>>1005545
>>1005532
> t. Microshit shill
▶ No.1005545
▶ No.1005554
▶ No.1005557
>>1004454 (OP)
>Objectively which language is better: C or C++?
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.
▶ No.1005559
You'll probably end up using both if you end up working in software engineer or in open source.
▶ No.1005582>>1005615 >>1005714 >>1005897
>>1004481
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.
▶ No.1005615>>1005666
>>1005582
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.
▶ No.1005666
>>1005615
>le zero cost abstractions
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.
▶ No.1005683
>>1004481
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.
▶ No.1005714
>>1005582
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.
▶ No.1005824
> Vastly different philosophies. Both of the languages themselves, and the standards committees in charge of them.
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.
> I can't make a decision on which to use for my personal projects.
Do what's comfortable. I've written "C++" code that is almost all C except it uses one C++ feature where I needed it.
▶ No.1005828>>1005900 >>1006763
>>1004475
put your thesaurus away
▶ No.1005896
▶ No.1005897>>1005937
>>1005582
>what is template metaprogramming
Templates allow c++ to be turing complete.
▶ No.1005900
>>1005828
You mean my onomasticon? I will not.
▶ No.1005934>>1007350
>C++ is slowwww
>C is fasterrrrrrrrrr
No honey
https://www.youtube.com/watch?v=zBkNBP00wJE
▶ No.1005935
>Asks "Objectively which language is better: C or C++?"
>proceeds to answer own question
>doesn't realize
>>>/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
▶ No.1005937>>1005940 >>1006073
>>1005897
They also encourage your code to become an unreadable pile of bloat and cancer worse than feminism and communism combined.
▶ No.1005940
>>1005937
Still more readable than rust :^)
▶ No.1005951>>1007401 >>1010423
>>1004474
>car
>safer than bike
Dumb citycucks
▶ No.1006019>>1006220 >>1006267 >>1015372
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.
▶ No.1006073
>>1005937
Fucking turing complete. Do you understand?
▶ No.1006120
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?
▶ No.1006179
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.
▶ No.1006220
>>1006019
If you don't know why you should use a certain standard you're better off playing with the other C VARP monkeys.
▶ No.1006267
▶ No.1006279>>1006281 >>1007379
C for simple fast stuff, D for big OOP stuff.
C++ belongs in the trash.
▶ No.1006281>>1006294
>>1006279
if you're using D at all, why not use betterC for "simple fast stuff"?
▶ No.1006294
>>1006281
BetterC just complicates things, if I want simple fast stuff I'd rather not have to deal with the differences between two languages.
▶ No.1006763
>>1005828
>becoming this banal-pained
▶ No.1007058
>>1004454 (OP)
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++
▶ No.1007350>>1007773
▶ No.1007377>>1007398 >>1007424
>>1004454 (OP)
>C has WAYY less bloat and is able to run faster code
Objectively incorrect, C++ is backwards compatibly linkable with C, so it's at least as fast as C.
>(while not hard to implement in C or C++ by hand)
Sure, you'll just end up with severely underperforming code that's not worth using at all.
>which is the language that's designed better.
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.
▶ No.1007379
>>1006279
>garbage collection
LOL
▶ No.1007398>>1007406
>>1007377
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++).
▶ No.1007401>>1009715 >>1009745 >>1010423
>>1005951
>Having a metal box with designed weak points so it can absorb most of the impact before transmitting the force to the driver
vs
>The driver is the chassis
Yep, they're safer.
▶ No.1007406>>1007424
>>1007398
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.
▶ No.1007424>>1007516
>>1007377
>>C has WAYY less bloat and is able to run faster code
>Objectively incorrect, C++ is backwards compatibly linkable with C, so it's at least as fast as C.
In much the same way that you can trivially link Visual Basic 6 to C which makes it at least as fast as C
>>(while not hard to implement in C or C++ by hand)
>Sure, you'll just end up with severely underperforming code that's not worth using at all.
Just like in all those other cases where excessively generalized solutions to highly specific problems are faster
>>which is the language that's designed better.
>C++, its standard library laughably dwarfs C's meaning you can better express your intentions in code.
Perls standard library dwarfs C++'s, making it clearly the bestest mostliest superiorest language
>>1007406
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.
▶ No.1007516>>1007530
>>1007424
>Visual Basic
>Perl
Not a superset of C.
>generalized solutions
Templates that replace runtime type checks are considerably faster, yes. And that's just one example.
>impossible to write a compiler for your language
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?
▶ No.1007530>>1007535
>>1007516
>>Visual Basic
>>Perl
>Not a superset of C.
Neither is C++
>Templates that replace runtime type checks are considerably faster, yes. And that's just one example.
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.
>Or are hugely underperforming DIY solutions a thing among C programmers?
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.
▶ No.1007535>>1007557 >>1007750 >>1008292
>>1007530
>Neither is C++
C++ is literally designed as a superset to C and to replace it in most cases.
>Dream on.
for_each, find_all, partition, lambdas, etc... All of this saves hours of manual labor. Again DIY foolery.
>ad hominem
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.
>specific muh specific and complex
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++?
▶ No.1007557>>1007687
>>1007535
>you're always writing C++
C++ contains a stale, incompatible variant of C. You stop writing C++ as soon as you don't explicitly cast malloc()'s return.
▶ No.1007579
▶ No.1007687>>1007693
>>1007557
>stale
There's nothing noteworthy in C11.
>don't explicitly cast malloc()'s return
And that's a good thing
▶ No.1007693
>>1007687
>you're always writing C++
>it's a good thing that you're not always writing C++
sour grapes.
▶ No.1007750
>>1007535
>C++ is literally designed as a superset to C and to replace it in most cases.
; gcc -c -x c++ -std=c++17 foo.cpp
foo.cpp:6:1: sorry, unimplemented: non-trivial designated initializers not supported
};
^
; gcc -c -x c foo.cpp
; cat foo.cpp
struct {
int i, j;
} x[] = {
{ .i = 1 },
{ .j = 2 },
};
And Microsoft has a C compiler because they sort of support C89 but not really.
>for_each, find_all, partition, lambdas, etc... All of this saves hours of manual labor. Again DIY foolery
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.
>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.
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.
>Are you going to keep going off on a tangent with your anecdotal edge cases or just admit the statistics are right about C++?
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.
▶ No.1007773>>1007831
▶ No.1007831
>>1007773
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.
▶ No.1008292
>>1007535
>C++ is literally designed as a superset to C
int main ( ) {
int typename;
return 0;
}
is a valid C program and is not a valid C++ program.
▶ No.1009198
>objecitvely
C++
>which one is better
Javascript
▶ No.1009684>>1009743
>>1004454 (OP)
C++ is better just because polymorphism.
▶ No.1009686>>1009691
Both are unsafe and using these languages to develop new software should be outlawed.
▶ No.1009691>>1009709
>>1009686
What should be used instead? Scheme? HAHAHAHAHAHAHAAHAHAHAH
▶ No.1009709
>>1009691
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: https://en.wikipedia.org/wiki/ATS_%28programming_language%29
▶ No.1009715>>1010423
>>1007401
>getting in accidents
>safe
Dumb citycucks
▶ No.1009743
>>1009684
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++.
▶ No.1009745
>>1007401
>hurr durr im an NPC I get into accidents therefore all that matters is how much armor i have
▶ No.1009746>>1009851
>>1004474
>botnetmobile is more safe than biking or merely sitting in your basement
oh okay, thank you reddit for another enlightened contrarian statistic based argument. kill yourself faggot
▶ No.1009851
>>1009746
This. WTF? What's wrong with this place?
▶ No.1010423>>1010428
>>1009715
>>1007401
>>1005951
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.
▶ No.1010428>>1010437
>>1010423
>nigger doesn't know how to ride a bicycle and crashes on everything in sight
▶ No.1010430>>1010433
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."
▶ No.1010433
>>1010430
>concerned about memory safety
>learn Rust because also concerned about the evils of capitalism
>rust code is 300% bloated due to lazy memory use, causes performance issues on servers as they're starved of FS cache
▶ No.1010437
>>1010428
nah dude I do it for fun, I like getting injured. I believe you had confused my statements for sarcasm.
▶ No.1010442>>1010443
>>1004481
It's easy to imitate templates in C11, though. You'll just need to do a preprocessing tool in the language of your choice.
▶ No.1010443>>1010444 >>1010450
>>1010442
>it's easy to imitate templates
>you just gotta summon an incarnation of Cthulhu into your body
>after murdering a few hundred children
▶ No.1010444
>>1010443
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.
▶ No.1010447
▶ No.1010450>>1010452 >>1012807 >>1012825 >>1012835
>>1010443
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.
▶ No.1010452>>1010459
>>1010450
>deliberately showing someone a lovecraftian horror
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.
▶ No.1010459
>>1010452
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).
▶ No.1011286
>>1004467
> Which is better a car or a bike?
Entirely inadequate comparison
▶ No.1011343
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.
▶ No.1011997
▶ No.1012807>>1012825
>>1010450
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.
▶ No.1012825
>>1010450
lol'd
>need to implement max for new struct-based datatype
>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.
<C: implement max for the type because your "template" uses operator> 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.
>>1012807
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<typename T1, typename T2, typename T3> void func(T1 stuff1, T2 stuff2, T3 stuff3);
:^)
▶ No.1012830>>1012996
>>1004467
gas the bikes race car now
▶ No.1012835
>>1010450
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.
http://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, ">" => "<");
begin
Put(Max("abc", "def"));
Put(Min("ABC", "DEF"));
Put(Max(123, 456));
Put(Integer'Max(456, 789)); -- built-in max function
New_Line;
end Max;
▶ No.1012996>>1013110
>>1012830
Car doesn't rhyme with war ESL faggot.
▶ No.1013110
▶ No.1014954>>1015022 >>1015332
C is for feminine soyboys, C++ is for true programmers, as illustrated by pic related.
▶ No.1015021>>1015350 >>1022791
>>1004454 (OP)
>able to run faster code
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.
▶ No.1015022>>1015080
>>1014954
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"
▶ No.1015076>>1015328
>>1004475
>personal projects
>proletarian
What did the thesaurus brainlet mean by this?
▶ No.1015080
>>1015022
It doesn't have a vagina, anon.
▶ No.1015328
>>1015076
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.
▶ No.1015332>>1015352
>>1014954
C++ is just a worse version of D
▶ No.1015350
>>1015021
>C++
>designed
top cake
▶ No.1015352>>1015441
>>1015332
>D
>garbage collected
into the trash it goes
▶ No.1015372
>>1006019
C++17 if you can get away with it.
▶ No.1015441
>>1015352
If you hate GC use Rust, it's still better than the abortion that is C++
>Inb4 muh SJWs
▶ No.1022791
>>1015021
>Anything that stands with a foundation of shit is better than the shit it is built upon.
That's actually a very nice way to put it. I'm stealing this.
There is no denying that C++ has some serious flaws, but overall, it's objectively a better language with respect to C. Anyone who still denies this in 2019 is delusional.