Write secure code with assertions (assert and static_assert) | Modern Cpp Series Ep. 87

  Рет қаралды 4,890

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 21
@MartinME3
@MartinME3 2 ай бұрын
A try/exception clause block video would be nice! Great great video series!!!
@MikeShah
@MikeShah 2 ай бұрын
Cheers! Indeed, that's on the todo list!
@__hannibaalbarca__
@__hannibaalbarca__ Жыл бұрын
Thanks; Very Kind small examples “ the big things came out of tiny things”. Thanks again for the methodology of how to understand and learn something.
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@enriquemorenoroldan8402
@enriquemorenoroldan8402 2 жыл бұрын
Thanks again for your videos Mike!
@MikeShah
@MikeShah 2 жыл бұрын
Cheers!
@reptilicusrex4748
@reptilicusrex4748 Жыл бұрын
Thanks for the great explanation.
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@GaryChike
@GaryChike 2 жыл бұрын
It's just a matter of time before someone comes up with a programming language called "42" 😂 Great explanation Mike!
@MikeShah
@MikeShah 2 жыл бұрын
Cheers! Thanks Gary 😁
@VoidloniXaarii
@VoidloniXaarii Жыл бұрын
Thank you very much. Sorry if stupid question, how do these asserts relate to the ones in Google's test framework asserts... If any?
@MikeShah
@MikeShah Жыл бұрын
Similar idea, you want to assert and catch during testing things that must be true. Google provides an abstraction layer to help make some of the testing ideas more clear.
@VoidloniXaarii
@VoidloniXaarii Жыл бұрын
@@MikeShah thank you!
@VoidloniXaarii
@VoidloniXaarii Жыл бұрын
@@MikeShah thank you so much for all your enlightened teachings!
@bsdooby
@bsdooby 2 жыл бұрын
How do you setup your C++ code such that it can be tested on an ad hoc basis? E.g. Java has maven with test profiles; I struggle a bit doing something similar with C++...I guess one has to resort to CMake (or similar build environments) to invoke test suits (?) And D has compiler switches which invoke unit tests.
@MikeShah
@MikeShah 2 жыл бұрын
Previously I've used Catch framework with a CMake to do a test build, alongside a debug and release build. D's compiler switches are a 'killer feature' in my opinion, and one of the reason you are seeing me make the DLang series :) Visual Studio is one IDE I know about that also has built-in test frameworks to emulate what D has (and essentially what Catch does as well). See an example here: docs.microsoft.com/en-us/visualstudio/test/writing-unit-tests-for-c-cpp?view=vs-2022
@bsdooby
@bsdooby 2 жыл бұрын
Thanks for these valuable hints! Will def. check them out.
@berlin-unlocked
@berlin-unlocked 10 ай бұрын
Great video! But) From my experience in the field, c assert() is a bad thing for the project. In Release variant asserts are compiled out, so you miss the checks. The checks were performed only in Debug variant. So you have different code between Debug and Release variants. C asserts can work good only in a big company, where they do extensive testing for debug AND release variants. My best practice: just do not use c asserts. If there is a suspect for an existence of an error, perform a mature param check with if (...) {print log, handle error / throw exception} and just avoid using c asserts... But static_assert is a great stuff)
@MikeShah
@MikeShah 10 ай бұрын
Agree to prefer static_assert when possible. Assert is for developers during development, at run-time in release if errors are handled this is where exceptions are useful. May depend on domain, but I recommend liberal use of assertions -- and you are correct we do not typically want an assert in release that crahes the program 🙂
@axelBr1
@axelBr1 4 ай бұрын
Came to the comments to see if anyone pointed out that asserts are only compiled in for debug code. I still keep using them though as during development I want the application to fail and force me to fix it. Of course it does mean that you end up having the assert followed by error checking and handling code. But then again, all my coding is for personal use.
@despender2678
@despender2678 2 ай бұрын
@@axelBr1 In many programming languages ​​and development environments, assert is disabled by default in release mode. It can be manually enabled in release mode (properties->C/C++->preprocessor->preprocessor definition->remove NDEBUG if in VS). After this, assert will work in release build mode. Before doing this, it's advisable to check whether something is tied to NDEBUG, if it's in the project (although according to the C standard it's intended exclusively for assert). If so, you can do it through define your assert.
auto in Modern C++ | Modern Cpp Series Ep. 88
10:20
Mike Shah
Рет қаралды 3,2 М.
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 17 МЛН
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 2,7 МЛН
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
BETTER Header Files and Preprocessor Debugging
24:26
The Cherno
Рет қаралды 74 М.
Can I Handle Exceptions with Try Catch in C? (setjmp, longjmp)
11:13
C++ Insights - Episode 19: How variadic templates work
13:05
Andreas Fertig
Рет қаралды 3,9 М.
Find bugs faster using assertions.
5:23
Jacob Sorber
Рет қаралды 18 М.
Introduction to constexpr | Modern Cpp Series Ep. 86
10:56
Mike Shah
Рет қаралды 12 М.
ENUMS in every programming language (All you need to know)
24:38
Safety in modern C++ and how to teach it
17:52
The Cherno
Рет қаралды 140 М.
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 17 МЛН