diff --git a/README.md b/README.md index 818ef3c..9035250 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,29 @@ -# Q&A sessions +# Sesja pytań i odpowiedzi Coders School -## [Moduł 1](module1/) +## [Moduł 1](module1/index.pl.html) -### [Współpraca grupowa - Scrum](module1/scrum.md) +### [Współpraca grupowa - Scrum](module1/01_scrum.pl.md) -### [Konkurs STL](module1/konkurs.md) +### [Konkurs STL](module1/02_konkurs.pl.md) -### [Przykłady z Code Review](module1/code-review.md) +### [Przykłady z Code Review](module1/03_code-review.pl.md) -### [Pytania z kanału #powtórka](module1/repetition.md) +### [Pytania z kanału #powtórka](module1/04_repetition.pl.md) + +___ + +# Q&A Session + +## [Module 1](module1/index.en.html) + +### [Teamwork - Scrum](module1/01_scrum.en.md) + +### [STL contest](module1/02_konkurs.en.md) + +### [Examples from Code Review](module1/03_code-review.en.md) + +### [Questions from #powtórka channel](module1/04_repetition.en.md) \ No newline at end of file diff --git a/module1/01_scrum.en.md b/module1/01_scrum.en.md new file mode 100644 index 0000000..0fd5e27 --- /dev/null +++ b/module1/01_scrum.en.md @@ -0,0 +1,19 @@ + + +# Teamwork - Scrum + +___ + +## Teamwork - Scrum + +* [Scrum meetings](https://github.com/coders-school/qa-sessions/raw/master/module1/ScrumFramework.pdf) + +* [Scrum cheat sheet](https://github.com/coders-school/qa-sessions/raw/master/module1/sciaga_scrum.pdf) + +___ + +## Scrum - good practices + +* Daily meetings - organized to synchronize workflow, see how the work is going and in particular who needs a helping hand because he is stuck. +* Iterative approach - we deliver small bits of functionality. It is important to provide anything as soon as possible that causes even only one test to pass. Then everyone can build new functionalities on it. +* Retrospectives - the most important meeting in my opinion. It takes place after the iteration (sprint) is completed and the team pats their backs about how great it was, how much has been done and how it can be improved. In addition, the team throws in the worst epithets about the inability to cooperate, not making it on time and not planing its work correctly. After this meeting, conclusions must be formulated, what can be improved for better cooperation and actions to be done for each person. diff --git a/module1/scrum.md b/module1/01_scrum.pl.md similarity index 100% rename from module1/scrum.md rename to module1/01_scrum.pl.md diff --git a/module1/02_konkurs.en.md b/module1/02_konkurs.en.md new file mode 100644 index 0000000..403c627 --- /dev/null +++ b/module1/02_konkurs.en.md @@ -0,0 +1,35 @@ + + +# STL contest + +___ + +## STL contest + +Thank you very much for participating in the competition 🙂 The award for all participants is the 'STL Star' achievement. + +___ + +## Podium + +* 1st place (30 XP) + * Konkurs-coders-squad-9 + * My tu tylko po punkty +* 2nd place (20 XP) + * Diggers team + * Squad – 2 +* 3rd place (10 XP) + * StowarzyszenieTechnicznychLemingow + * very smart pointers + +___ + +## Make your repositories public and post them on the `#contest` channel 🙂 + +___ + +## Conclusions after the contest + +* Formulating tasks/requirements is an art. After all, there will always be many people who will be able to interpret the requirements differently than assumed by the author. I highly recommend this video +* As many coaches, as many opinions about the requirements +* As many coaches as many opinions about coding styles diff --git a/module1/konkurs.md b/module1/02_konkurs.pl.md similarity index 100% rename from module1/konkurs.md rename to module1/02_konkurs.pl.md diff --git a/module1/03_code-review.en.md b/module1/03_code-review.en.md new file mode 100644 index 0000000..0089152 --- /dev/null +++ b/module1/03_code-review.en.md @@ -0,0 +1,237 @@ + + +# Examples from Code Review + +___ + + +Example: + +```cpp +bool doesPasswordsMatch(const std::string& password, const std::string& repeatedPassword) { + if (password == repeatedPassword) { + return true; + } + return false; +} +``` + +Better: + + +```cpp +bool doesPasswordsMatch(const std::string& password, const std::string& repeatedPassword) { + return password == repeatedPassword; +} +``` + + +___ + + +Example: + +```cpp +std::string getErrorMessage(ErrorCode Error) { + switch (Error) { + case ErrorCode::Ok: + return "OK"; + break; + case ErrorCode::PasswordNeedsAtLeastNineCharacters: + return "Password Needs At Least Nine Characters"; + break; + case ErrorCode::PasswordNeedsAtLeastOneNumber: + return "Password Needs At Least One Number"; + break; + case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter: + return "Password Needs At Least One Special Character"; + break; + case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter: + return "Password Needs A Least One Uppercase Letter"; + break; + case ErrorCode::PasswordsDoesNotMatch: + return "Passwords Does Not Match"; + break; + default: + return "UNDEFINED ERROR"; + } + } + // What do you think about removing case ErrorCode::Ok: and putting it in default? + // Braces are not needed even for multiline cases. It's only matter of convention if you should apply them or not. They don't provide additional safety. + // We usually don't indent case and code inside namespace +``` + +___ + +Better?: + +```cpp +std::string getErrorMessage(ErrorCode error) { + switch (error) { + case ErrorCode::PasswordNeedsAtLeastNineCharacters: + return "Password Needs At Least Nine Characters"; + case ErrorCode::PasswordNeedsAtLeastOneNumber: + return "Password Needs At Least One Number"; + case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter: + return "Password Needs At Least One Special Character"; + case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter: + return "Password Needs A Least One Uppercase Letter"; + case ErrorCode::PasswordsDoesNotMatch: + return "Passwords Does Not Match"; + default: + return "OK"; + } + } +``` + +___ + +Example: + +```cpp +if(doesPasswordsMatch(first_pass, second_pass)) { + return checkPasswordRules(first_pass); +} else { + return ErrorCode::PasswordsDoesNotMatch; +} +``` + +Better: + + +```cpp +if(doesPasswordsMatch(first_pass, second_pass)) { + return checkPasswordRules(first_pass); +} +return ErrorCode::PasswordsDoesNotMatch; +``` + + +___ + +```cpp +enum class ErrorCode { + PasswordNeedsAtLeastNineCharacters, + PasswordNeedsAtLeastOneUppercaseLetter, + PasswordNeedsAtLeastOneSpecialCharacters, // trailing comma +} +``` + +> I do not know really, it's maybe my habit taken from python, to have commas also in the last element of enum/collection, because if I add new element in the future, i didn't have to worry about some errors in regards to missing comma :) + +___ + + +> A: You can specify a size of vector in constructor :) + +```cpp +std::vector> resultVector(count); +``` + +> B: Yes, but what about situation, when count is negative value? I do not think such value should be used in the vector constructor, that's why I do such check first. + + +```cpp +std::vector> resultVector{}; +if (count < 0) { + return resultVector; +} +resultVector.reserve(count); +``` + + +> A: you are right :) , my fault :) + + +> B: No problem, thanks for review :) + + +https://github.com/coders-school/kurs_cpp_podstawowy/pull/254/files + + +___ + + +Max line length - 120. How to format? + +Typically lines are long when the function takes multiple parameters: + + +```cpp +int superFunction(std::vector> vectorOfSharedPointers, std::map miniMap, std::unordered_set hashes, std::function compareFunction) { + // do sth +} + +// usage +auto result = superFunction(mySuperVector, myMiniMap, myGreatHashTable, [](const auto & lhs, const auto & rhs) { return lhs >= rhs;}) +``` + + +Better formatting: + + +```cpp +int superFunction(std::vector> vectorOfSharedPointers, + std::map miniMap, + std::unordered_set hashes, + std::function compareFunction) { + // do sth +} + +// usage +auto result = superFunction(mySuperVector, + myMiniMap, + myGreatHashTable, + [](const auto & lhs, const auto & rhs) { return lhs >= rhs;}); +``` + + +___ + +Or for longer lambdas / too long first parameter which exceeds line limit: + +```cpp +int superFunction( + std::vector> vectorOfSharedPointers, + std::map miniMap, + std::unordered_set hashes, + std::function compareFunction) { + // two levels of indentation above to avoid confusion. + // The function body below will be indented with one level + // do sth +} + +// usage +auto result = superFunction(mySuperVector, + myMiniMap, + myGreatHashTable, + [](const auto & lhs, const auto & rhs) { + return lhs >= rhs; + }); +``` + + +___ + +* Nice usage of std::map instead of ifs' ladder +* Pay attention to the line breaks at the end of the document. +* enum or enum class are integer values ​​underneath (some kind of int). It's not worth passing them over const& for optimization. +* Max 2 blank lines. Usually one is enough. 2 empty lines cannot appear inside any blocks (ranges) like functions, classes, enums. +* Good practice - allocate vector capacity when known in advance. +* When do we use the conventions? + * Group cooperation - obligatory. There is nothing worse than patchy formatting in your project. We are imposing on you the Chromium Modified Style so that there is no scuffle. You can enforce it at will, in particular in the Internal Code Review (i.e. inside the group, before sending us a Pull Request for review) + * Individual work - you can use your own preferences, it is important that it is uniform. + * Don't be "code style nazi" and don't force your formatting style on other people if you comment on individual PR. Of course, it would be nice if everything has same formatting everywhere, but in fact, every company/project will use a different formatting. It is worth to get used to the fact that what you check does not always suit you. This mainly applies to new lines and {} brackets. + +___ + +* #include - I (Łukasz) am not too Nazi commenting to you that: + * it is unsorted + * there is no new line + * to move it to cpp instead of sticking to hpp + * remove, because not used. + + Only when it catches my eye I give such a comment. But know that these are good practices and it is worth applying them. + + +* Also, don't be Nazis and don't do the whole code review just to point out to someone unsorted headers or missing {} in one place. During group projects you'll give yourself a needles about such things inside the groups and this is how you learn the fastest :) To outside review should goes only the code checked by other group members. There is no blaming X that wrote that and he did not take care of it. The whole group gets a beating evenly ;) diff --git a/module1/code-review.md b/module1/03_code-review.pl.md similarity index 82% rename from module1/code-review.md rename to module1/03_code-review.pl.md index 7b0ef3c..3319d38 100644 --- a/module1/code-review.md +++ b/module1/03_code-review.pl.md @@ -5,7 +5,7 @@ ___ -Example: +Przykład: ```cpp bool doesPasswordsMatch(const std::string& password, const std::string& repeatedPassword) { @@ -16,7 +16,7 @@ bool doesPasswordsMatch(const std::string& password, const std::string& repeated } ``` -Better: +Lepiej: ```cpp @@ -29,7 +29,7 @@ bool doesPasswordsMatch(const std::string& password, const std::string& repeated ___ -Example: +Przykład: ```cpp std::string getErrorMessage(ErrorCode Error) { @@ -56,14 +56,17 @@ std::string getErrorMessage(ErrorCode Error) { return "UNDEFINED ERROR"; } } - // What do you think about removing case ErrorCode::Ok: and putting it in default? - // Braces are not needed even for multiline cases. It's only matter of convention if you should apply them or not. They don't provide additional safety. - // We usually don't indent case and code inside namespace + // + // + // + // Co myślisz o usunięciu przypadku ErrorCode::Ok: i ustawieniu go jako domyślnego? + // Nawiasy klamrowe nie są potrzebne nawet w przypadkach wielowierszowych. To tylko kwestia konwencji, czy powinieneś je stosować, czy nie. Nie zapewniają dodatkowego bezpieczeństwa. + // Zazwyczaj nie dokonujemy wcięć przy caseach i kodzie w namespaceach ``` ___ -Better?: +Lepiej?: ```cpp std::string getErrorMessage(ErrorCode error) { @@ -86,7 +89,7 @@ std::string getErrorMessage(ErrorCode error) { ___ -Example: +Przykład: ```cpp if(doesPasswordsMatch(first_pass, second_pass)) { @@ -96,7 +99,7 @@ if(doesPasswordsMatch(first_pass, second_pass)) { } ``` -Better: +Lepiej: ```cpp @@ -113,22 +116,22 @@ ___ enum class ErrorCode { PasswordNeedsAtLeastNineCharacters, PasswordNeedsAtLeastOneUppercaseLetter, - PasswordNeedsAtLeastOneSpecialCharacters, // trailing comma + PasswordNeedsAtLeastOneSpecialCharacters, // końcowy przecinek } ``` -> I do not know really, it's maybe my habit taken from python, to have commas also in the last element of enum/collection, because if I add new element in the future, i didn't have to worry about some errors in regards to missing comma :) +> Naprawdę nie wiem, może to mój nawyk zaczerpnięty z Pythona, aby mieć przecinki również po ostatnim elemencie wyliczenia/kolekcji, bo jeśli w przyszłości dodam nowy element, nie będę się musiał martwić o błędy w odniesieniu do brakującego przecinka :) ___ -> A: You can specify a size of vector in constructor :) +> A: Możesz określić rozmiar wektora w konstruktorze :) ```cpp std::vector> resultVector(count); ``` -> B: Yes, but what about situation, when count is negative value? I do not think such value should be used in the vector constructor, that's why I do such check first. +> B: Tak, ale co z sytuacją, gdy licznik ma wartość ujemną? Nie sądzę, aby taka wartość była używana w konstruktorze wektora, dlatego najpierw wykonuję takie sprawdzenie. ```cpp @@ -140,10 +143,10 @@ resultVector.reserve(count); ``` -> A: you are right :) , my fault :) +> A: masz racje :) , mój błąd :) -> B: No problem, thanks for review :) +> B: Nie ma problemu, dziękuję za recenzję :) https://github.com/coders-school/kurs_cpp_podstawowy/pull/254/files @@ -159,15 +162,15 @@ Zazwyczaj linie są długie gdy funkcja przyjmuje wiele parametrów: ```cpp int superFunction(std::vector> vectorOfSharedPointers, std::map miniMap, std::unordered_set hashes, std::function compareFunction) { - // do sth + // rób coś } -// usage +// użycie auto result = superFunction(mySuperVector, myMiniMap, myGreatHashTable, [](const auto & lhs, const auto & rhs) { return lhs >= rhs;}) ``` -Better formatting: +Lepsze formatowanie: ```cpp @@ -175,10 +178,10 @@ int superFunction(std::vector> vectorOfSharedPointers, std::map miniMap, std::unordered_set hashes, std::function compareFunction) { - // do sth + // rób coś } -// usage +// użycie auto result = superFunction(mySuperVector, myMiniMap, myGreatHashTable, @@ -188,7 +191,7 @@ auto result = superFunction(mySuperVector, ___ -Or for longer lambdas / too long first parameter which exceeds line limit: +Albo dla dłuższych lambd / zbyt długich parametrów, które przekraczają limit linii: ```cpp int superFunction( @@ -196,12 +199,12 @@ int superFunction( std::map miniMap, std::unordered_set hashes, std::function compareFunction) { - // two levels of indentation above to avoid confusion. - // The function body below will be indented with one level - // do sth + // dwa poziomy wcięcia powyżej, aby uniknąć nieporozumień. + // Ciało funkcji poniżej będzie wcięte o jeden poziom + // rób coś } -// usage +// użycie auto result = superFunction(mySuperVector, myMiniMap, myGreatHashTable, @@ -213,9 +216,9 @@ auto result = superFunction(mySuperVector, ___ -* Nice usage of std::map instead of ifs' ladder +* Dobre użycie std::map zamiast drabiny ifów * Zwracajcie uwagę na znaki końca linii na końcu dokumentu. -* enum lub enum class są pod spodem wartościami całkowitymi (jakiś rodzaj inta). Nie warto przekazywać ich przez const& w celu optymalizacji. +* enum lub enum class są pod spodem wartościami całkowitymi (jakiś rodzaj inta). Nie warto przekazywać ich przez const& w celu optymalizacji. * Max 2 puste linie. Zazwyczaj wystarcza jedna. 2 puste linie nie mogą wystąpić wewnątrz żadnych bloków (zakresów), jak funkcje, klasy, enumy. * Dobra praktyka - alokowanie pojemności wektora, gdy jest z góry znana. * Kiedy stosujemy konwencje? diff --git a/module1/04_repetition.en.md b/module1/04_repetition.en.md new file mode 100644 index 0000000..d3535c3 --- /dev/null +++ b/module1/04_repetition.en.md @@ -0,0 +1,70 @@ + + +# Questions from #powtórka channel + +___ + +@edmundoPL +> Question from me to for the recap. What is the point of ensuring a long enough life for the variable which the pointer or reference points to? +> It happened a couple of times now, and I still don't feel it. I kind of understand but not quite. Maybe an interesting example will be found by Thursday? + +___ + + +Let's trace the stack in this piece of code + +```cpp +#include + +int doNothing() { +/* G */ int b = 50; + int c = 100; +/* H */ return b; +} + +int* getObject() { +/* C */ int a = 10; + int* ptr = &a; +/* D */ return ptr; +} + +int main() { +/* A */ int number = 5; +/* B */ int* pointer = getObject(); +/* E */ *pointer = 20; +/* F */ number = doNothing(); +/* I */ std::cout << *pointer << '\n'; +} +``` + +Stack graphically. Right -> next lines of code + +
+ +| FRAME | A | B | C | D | E | F | G | H | I | +| :---: | :-------------- | :------------- | :---------- | :----------- | :------------------- | :----------- | :-------------- | :----------- | :-------------- | +| 1 | | | **ptr = ?** | **ptr = &a** | | | **c = ?** | **c = 100** | | +| 1 | | | **a = ?** | **a = 10** | | **??? = 20** | **b = ? (20?)** | **b = 50** | | +| 0 | **pointer = ?** | pointer = ? | pointer = ? | pointer = ? | **pointer = &a** !!! | pointer = &a | pointer = &a | pointer = &a | pointer = &a | +| 0 | **number = ?** | **number = 5** | number = 5 | number = 5 | number = 5 | number = 5 | number = 5 | number = 5 | **number = 50** | + +
+ +___ + +@Jakub J +> Generic lambdas, what's the point of using regular lambdas (in which we pass a specific type)? + +Limited. Only when we want lambda to work for a certain type and e.g. not compile for another. +I normally recommend using generics. You can come across such and such in the code. Generics are in C++14, and are yet to become well-established. But I strongly encourage you to use them. +___ + + +@lisie_sprawy +> Repasting it from other channel, so it will not lost itself :) why in some tasks about deleting vowels you can see "constexpr int" instead "const int"? + +`constexpr` in the context of a variable is a stronger const. In addition to the fact that it is a constant and we will not change its value, the compiler can further optimize all calculations made with its use and simply calculate the result during compilation and put it in the appropriate places as program constants. We will learn how to do it in modern C++, where more fascinating will be topic of `constexpr` functions, not variables (constants). + +Anyway, this is an optimization and you should have the habit to write `constexpr` right away. If the compiler protests somewhere, it means you can't use it there and should leave just `const`. From C++20, `constexpr` will become even more common, because many of the limitations of `constexpr` will be lifted. + +To remember for now: try to use `constexpr` by default when defining constants instead of `const`. diff --git a/module1/repetition.md b/module1/04_repetition.pl.md similarity index 100% rename from module1/repetition.md rename to module1/04_repetition.pl.md diff --git a/module1/index.html b/module1/index.en.html similarity index 93% rename from module1/index.html rename to module1/index.en.html index 378732c..308c161 100644 --- a/module1/index.html +++ b/module1/index.en.html @@ -46,9 +46,9 @@

Łukasz Ziobroń

## Agenda 1. Scrum - 2. Konkurs - 3. Code review - przykłady - 4. Pytania z kanału #Powtórka + 2. Contest + 3. Code review - examples + 4. Questions from #Powtórka channel @@ -64,19 +64,19 @@

Łukasz Ziobroń

Open http://localhost:8000 to view your presentation You can change the port by using npm start -- --port=8001. --> -
-
-
-
diff --git a/module1/index.pl.html b/module1/index.pl.html new file mode 100644 index 0000000..71044dc --- /dev/null +++ b/module1/index.pl.html @@ -0,0 +1,114 @@ + + + + + + + Sesja pytań i odpowiedzi - Coders School + + + + + + + + + + + + + + + +
+
+
+
+ +

Sesja pytań i odpowiedzi

+ + + Coders School + + +

Łukasz Ziobroń

+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ +

Coders School

+ Coders School + +
+
+
+ + + + + + \ No newline at end of file