Timeline for Deck of Cards written in C++
Current License: CC BY-SA 4.0
19 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 8, 2021 at 21:39 | comment | added | JDługosz | @ahazybellcord OK, #2 is subjective; removing distracting visual noise is more readable and more fits on the screen, #1 different things should look different. If you need more than one line, it's a "dive into" more detail rather than a simple thing. Maybe you have not decomposed enough. #3 no, it's not. Or, maybe the extra work will make you consider that the addition should be put into the function call instead or that the statement ought to be refactored. | |
| Jul 8, 2021 at 19:26 | comment | added | ahazybellcord | @JDługosz ...but you've provided zero counter-arguments. I've asked that question and given three separate arguments for why you should always use braces around if-statements even if the conditionally-executed code is a single line. | |
| Jul 7, 2021 at 21:42 | comment | added | JDługosz | @ahazybellcord I would advocate the opposite: I heard someone talking about this at one of the major conferences, but I don't recall the exact talk. Instead, ask "why isn't it one line"? | |
| Jul 6, 2021 at 21:01 | comment | added | indi | @EmilyL. 2c) Finally, that StackOverflow answer is just plain wrong. sync_with_stdio() has nothing to do with line buffering. It just turns off the interlock between <iostream> stuff and <stdio> stuff. When cout is line-buffered and you do sync_with_stdio(false), cout << '\n' will still trigger a flush… but only cout will be flushed, not the C stream buffer stdout. With printf('a'); cout << 'b'; cout << '\n';, normally 'n' will trigger a flush that prints “ab”. But with sync_with_stdio(false), the 'n' will trigger a flush that just probably prints just “b”. | |
| Jul 6, 2021 at 20:57 | comment | added | indi | @EmilyL. 2b) And since endl is literally '\n' then a flush, it is absolutely not “moot” that you use it, whether line-buffered or not. If your output is line-buffered, then cout << '\n' does one flush (when it writes the line), while cout << endl does two flushes (when it writes the line, and then the call to flush()). If your output is not line-buffered, cout << '\n' does zero flushes (unless the buffer is full, of course), while cout << endl does at least one. endl always causes an extra, usually unnecessary flush… which is why it’s pretty much always wrong. | |
| Jul 6, 2021 at 20:56 | comment | added | indi | @EmilyL. 2a) Basically everything you said about std::endl is wrong. std::endl has absolutely nothing to do with system specific newline sequences. os << endl; is is literally defined in the standard as just os.put('\n'); os.flush(); (except that '\n' is widened with os.widen() to handle non-char streams). Newline translation is done by the stream buffer—usually basic_filebuf in text mode. All newlines will be translated by the stream buffer, not just the newlines endl puts in there. | |
| Jul 6, 2021 at 20:55 | comment | added | indi | @EmilyL. 1) You can’t use std::array here. The size of the deck changes. If you use std::array, then there will be 52 cards in the deck… there will ALWAYS be 52 cards in the deck, which makes it pretty useless; you can’t remove any cards from it when you deal. The whole point of using std::vector or boost::container::static_vector is that your deck will never have more than 52 cards (when no cards have been dealt and all are in the deck), but it can have less as you deal cards out to the players. The deck size changes. array.size() is fixed. | |
| Jul 5, 2021 at 9:27 | comment | added | Emily L. | Instead of boost static vector, you should use std::array. Also, most likely this application is going to run in an interactive shell so '\n' is also an implicit flush so the whole section about std::endl is moot, see: stackoverflow.com/a/25569849/2498188. std::endl clearly denotes the system specific new line sequence (instead of quietly converting '\n' to CRLF on eg Windows) and imho is more readable. | |
| Jul 5, 2021 at 6:51 | history | edited | Toby Speight | CC BY-SA 4.0 | Removed stray word, and fixed inverted logic of game loop |
| Jan 17, 2021 at 21:03 | comment | added | Off_grid_coder | I got home and noticed that rank was a string and not an int, also missing semicolon. Rank and value need to be defined because in BlackJack a king is worth 10 points but in poker a king is higher than a queen. I'm Still trying to define ace to be hi or low. My random function should not be static.Thank you for your input. I get no I tenet a home so I bring my phone out and copy web pages and pdf's to take home and read. That was a good answer and will consider this as answered.I am just super stoked that I made a BlackJack game that worKS.Thank you. | |
| Jan 17, 2021 at 18:34 | comment | added | SethMMorton | @AnnoyinC And for the second: stackoverflow.com/questions/30395205/… | |
| Jan 17, 2021 at 18:32 | comment | added | SethMMorton | @AnnoyinC RE: your first question: stackoverflow.com/questions/1452721/… | |
| Jan 16, 2021 at 20:13 | comment | added | AnnoyinC | Also, what are the problems caused by unsigned ints? | |
| Jan 16, 2021 at 19:02 | comment | added | AnnoyinC | Why never put using namespace std;? | |
| Jan 16, 2021 at 18:09 | comment | added | ahazybellcord | Quite a dazzlingly thorough answer. But I would advocate for always using braces around if-blocks. The argument can be made from (1) stylistic consistency, (2) readability and (3) maintainability. (1) is obvious; (2) braces make it much easier to see the logical structure of the code when skimming quickly; (3) it's annoying if and when the time comes to add more logic to an if-block to add in braces (that really should have been there in the first place...) | |
| Jan 16, 2021 at 16:09 | comment | added | Toby Speight | @Jack good advice - I would add that you should just use std::shuffle() rather than reimplementing Fisher-Yates yourself. | |
| Jan 16, 2021 at 13:21 | comment | added | anon | The only thing missing from this tour de force is a mention that a proper shuffling algorithm is vital in a card game. The Fisher-Yates Shuffle an easily implemented and well known option: en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle . Never try and roll your own shuffle. | |
| Jan 16, 2021 at 8:34 | history | edited | Toby Speight | CC BY-SA 4.0 | Fixe a wee cut-and-paste oversight |
| Jan 16, 2021 at 5:15 | history | answered | indi | CC BY-SA 4.0 |