New answers tagged

1

They are mostly visual separators for different parts of a single function. ... make clean to the reader which lines of code inside a function are closely related and which are not. Your first function listed, the constructor, doesn't need such "visual separators" other than a blank line. The closely-related lines come in pairs, one for the real ...


0

using string_view Your comment to my main answer states: The problem with string_view is that I have to provide a null-terminated [sic] string to Linux API, but string_view doesn't support .c_str() so I have to create a temporary std::string each time. Here's my code for dealing with that. /* Sometmimes we need a nul-terminated const char*, such as for ...


1

So what do you think about this commenting style? It encourages meandering functions, and does not help make sure each "clump" is cohesive. You lose the exit pathway, where you can return when you have the answer as the function is a strong boundary with special semantics; if it's just a clump of lines, that's a goto to jump out of the clump. ...


0

Raw Strings Your code currently suffers from Leaning Toothpick Syndrome. The directory separator backslash \ in Windows paths needs to be escaped in strings (\\) to avoid being mistaken for an escape sequence like \n, \r, \t, or \x. A similar problem happens with regular expressions, which use the backslash to introduce terms like whitespace (\s). Python ...


5

It's generally a very bad idea to put credentials in a program. That's a bigger topic, and the best approach will vary depending on your situation. But you should address this problem. When naming things, let ordinary English usage guide you: plural for collections (lists, tuples, dicts, etc) and singular for individual values. For example, use files and ...


1

When you use conditional code make it functional so the code you read looks normal. i.e. don't mess up the code by putting conditional compilation in. Use conditional compilation to generate alternative versions of appropriate functions. static void color_green(std::string path) { #ifndef __LINUX //color code for green std::cout <&...


6

Command Loop std::cout << "$ "; //Main Loop while (true) { std::string cmnd; getline(std::cin, cmnd); #if DEBUG if (cmnd == "exit") return 0; #endif A few comments here: You output a prompt, "$ ", but you only do that once. The other ...


2

std::cout << "\033[32m" << path << "\033[0m"; Please don't do that - not all the world is an ANSI terminal.


Top 50 recent answers are included