Esa
β
how can i improve this code ?
Allright so I mocked up something here: https://github.com/EivindAntonsen/RefactoringExample/blob/refactoring-example/ConsoleApp1/Program.cs
This branch is a refactored version of the code you pasted up above. There's probably a lot of different ways to do this, and many ways this can get over-complicated, but this is how I'd think about solving this.
* Split classes into their own files.
* Changed Company from being an instanced class to a static one.
* Kept Employee as a class (like you had it initially, and not a
record
as I suggested a bit hastily).
* Changed some of the do-while loops into while(true) loops with break conditions inside instead.
* Removed the accessors in your Company class in favor of more explicit methods with accurate names, to more clearly express the intent of the methods.
* Improved error messages for bad user input.
Just ask if any of this stuff is unclear. And to anybody else watching, let me know if you disagree with where I've taken the code for any reason, I'm also interested in learning if anybody thinks I've made some poor choices.78 replies
β
how can i improve this code ?
It dependsβ’.
Performance can be measured in several ways, personally I consider readability a performance index, since that directly affects how long it'll take me to understand and modify a codebase - and therefore it affects developer output.
Then there's stuff like cyclomatic complexity (how many different branches are there, such as if-statements, switches, do-while loops etc) as well as time complexity which you mentioned.
If you do not agree that readability is a performance index, then you may honestly make the argument that the code you shared is fine as-is.
78 replies
β
How to get Options from DI
This is an example of how to bind a config class and register it as an Option in your app. When you then create a class and add
IOptions<SpotifyConfig>
to its parameter list, the DI container will inject that for you.14 replies
β
How to get Options from DI
The MSFT docs for the IOptions<T> pattern are really good, and will answer the general question "How do I use/obtain IOptions<T> from DI?" sufficiently.
If your question is more about the google credentials specifically, that's an appropriate question for a thread like this imo.
14 replies