Replies: 5 comments
-
Why aren't nested classes sufficient for this? Personally, I like that in C#, files don't really matter, because it makes refactoring easier. This proposal would break that: for example, I can't easily move a file-scoped class to a different file, if it becomes too large.
I don't understand what are you proposing here, could could clarify, maybe by showing example code that uses this? |
Beta Was this translation helpful? Give feedback.
-
Big neested class or big scope hierarchy makes class terrible and unreadable.
|
Beta Was this translation helpful? Give feedback.
-
I don't see how that avoids either problem of "long nested class names" or "big nested classes". You're still embedding the parent class name right in the nested class name. And as for the size of your nested class, where do you expect that code to go? If the complaint is that the nested class code is embedded in the same file as the parent class, well, nobody is forcing you to do that. Define the parent class as a I'm not personally opposed to the notion of class names being compound like that but I think it immediately runs into an ambiguity problem as to whether the nesting is parent classes vs. namespaces. |
Beta Was this translation helpful? Give feedback.
-
Not problem in just long name. Problem in hard name (especially when refactoring, because I can forget to rename other classes) and problem in unreadability neested classes.
And it's not problem. I had written in one file:
I just like structured and flat code. Which option is more readable? It's simply example because of copy past. In real code it's more hard to see where neested example starts or ends.
|
Beta Was this translation helpful? Give feedback.
-
I'm confused. Your long example above makes no use of Swift has |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Kotlin has one good feature: private modifier for classes.
https://kotlinlang.org/docs/reference/visibility-modifiers.html
I think it would be very useful for decomposition of classes.
For example: split class into main class and thair helper or into View, Model, Controller.
Now I must to name/rename every class with full name: MyBlaBlaBlaClass, MyBlaBlaBlaClassHelper or MyBlaBlaBlaView, MyBlaBlaBlaModel, MyBlaBlaBlaController.
With file scoped modifier I could name just: Helper, Model (I'm writting Model and Controller in the same file).
It will encourage to write more decomposed code and smaller classes.
Only one problem: how those classes can be available for tests.
Also I have one more similar proposal: class scoped modifier (neested classes without real nesting).
For example: MyBlaBlaBlaClass.Helper or MyBlaBlaBlaController.Model.
I don't need to access private members of outer class. I want to avoid hell of long class names and big neested classes.
Beta Was this translation helpful? Give feedback.
All reactions