-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ":" symbol as alternate to "=" in initializers and anonymous class declaration #6963
Comments
There is no reason to do this. The Also, REST has NOTHING to do with JSON, or any particular wire format. REST is the pattern of HTTP verbs and resource names. It's just as likely to return XML or plain/text or pictures. So that argument goes right out the window. |
@HaloFour i see that only reasone of your posting is trying to show you are passion warior of C# clearance. The only thing that most people who really use C# over 10+ year asked about initializers - why they choose '=' to do things where ':' should be more preferable. If you are not comfort with it - continue use '=' what is problem? "Smell like JavaScript" - you are so bad about JavaScript? We must ask why? - it's efficient, readable and very compact language... you don't lilke readability and compact code? - it's "smell" for you? Hejlsberg will be not your best frend. ))) May be you think that C# always "smell as dior"? No - it's not true, sometimes it smell as GC. Man, don't try throll me with you great knowlege about REST - you speak as school teacher - mentored but without experience with dealling with real one. |
@comdiv I'd suggest reading some Douglas Crockford if you don't know about the myriad of language absurdities with JavaScript. The language was slopped together over a three day weekend, and it shows. It is largely an awful language with awful syntax and awful idiosyncrasies. C# chose to use I write REST services on a daily basis and have been doing so long before ASP.NET supported them and before JSON existed. REST was described in 1996. I'd suggest you learn a thing or two about the technologies that you demand be incorporated as syntax into the language. |
There are already subtle differences between the
|
Man - it's not problem of my suggestion. It's problem of C# itself - starting as modern and clear language it get already two not good initializers - both It's ALREADY mistake of C# - try to close question with @sharwell As you see in links this query is in row with others that goal is to simplify JS/JSON interop You may be completly right, but just say - do you really thing that it's code on good language:
May be you can tell that you can do it with anonymous:
The only answer is that C# that support usual JS-like initializer for Dictionary<string,object> and it's default class for mapping is good for C#:
It's not just readable, not require anything except System.Collection.Generics, not require much work on Roslyn - it's highly compatible with JS - last code already is JS too. So if we need to supply both C# and JS(for nodejs) version of some logic it will be less work to accomplish. May be you can say that I must say that existed situation is good? It's not Existed initializers are dark side of C# and you try (i work with C# since 1-st version and have millions lines of code in it myself and with my team) tell me that they are cool. We know existed initializers, both of them and every time we wander about it's design. You can further think that it's all good but it's just sign that C# became older and it's community is not oriented to C# usage, but oriented to keep it "very special and original" even if it's not truth. I'm not best Guru but work hard with C#, JavaScript and some other things. It's sad but C# community more and more is looks like Java community - every ugly thing in those language and every comparison with C# or something else - and they not try to think "why our Java developers not agree with our roadmap and look for C# and migrate to it" - they was just hated and speak that "Java really is beter and cooler forever and ever and it will never be close to C# because C# is bullshit and Java is GOD".
|
@comdiv It's no mistake, it's just different. I'm sorry that you don't like it, but that's no reason to arbitrarily change it to just use one special character in place of another. Your argument boils down to nothing more than, "I want C# to be JavaScript." C# isn't JavaScript and there is no reason for C# syntax to become JavaScript. ElastiSearch uses JSON, not JavaScript. A dictionary initialization syntax which would potentially be a superset of JSON (but not JavaScript) is being considered. That syntax would include |
Is there any chance to see a "C#: The Good Parts" book in the future? Because these are going to be the good parts. |
@HaloFour - i work with ElasticSearch - every day - i create dictionaries and serialize them to JSON - i know with what i work. Problem is Dictionary creation - not JS or JSON. But I know cause - C# is not dynamic language by nature and when dynamic requirements occured - C# designers try to resolve it on typed-object maner - "you should supply POCO model, supply serializer"- or they supply something monstrous as DLR and For following hollywar @HaloFour
or
I think I know your answer "C# is object oriented, binding operators to functions and binding functions to classes - is main think you must pray about, namespaces are only ultimate way to avoid ambiguity!!!!" But i know real answer - Roslyn already can parse method body on script manner and supply wrapping method and class dynamically with dynamic names. Why? Because it's really needed to use C# in short script developing too, especially due to new coming dnx realty. Se further man. See to EDGE - their comunity hardly discuss common modules both for JS and C# - they think int terms of code generation from TypeScript definitions and similar, but I think they would very glad if they could write :
And get both JS and CS without overheat? |
So basically - you want Roslyn to do you parsing because you do not want to write your own parser or consume an existing parser? Am I understanding that correctly? |
I think that it's not good idea write OWN Roslyn. I have not good expirience with Boo (meta) and good experience own parsers for some domain-oriented langs. |
@comdiv You have yet to demonstrate why C#'s dictionary initialization syntax is "invalid" beyond the fact that it's not JavaScript. |
@comdiv You're the one making the proposals. The burden of proof is on you to demonstrate why the effort needs to be expended. |
@HaloFour - you are just holywar throll
I have post it more than 10 times as main motivation. You still speak about JS - please talk about C# |
@comdiv Your argument is with the explicit creation of the type, not the dictionary initialization syntax. Fine, a dictionary literal would solve that. But, as mentioned before, a dictionary literal syntax would not reuse identifiers as names nor would it be limited to keys of |
@HaloFour why anonymous classes reuse names and can use them even replacing values
Oh, i know - "it's class and it's names - dictionary is not class - so no names", logically... nothing can said. your last comment is even stranger than all things you write before, i translate: "Ok, stupid and nooby Comdiv - take your shitty dictionary literals - BUT WE NEVER do them good - they will be not help for you - it will be inquisition - NO NAMES, NO KEYS, JUST STRINGS AND NOTHING MORE!" What do you want to say exactly. I give simple to reproduce sample of bad C# design. (I'm C# guy - i don't know another samples of bad design of C# and agree with most decisions in C# 2,4,5,6 ) I give simple to implement solution that is close to existed C# notation (far close than C-Omega syntax) and in another issue suggest parser/production rules for it. But almost all discussion is with you and is about that C# is not JS. What is you goal in github and roslyn project? What do you develop with C# what kind of products? How it occured that you totally comfort with existed initializers and so angree about JS? So strange... so strange... |
Anonymous classes don't have keys, they have properties. Properties are identifiers. Keys are not identifiers. Properties aren't expressions. Keys are expressions. Properties must be names that confirm to the rules of identifiers per the C# specification. Expressions can be of any type and of any value. You're the one trying to force JavaScript into this conversation since you demand on JavaScript syntax and not JSON (despite the argument about REST/ElastiSearch/etc.). |
This has nothing special to do with dictionaries, These are just indexer initializers , and before that there was collection initializers which call |
@comdiv The two initializer syntaxes do not do the same thing.
|
@sharwell I know what is initializers. But there is not normal dictionary tree semantic where we can define dictionary<string,object> as tree structure? As it can be defined in JS or Groovy or Python. It's kind of indexer semantic but without syntax overheat. |
@comdiv why put together a working example on https://github.com/dotnet/corefxlab and see if the community adopts it? |
That is unrelated to this proposal. This proposal only concerns the ability to use The comment where you replied to my first response contains the following:
I was simply clarifying that C# contains two initializer expressions, but they do not behave in the same way. The proposal you are making here does not contain any new behavior. This proposal, unlike the introduction of indexer initializers, is a true duplication of an existing language feature. 📝 Note that I am not criticizing you for making this feature request. I am simply adding context to my reasoning for objecting to using it. |
It think that it can be pull request for roslyn repository - it cannot be created at corefxlab level, while it require to fix compiler at parser level and add rewrite tree filter. It would be pleased if someone from roslyn community can help to explore roslyn code and find minimal set of point to add required fixes in, while roslyn codebes is much complex - it's hard to explore it from zero. @sharwell you are right and i make reference to #6965, it's not copy of existed feature - it's advanced version of feature. Where are many C# things that is no actually new features but are advanced old ones - for example lambda syntax for delegates - of course you can speack that lambdas are coupled with expression support - but in practice it's just shugar over existed |
There is absolutely nothing that makes If you want to argue for dictionary literals, I'm all for that. You've already proposed your syntax on that subject and it has some comments by members of the C# team. Redefining existing initializer syntax just 'cause is silly when it provides absolutely no verbosity or functionality improvements over the existing syntax. |
So it's better explanation is in #6965, i close this issue while it's not clear. Additionally after discussion of ambiguity with anonymous i review own opinion and think that ':' is not good for all proposes but for dictionary literals only. I close this issue. |
Due to #6673 became some case of holy war I split it to more localized issues.
In JS, JSON, Groovy we see usefull syntax to define mapping:
{"key":value}
In C# we see:
new { key = value}
for anonymousnew X{ key = value }
for class initializernew Dictionary<stirng,object>{ { key, value} }
old initializer syntaxnew Dictionary<string,object>{ [key] =valye ,}
new initializer syntaxSuggest to allow both symbols
:
and=
to be valid in initialzier.So anonymous could be
new {key: value}
and class initalizer too `new X { key : value }It will be greatly usefull for 2-language projects with JS and for readablity in REST contet.
":" symbol is not much overloaded in C# ( it used for 1) ternars 2) before base class list ) it's much more free than in C++ (where :: operator exists) so it will be not ambigous in initializer context.
For #6673 and similar issues it will be first step to do C# and JS initializers closer.
The text was updated successfully, but these errors were encountered: