From 7716d2a5d3d6df7380f0ad9bed46c9adee50d2a3 Mon Sep 17 00:00:00 2001 From: "easyaspi314 (Devin)" Date: Wed, 24 Nov 2021 19:46:11 -0500 Subject: [PATCH 1/2] c_vs_cpp: Mention type checking, raii, ffi pros to C: - only does what you say - easy to mix with other languages pros to C++: - RAII prevents resource leaks - stricter syntax prevents subtle bugs by easyaspi314#1497 --- c_vs_cpp.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/c_vs_cpp.md b/c_vs_cpp.md index 66588da..5b66396 100644 --- a/c_vs_cpp.md +++ b/c_vs_cpp.md @@ -8,18 +8,22 @@ There are good reasons for using both languages: ✅ relatively low-level language ✅ much simpler language (no classes, templates, ...) ✅ portable to a wide variety of systems +✅ only does what you say +✅ easy to mix with other languages ## Reasons To Use C++ ?inline ✅ lots of helpful abstractions (classes, templates, ...) ✅ feature-rich language (function overloads, `constexpr`, ...) ✅ extensive standard library +✅ RAII prevents resource leaks +✅ stricter syntax prevents subtle bugs ## Which Is Faster? Neither language is inherently faster than the other. In modern compilers, the exact same optimizer is used for both languages. Certain high-level C++ features can make it easy to inadvertently write inefficient code (e.g. -innocent looking code performing large copies). +innocent looking code performing large copies or complicated RAII setups). One notable difference between the two languages is their standard libraries' string representation: C strings, while simple, are highly inefficient. From 3dfe495e6c3a332906e87acbd115bcfe9337b782 Mon Sep 17 00:00:00 2001 From: "easyaspi314 (Devin)" Date: Wed, 24 Nov 2021 21:32:23 -0500 Subject: [PATCH 2/2] c_vs_cpp: rewrite the which is faster part Points made: - C++'s standard library avoids inefficient DIY code - C++ uses a more efficient string representation - C++ can hide many slow operations behind abstractions Also uses simpler wording. --easyaspi314#1497 --- c_vs_cpp.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/c_vs_cpp.md b/c_vs_cpp.md index 5b66396..f77a262 100644 --- a/c_vs_cpp.md +++ b/c_vs_cpp.md @@ -16,18 +16,19 @@ There are good reasons for using both languages: ✅ lots of helpful abstractions (classes, templates, ...) ✅ feature-rich language (function overloads, `constexpr`, ...) ✅ extensive standard library +✅ stricter syntax ✅ RAII prevents resource leaks -✅ stricter syntax prevents subtle bugs ## Which Is Faster? Neither language is inherently faster than the other. In modern compilers, the exact same optimizer is used for both languages. -Certain high-level C++ features can make it easy to inadvertently write inefficient code (e.g. -innocent looking code performing large copies or complicated RAII setups). -One notable difference between the two languages is their standard libraries' string representation: -C strings, while simple, are highly inefficient. +C++ mostly benefits from its robust standard library, reducing naïve DIY algorithms and +boilerplate significantly. It also uses an *exponentially* more efficient string representation +than C. +However, C++ can also hide slow tasks (e.g. allocations, large copies, exceptions, and RTTI +lookups) behind seemingly innocent code, all of which would be obvious in C. ## Conclusion Both languages can be equally fast, choose the right language for your job, and the language you enjoy working in. \ No newline at end of file