|When distributing the code I think it could even be harmful to use -Werror because people might use other compiler versions and get warnings that I didn't get ... if I strongly disagreed with the warning I would disable it instead|
That's a very good reason!
I also do not turn warnings into error because often times you compile just to do quick debugging rather than building the project for release, so errors would be counterproductive for iteration and debugging.
|You mean like thinking through how it should work before writing it? I think I'm improving but I could do a lot better...|
A lot of info online can be found about "API design", there are even books written, however if you google for "code design" you won't find anything.
I've heard from some people using the term, to my knowledge code design is in fact API design that is not about API but about all the code that is not API, ex. not a library.
In your project which is ie. a console program there is no API, but this doesn't make it not a program, so anything in it is subject to design.
Ex. how are errors handled in your program?
- do you use std::cout everywhere to print errors? that's very bad code design.
- do you return literal integers as exit codes when there is failure, that's bad code design.
- do you throw exceptions of different type? that's bad code design.
Ex. how are functions and classes written?
- are there functions or classes with duplicate or similar logic? that's bad code design.
- are functions or classes contained within their own translation unit? etc.
Good code design for those sample cases is:
- you have unified error handling, ex. an enum enumerating error codes and functions which translates them to strings, and a function which returns them to system on failure.
- you have custom exception class and you always throw that, if that's not possible you further derive new exception classes from base class.
- Instead of 2 functions doing the same thing for different types you write a template instead.
- instead of 2 classes doing similar things, you write a base class for them.
this helps to reduce code bloat and improves maintenance.
- You group functions into TU's depending on purpose, and each class has it's own header\TU.
This are just examples but it's obvious that none of this is "API design", I wonder why the term "code design" is nonexistent, is there another term?
I guess those are the people who get things done ;)
Yeah, you're perhaps right, but you can get things done the other way as well, only that it's going to be slower.
We all know and experienced programs crashing right?
I think programs don't crash as often to pedantic coders ;)
So good luck to those quick coders finding a dangling pointer just because static analysis was off.
I'm sure users will understand it's a "bug" lol :)
George P wrote:
|Visual Studio has editor settings for choosing the various format options. If I open a file that isn't "properly formatted" I use the IDE to automate the formatting|
I'm not able to find an option to view and to auto trim trailing spaces :(
Since VS 2022 many great extensions no longer work, I currently don't have any extensions but used to have at least 10 in previous versions.
|Beyond that I am consistently inconsistent on doing what you talk about, malibor. A console mode program might have a different coding style than a WinAPI GUI app|
Well, when it comes to GUI it gets even more time consuming to take care of everything, so like Peter87 said, it depends whether it is about personal joy project or ex. marketing program that needs to be done ASAP.