First, I welcome back! (?). Secondly, the technical content of this post was generated using ChatGPT! Now, what is ChatGPT? Well, I asked the following:
I wrote on the presentation of the post that the content were generated using ChatGPT, then, which is the answer for the reader about what is ChatGPT?
And, ChatGPT answer to me this:
ChatGPT is a large language model developed by OpenAI. It's trained on a massive dataset of text and is capable of generating human-like text. It's been used in a wide range of applications, such as writing code, composing poetry, and even writing news articles. In this case, it was used to generate technical guidelines and a funny closing for a blog post about good practices in modern C++.
So, my job here is done.. just asking questions and giving answers! Well, not more to say..here the 10 good practices to code using modern code C++:
The Top 10 Commandments of Modern C++ Coding:
- Thou shalt not mix tabs and spaces (lest ye be cast into the indentation abyss).
- Thou shalt always use nullptr instead of NULL (for the love of all that is holy).
- Thou shalt not use raw pointers unless thou art prepared to smite memory leaks with the wrath of a thousand smart pointers.
- Thou shalt not use C-style casts (thou shalt use static_cast, dynamic_cast, and const_cast instead).
- Thou shalt always initialize variables upon creation (lest thou leave them in a state of eternal mystery).
- Thou shalt not use the goto statement (it is an abomination unto the language).
- Thou shalt always use const when appropriate (lest ye accidentally change something that should not be changed).
- Thou shalt always use auto when appropriate (for the sake of thy sanity).
- Thou shalt not fear the Standard Template Library (for it is thy friend).
- And lastly, thou shalt not forget to have fun (for coding is not just a job, but a joy).
And a bonus one: 11. Thou shalt not use a single line of code without a proper comment explaining its purpose (lest thou confuse thy fellow coders and thy future self).
Remember, these commandments are not just suggestions, but a sacred code for all C++ developers to live by. Follow them and thou shall code like a pro!
The previous content were generated with the following question:
Can you write a funny and technical entry for my blog located in ecode.dev regarding good practices at using modern C++? The post should be enumerating at least 10 important points for developers
See? It is amazing!! Now, those ones were so general that I push a little bit asking the following:
umm I dont want commandments, I prefer technical guiding
And again, this is the answer:
Sure, here's a list of 10 technical guidelines for using modern C++:
- Always use C++11 or later. This version of the language brings many improvements and new features that will make your coding experience much more pleasant.
- Use smart pointers to manage memory. Smart pointers, such as
std::unique_ptr
andstd::shared_ptr
, are a safer and more efficient way to manage memory compared to raw pointers. - Use
const
whenever possible. This will help prevent accidental modification of data and improve performance. - Use
auto
to deduce variable types. This reduces verbosity and improves readability of your code. - Use the
auto
keyword for range-based for loops. This greatly simplifies iteration over containers. - Use template metaprogramming (TMP) judiciously. TMP can make your code more efficient, but it can also make it harder to understand and maintain.
- Prefer standard library functions over writing your own. The standard library provides high-quality, well-tested implementations of many common algorithms and data structures.
- Use exceptions for error handling. Exceptions provide a more robust and expressive way to handle errors compared to traditional error codes.
- Use
std::string
instead ofchar*
orchar[]
.std::string
offers many advantages over traditional C-style strings, such as automatic memory management and a rich set of member functions. - Use the
final
keyword to prevent class inheritance. This can help prevent unexpected behavior and improve performance.
By following these guidelines, you can take full advantage of the power and expressiveness of modern C++ while also maintaining high levels of readability and maintainability in your code.
My last question regarding the same topic, was this:
I like those, but could include more things focused on C++ 14 and c++ 17?
Sure, here are some additional guidelines for using C++14 and C++17 specifically:
- Use C++14's
std::make_unique
andstd::make_shared
for creating smart pointers. These functions provide a more convenient and safer way to create smart pointers compared to usingnew
. - Use C++14's
std::exchange
for atomic operations. This function provides a more readable and efficient way to perform atomic operations compared to usingstd::atomic
directly. - Use C++14's
std::is_final
to check if a class is final. This is a more readable and expressive way to check if a class is final, compared to using thefinal
keyword. - Use C++17's
std::optional
for optional values.std::optional
provides a safer and more expressive way to handle optional values compared to usingnullptr
orstd::unique_ptr
with a sentinel value. - Use C++17's
std::variant
for discriminated unions.std::variant
provides a safer and more expressive way to implement discriminated unions compared to usingstd::tuple
andstd::visit
. - Use C++17's
std::string_view
for working with string data.std::string_view
provides a more efficient and safer way to work with string data compared to usingconst char*
orstd::string
. - Use C++17's
std::invoke
for calling callable objects.std::invoke
provides a more readable and general way to call callable objects compared to usingstd::bind
orstd::mem_fn
. - Use C++17's
std::apply
for passing tuple elements as function arguments.std::apply
provides a more readable and general way to pass tuple elements as function arguments compared to usingstd::tuple_cat
orstd::tuple_element
. - Use C++17's
std::filesystem
for working with the file system.std::filesystem
provides a more modern and expressive way to work with the file system compared to usingstd::experimental::filesystem
or platform-specific libraries. - Use C++17's
std::any
for holding any type of value.std::any
provides a more general and efficient way to hold any type of value compared to usingvoid*
orstd::function
.
By following these guidelines, you can take full advantage of the new features and improvements provided by C++14 and C++17, and write more expressive, efficient, and maintainable code.
The last part, giving that is the same, then, I asked this:
would you change this phrase "By following these guidelines, you can take full advantage of the new features and improvements provided by C++14 and C++17, and write more expressive, efficient, and maintainable code." to look different than previous one... Also, I need a funny closing for the post
And the answer is epic:
Sure, here's a revised closing for the post:
"By adhering to these technical guidelines, you'll be tapping into the full potential of C++14 and C++17. Your code will be expressive, efficient, and a joy to maintain. So go forth and write beautiful, modern C++ code! Just remember, with great power comes great responsibility, so use your newfound C++ skills for good and not for evil."
As for a funny closing, here's one: "And don't forget, a good C++ developer always 'throws' their exceptions, not 'catch' them."
For now, I am totally surprised with the full potential of ChatGPT for text-based content in many ways! No, this part wasn't written by ChatGPT (wasn't?) 🤖
From a geek to geeks.