Replies: 49 comments 29 replies
-
@lostmsu The other proposal is much more sensible in my opinion because it tries to reduce the nesting created by namespaces but this looks like a complete new language to me. 😆 Edit: Rephrased. |
Beta Was this translation helpful? Give feedback.
-
@eyalsk same for me. However, I think its because we all so much used to the two levels of indentation, that their absence feels completely alien. |
Beta Was this translation helpful? Give feedback.
-
@lostmsu Can't see the benefit of this but each to his own I guess. :) |
Beta Was this translation helpful? Give feedback.
-
@eyalsk open this on laptop (random pull request from my browsing history): https://github.com/dotnet/roslyn/pull/20269/files |
Beta Was this translation helpful? Give feedback.
-
I am completely on board with including namespace and declaring type name inline with the class name, but I really am not liking the more drastic effect of making it look like the class declaration has ended but then including the following declarations inside it. I don't like it any more than I liked it in the |
Beta Was this translation helpful? Give feedback.
-
@jnm2 that makes sense. Unfortunately, some token is needed there to avoid ambiguity. Perhaps it's better to replace Another alternative is to use some existing keyword like But I am actually against that. Somehow this is similar to |
Beta Was this translation helpful? Give feedback.
-
Same with variable declarations; and yet my point is, in neither case do these statements actually contain the following declarations or statements. With |
Beta Was this translation helpful? Give feedback.
-
This is not same
I expect Instead I would say namespaces could be omitted inside class name. so
would be equal to
IMO replacing body of class semicolon is not good suggestion. that's 👎 part but having namespace with class name for me is 👍 and doesn't make strange change in current syntax. (it saves 3 lines for good sake.) |
Beta Was this translation helpful? Give feedback.
-
@jnm2 you are appealing to consistency, but that consistency does not really exist, and two different kinds of P.S. I intentionally did no say |
Beta Was this translation helpful? Give feedback.
-
This syntax may collide with the proposed syntax for records. |
Beta Was this translation helpful? Give feedback.
-
OK to remove namespace indentation but I prefer to leave the '{' for the class body, I'll interpret your example as: This version of C# seems more a scripting language that a "true" programming language. |
Beta Was this translation helpful? Give feedback.
-
@lostmsu I don't see any inconsistency. Technically there's one Things that contain other things do it via blocks and indentation. Classes contain declarations, block statements contain statements, etc. There's a special exception for blocks containing one statement but no exception for blocks containing one declaration, but that's not what you're asking for either. |
Beta Was this translation helpful? Give feedback.
-
How would nested classes be handled? Nested classes are more common (and more useful) than nested namespace. Nor am I fan of working in a codebase where it's impossible to add a new class to an existing file even on a temporary (i.e. pre-PR) basis. When I'm bringing up a big new feature with lots of new classes, it's just much more efficent to throw them into the file I'm working on during the bringup and segregate them in waves (during those otherwise unproductive 15min time-slices between meetings and a lunch or whatever) after the big thinking is done and I'm sure I actually want the classes. |
Beta Was this translation helpful? Give feedback.
-
^^ So much this. |
Beta Was this translation helpful? Give feedback.
-
I really (and I mean terribly) wish I could do this: SomeClass.cs:partial class Some.Namespace.SomeClass
{
// ...
} SomeClass.SomeNestedClass.cs:class Some.Namespace.SomeClass.SomeNestedClass
{
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Hi. I'm a Java developer. I don't put newlines after closing braces. Now you've met one. 😜 My point is that you choose your verbosity. The language only requires two characters to establish the scope within a type. Newlines and indentation is all up to the developer. You also demanding that F# nix the indentation that is required for everything? Even without the braces I doubt too many developers would embrace the idea of not enclosing the members in some kind of scope denoted by indentation. |
Beta Was this translation helpful? Give feedback.
-
Um, I was talking about opening braces. I suspect this a simple typo on your part, but hey, if cheap points are offered... 😉
Technically, yes. But to mind at least, convention trumps personal preference a lot of the time. That's why, when writing JavaScript or Java, I follow the K&R brace layout. For C#, I use Allman. I prefer the latter, but I follow the conventions of the former two languages over my own preferences.
F# is an odd one in this regard. Declare a module (which, as far as I know, is just a abstract final class in .NET, or "static" in C# terms) and no indentation is required for the functions therein. Declare an interface or class/struct though and indentation must follow that |
Beta Was this translation helpful? Give feedback.
-
A newline after the opening brace? I've never seen that. Java devs seem to prefer fairly dense code, to the point of having closing brace, keyword and opening brace all on the same line, e.g.: if (foo) {
doFoo();
} else {
doBar();
} |
Beta Was this translation helpful? Give feedback.
-
@HaloFour newline after opening brace is default in IDEA for method bodies AFAIK. At least I've seen it a lot. Not for IFs. I also prefer opening brace on the same line btw. Saves vertical space. I am sad to see people downvoting feature that brings physically measurable advantage over their idea of language consistency. I fail to see how anyone even with least experience and involvement could not comprehend and remember that |
Beta Was this translation helpful? Give feedback.
-
C# is a curly brace (or bracket) language not because the "userbase" chose it to be but because the designers of the language chose it and we followed partly because the syntax is similar to what we are accustomed to, most notably the curly braces so the idea wasn't ours to begin with. You see that as a benefit some of us see that as a fundamental change to the language that we're not in favor of or think that it's too extreme and this is the reason for the downvotes. p.s. I really wouldn't mind it either way so I removed the downvote, I still think it's a fundamental change to the language and one that I probably wouldn't use but don't care whether others will. |
Beta Was this translation helpful? Give feedback.
-
💭 Java approaches this functionality in a slightly different manner:
If this approach (both options) were applied to C#, the resulting code might look like this:
💭 My biggest concern overall with this proposal is the confusion and/or limitations that may result from the placement of 💭 I also have a concern related to the
|
Beta Was this translation helpful? Give feedback.
-
Absolutely it's dependent, and I like it that way. Any time you have |
Beta Was this translation helpful? Give feedback.
-
I think it's a good idea to remove the namespace indents, but I would feel like everything I'm writing is in some global scope without the class. It feels like I'm writing in C or something 😐 |
Beta Was this translation helpful? Give feedback.
-
It's interesting revisiting ideas like this years later. Back then, I was really keen on that idea. Since then, the language has added support for file-scoped namespaces. But it has also added top-level statements. To my mind, that latter feature changes this one from one I was keen on to one I'm strongly opposed to: // Not a class, just some top level statements
namespace MyNamespace;
string field = 1;
void Bar() => field = 2;
string Foo() => field;
// Is a class
namespace MyNamespace;
class SomeClass;
string field = 1;
public string Foo() => field;
void Bar() => field = 2; The only clues that one is a class and one isn't is that |
Beta Was this translation helpful? Give feedback.
-
See also the answers for #4722, where Cyrus and I laid out why this won't happen. |
Beta Was this translation helpful? Give feedback.
-
So C# recently introduced a public file class MyClass; Looking forward to your thoughts. |
Beta Was this translation helpful? Give feedback.
-
I agree with this proposal, but the ";" at the end of the class declaration needs to go and be replaced with something else. Although I understand that this is there to put it in line with the |
Beta Was this translation helpful? Give feedback.
-
It looks great, it can save screen space. Is there any progress on this? |
Beta Was this translation helpful? Give feedback.
-
it might look like this:
|
Beta Was this translation helpful? Give feedback.
-
I don't think anyone suggested this yet: why don't we couple the namespace declaration with the class declaration? namespace MyNamespace.MySubNamespace with
class MyClass : IWhatever; In which case the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is related to "File scoped namespaces" proposal #137, I just wanted to track it separately (though IMHO, they both should be implemented in the same iteration).
Basically, the idea is to remove two indentation levels, that unnecessarily appear in C#<=7: namespace and class. Here's the example syntax I'd be looking for:
We can decide if usings will be treated as being inside MyCompany.MyLib or outside. I'd prefer the first one, but the second option would be less of surprise for newcomers.
Same code without the feature for comparison:
Beta Was this translation helpful? Give feedback.
All reactions