✅ Do I always need to avoid coupling?
For example, I have a class Application where the main part of my project's logic is written, and I also have a GenerateVocabulary object which will itself use an Interface to actually generate content. Will it be good practice to simply create this object inside my Application class? And in general, is it acceptable in a professional context to create one object inside another if I'm 100% sure that I won't change it?
24 Replies
if you don't expect to benefit from decoupling, then don't do it
it just makes the code more noisy and harder to understand otherwise
Thank you! After watching Bob Tabor's course about oop I started to decouple everything
Also, is it okay to use TLS varaibles like those?
TLS as in top level statements? the visibility doesn't matter there, all that code gets shoved into a Main method
so they're locals
Okay, is it okay to use locals?
you can't write useful code without them
local variables are just variables declared inside a method
No, I think they're TLS
when you say TLS, what do you mean
Variables that located in object outside methods
those are called fields
Ah, then what is TLS?
$tls
$toplevelcode
$toplevelcode
Traditionally in C#, the main entry point of any program would be a static
Main
method (see $mains): In C# 9, a feature called top-level statements was added which allows the static Main
method to be omitted in favor of brevity and simplicity, and in C# 10, this was made part of the default console application template:
If you are following a tutorial or example code and your default template looks different, you can still write the exact same code as if you were writing it inside the static Main
method. In addition, you can still write static methods inside top-level code. You can however not use top-level code in more than one file.
If you wish to use the old traditional entry point, you can still use a Program
class with a static Main
method.
https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statementsTop-level statements - programs without Main methods - C#
Learn about top-level statements. You can create programs without the ceremony of a Program class and a Main method.
Ah, okay
So, is it okay to use fields like that?
yes
How important is it to carefully choose names for variables and methods?
it's important because you should write code in a way that people can read it, because the computer doesn't care what it looks like
which means making it easy to understand like with meaningful names for things
Okay. Is using more than two words in variable name acceptable? For example, here is my two varaibels ExistingVocabulary and ExistingVocabularyPath
yes, the goal is to make it easy for people to understand
trying to set arbitrary limits goes against that
May I contact you via dm if'll have questions like that? And hank you again for help. I wish you good evening.
just make new help posts, it will be much easier to get help that way
i don't typically respond to dms from here
Okay