>learning C++
>tutorial teaches me a thing but then tells me I shouldn't ever use it because it's "risky"
Is it going to be like this all the way?
Learning C++
Other urls found in this thread:
en.wikipedia.org
twitter.com
>tutorial teaches me a thing but then tells me I shouldn't ever use it because it's "risky"
It's teaching you C++. Don't use it.
pretty much 90% of C++ and STL, but that tutorial probably sucks
Have you learned c? if you do, you'll have a better understanding of why things happen in c++.
>you can go 0 to 100 mph in 10 seconds in this car, but you are too stupid to do it in this moment and will kill you. Don't it.
>You have a gun. Don't use it to shoot yourself in the head.
/thread
Because you're going to see it in wild code.
>#define
can rape your code and you'll never figure it out by the error messages, use const/constexpr.
>new/delete malloc/calloc/realloc/free
are easy to fuck up when the complexity of your code increases. Use RAII and hide them in std::unique_ptr or some other class's constructor/destructor.
>unique_ptr(new thing(), new thing2(), new thing3())
exceptions can lead to memory leaks, just use make_unique
>typedef
is ugly and can't be templated, "using new_thing = old_type;" is clearer and better
>Type name();
Could be read as a function declaration rather than a variable declaration. Therefore will be. Worse
>int mian(){
>>std::string(foo);
>}
Not an error, is a variable declaration of a string foo rather than turning nonexistant foo into string. In real life:
>unique_lock(my_mutex)
Will declare a unique_lock called my_mutex rather than make a lock and pass it my_mutex. Enjoy spending hours finding this bug because you didn't write unique_lock my_lock{my_mutex}.
see en.wikipedia.org
>tl;dr use {} and not () for constructor invocations.
>multiple inheritances
A has children classes B and C that fuck into a grandchild class D. Does D inherit B::A or C::A? A rapes D and produces E. What A's does E now have?
>rand()
No, no, no. Use std::random_device or std::mt19937
>rand()%(b-a+1) + a
Oh fuck no. Use std::uniform_distribution{a,b}(std::random_device{})
>const_cast
Step away from the keyboard. Use mutable instead if you really need to change data in const functions.
I appreciate the write-up, but why do these shitty features even exist?
>>#define
C carry over. It's sometimes used by people to make language extensions
>>typedef
C carry over
>>malloc/calloc/realloc/free
C carry over
>>new/delete
You need to be able to allocate memory somehow. Just do it in a way that makes it impossible to forget to deallocate it.
>>rand()
C carry over
>>rand()%(b-a+1) + a
>>int{double{rand()}/RAND_MAX * (b-a+1) + .5} + a
Can't stop stupid people from being stupid.
>>const_cast
Some people like breaking stuff and seeing what happens
C++ was the first programming language I learned and it was the easiest.
Though I had lots of trouble with Java for some reason.
I have the same level of experience w/ the two languages and I agree
probably the verbosity of Java
>>#define
>can rape your code
How?
>C++ easier for you than java
I don't believe you. I started with java and it wasn't very hard for me. This easiest language for me has been python but java was second easiest. C and C++ have been very hard for me.
Functional vs. Object-oriented mah dude.
Y'all just think differently.
>mfw Visual Basic was the first language I learned
>mfw moved to C
>mfw have used a little of C++ features but still think as a functional programmer, not object-oriented
probably why I play with ucontrollers.
>>c++
>>not also object oriented
look at any decently sized project on github, c++ very much so Object Oriented
C++ is object oriented as well and I rarely write python programs in an object oriented fashion.
The tutorial is telling you that you're a retard who won't be able to use language features properly. It knows this because you're learning C++ from a tutorial. The only things you shouldn't use are the things that are deprecated. And don't use shit just because "wow this looks advanced it must be good", that's wrong in 100% of cases.
>#define true false
>#define i j
The preprocessor is not your friend.
>#define (you) pajeet
>#define spacing reddit
it's just a tool, you brainlet
>Book goes right through c++
>Very end of book "the std is largely non-thread safe"
>Has a short chapter on alternative libraries that cover 90% of the book material
>>#define spacing reddit
People have been double spacing quotes here since the beginning newfag.
Why do they even include that shit then? Just wastes some common sense naming
sure, now return to reddit
>look at me mommy
>im showing off what reddit has taught me about posting on Sup Forums
Backwards compatibility. Remember the troubles of python 2 -> python 3?
>>Very end of book "the std is largely non-thread safe"
It's thread safe enough to be usable.