Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit: Watch C++ video for better understanding #5

Open
7 tasks done
apslight opened this issue Mar 30, 2018 · 6 comments
Open
7 tasks done

Revisit: Watch C++ video for better understanding #5

apslight opened this issue Mar 30, 2018 · 6 comments

Comments

@apslight
Copy link
Owner

apslight commented Mar 30, 2018

@apslight
Copy link
Owner Author

apslight commented Mar 31, 2018

STL Algorithms in Action : STL Algorithms and their everyday applications

This information is important for every developer because it help developer to write better code.
There are 5 main section of STL library that are :

  • Non-modifying sequence operation
  • Mutating sequence operation
  • Sorted and related operation
  • General numeric operations
  • General C algorithms.

for_each and transform() are very similar except completely different. The difference is that for_each discards the operation's return value, while transform copies the return value to an element in the output range.
accumulate differ from for_each in that the algorithms carries a value than a function object.

Sorting Algorithms contains: sort , stable_sort , partial_sort, partial_sort_copy.
Sorta-sort Algorithms contains: nth element: reorder sequence such that all item before nth element are less and other are not less, partition: reorder sequence such that all item before partition point are less and other are not less, partition_copy, stable_partition.

@apslight
Copy link
Owner Author

apslight commented Mar 31, 2018

All your tests are terrible: Tales from the trenches.

There are 5 properties of good test:
Correctness: Test must verify the requirement of the system are met, tests that actually execute real scenario.
Readability: Test should be obvious for future reader(including yourself). Avoid too much boilerplate and other discussion. Keep enough context for the reader.
Completeness: Include simple basic test but also include edge test. Make sure that you only test that thing that you are responsible for.
Demonstrability: Test should serve as demonstration of how the API works.
Resilience: It should not be flaky test, brittle tests, tests that depends upon execution ordering, mocks with deep dependence upon underlying API’s. It should be hermetic tests, only breaks when there is an unacceptable behaviour changes.

@apslight
Copy link
Owner Author

apslight commented Mar 31, 2018

Stop teaching C

Many C-isms are bad C++:

  • A collection of functions with related names is not as good as a class
  • No RAII
  • No iterators
  • Less type safety

It would be better if you adopt these four changes:

  • “string” is a thing, not a bunch of characters where the last one has a special value
  • “vector” is a thing
  • Operator overloads are intuitive
  • You haven’t had to teach destructors or memory cleanup yet

What make C++ C++ are: User defined types (objects and classes), Scope, Using templates, Standard library, const, Exceptions, Lambdas. C is not prerequisite for C++, you can directly learn C++. It's become simpler for them to learn c++. They will be missing some skills but overall, they will be better C++ programmer.

@apslight
Copy link
Owner Author

Writing Good C++14

The problem is many people use C++ in archaic and foreign style. Provide coding guidelines supported by GSL and analysis tool help us progress from older styles.

Some rules using GSL :

  • Never transfer ownership by raw pointer
  • Declare a pointer that may not be the nullptr as not_null
  • Do not pass an array as a single pointer.

Core Rules of coding guideline:

  • No resource leaks
  • No dangling pointers
  • No type violations through pointers

There are too many rules but the idea is you shouldn’t know the rules, the tools know the rules. We aim to change the way we write code by taking help of rules, tools, review, comment and editor.

The core guidelines and a guideline support library reference implementation will be open source projects freely available on all major platforms (initially, GCC, Clang, and Microsoft).

@apslight
Copy link
Owner Author

Back to the Basics! Essentials of Modern C++ Style

  • Default means don’t overthink it and don’t optimize prematurely.

  • Write make_unique(by default) and make_shared(when needed) instead of *, new and delete.

    • Never pass smart pointers (by value or by reference) unless you actually want to manipulate the pointer -> store, change, or let go of a reference.
    • Express ownership using unique_ptr wherever possible including when you don’t know whether the object will actually ever be shared.
    • Else use make_shared up front wherever possible, if object will be shared.
  • Prefer auto x = expr; by default on variable declarations because it offers so much correctness, clarity, maintainability, performance and simplicity but don’t resisted using auto.

  • Don’t assume that the cost of construction is the same as assignment.

  • Use forwarding reference.

@apslight
Copy link
Owner Author

apslight commented Mar 31, 2018

Essence of C++

Fundamentally, if you understand vector, you understand C++.

Type safety and resource safety are key design aims for a program. These aims must be met without limiting the range of applications and without imposing significant run-time or space overheads.

For general, simple, implicit, and efficient resource management we should follow some techniques that are: Store data in containers, Manage all resources with resource handles, Use “smart pointers”, Plug in a garbage collector.

Discuss OOP, inheritance, Generic Programming(templates and concepts) and challenges.

In this presentation his aim is not so much to present novel features and technique, but to explore how C++’s feature set supports a new and more effective design and programming style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant